"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "support/regexec.c" between
gawk-5.0.1.tar.xz and gawk-5.1.0.tar.xz

About: GNU awk - pattern scanning and processing language.

regexec.c  (gawk-5.0.1.tar.xz):regexec.c  (gawk-5.1.0.tar.xz)
skipping to change at line 445 skipping to change at line 445
bufp->regs_allocated = re_copy_regs (regs, pmatch, nregs, bufp->regs_allocated = re_copy_regs (regs, pmatch, nregs,
bufp->regs_allocated); bufp->regs_allocated);
if (__glibc_unlikely (bufp->regs_allocated == REGS_UNALLOCATED)) if (__glibc_unlikely (bufp->regs_allocated == REGS_UNALLOCATED))
rval = -2; rval = -2;
} }
if (__glibc_likely (rval == 0)) if (__glibc_likely (rval == 0))
{ {
if (ret_len) if (ret_len)
{ {
assert (pmatch[0].rm_so == start); DEBUG_ASSERT (pmatch[0].rm_so == start);
rval = pmatch[0].rm_eo - start; rval = pmatch[0].rm_eo - start;
} }
else else
rval = pmatch[0].rm_so; rval = pmatch[0].rm_so;
} }
re_free (pmatch); re_free (pmatch);
out: out:
lock_unlock (dfa->lock); lock_unlock (dfa->lock);
return rval; return rval;
} }
skipping to change at line 504 skipping to change at line 504
re_free (new_start); re_free (new_start);
return REGS_UNALLOCATED; return REGS_UNALLOCATED;
} }
regs->start = new_start; regs->start = new_start;
regs->end = new_end; regs->end = new_end;
regs->num_regs = need_regs; regs->num_regs = need_regs;
} }
} }
else else
{ {
assert (regs_allocated == REGS_FIXED); DEBUG_ASSERT (regs_allocated == REGS_FIXED);
/* This function may not be called with REGS_FIXED and nregs too big. */ /* This function may not be called with REGS_FIXED and nregs too big. */
assert (regs->num_regs >= nregs); DEBUG_ASSERT (nregs <= regs->num_regs);
rval = REGS_FIXED; rval = REGS_FIXED;
} }
/* Copy the regs. */ /* Copy the regs. */
for (i = 0; i < nregs; ++i) for (i = 0; i < nregs; ++i)
{ {
regs->start[i] = pmatch[i].rm_so; regs->start[i] = pmatch[i].rm_so;
regs->end[i] = pmatch[i].rm_eo; regs->end[i] = pmatch[i].rm_eo;
} }
for ( ; i < regs->num_regs; ++i) for ( ; i < regs->num_regs; ++i)
skipping to change at line 597 skipping to change at line 597
const re_dfa_t *dfa = preg->buffer; const re_dfa_t *dfa = preg->buffer;
Idx left_lim, right_lim; Idx left_lim, right_lim;
int incr; int incr;
bool fl_longest_match; bool fl_longest_match;
int match_kind; int match_kind;
Idx match_first; Idx match_first;
Idx match_last = -1; Idx match_last = -1;
Idx extra_nmatch; Idx extra_nmatch;
bool sb; bool sb;
int ch; int ch;
#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
re_match_context_t mctx = { .dfa = dfa }; re_match_context_t mctx = { .dfa = dfa };
#else
re_match_context_t mctx;
#endif
char *fastmap = ((preg->fastmap != NULL && preg->fastmap_accurate char *fastmap = ((preg->fastmap != NULL && preg->fastmap_accurate
&& start != last_start && !preg->can_be_null) && start != last_start && !preg->can_be_null)
? preg->fastmap : NULL); ? preg->fastmap : NULL);
RE_TRANSLATE_TYPE t = preg->translate; RE_TRANSLATE_TYPE t = preg->translate;
#if !(defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
)
memset (&mctx, '\0', sizeof (re_match_context_t));
mctx.dfa = dfa;
#endif
extra_nmatch = (nmatch > preg->re_nsub) ? nmatch - (preg->re_nsub + 1) : 0; extra_nmatch = (nmatch > preg->re_nsub) ? nmatch - (preg->re_nsub + 1) : 0;
nmatch -= extra_nmatch; nmatch -= extra_nmatch;
/* Check if the DFA haven't been compiled. */ /* Check if the DFA haven't been compiled. */
if (__glibc_unlikely (preg->used == 0 || dfa->init_state == NULL if (__glibc_unlikely (preg->used == 0 || dfa->init_state == NULL
|| dfa->init_state_word == NULL || dfa->init_state_word == NULL
|| dfa->init_state_nl == NULL || dfa->init_state_nl == NULL
|| dfa->init_state_begbuf == NULL)) || dfa->init_state_begbuf == NULL))
return REG_NOMATCH; return REG_NOMATCH;
#ifdef DEBUG
/* We assume front-end functions already check them. */ /* We assume front-end functions already check them. */
assert (0 <= last_start && last_start <= length); DEBUG_ASSERT (0 <= last_start && last_start <= length);
#endif
/* If initial states with non-begbuf contexts have no elements, /* If initial states with non-begbuf contexts have no elements,
the regex must be anchored. If preg->newline_anchor is set, the regex must be anchored. If preg->newline_anchor is set,
we'll never use init_state_nl, so do not check it. */ we'll never use init_state_nl, so do not check it. */
if (dfa->init_state->nodes.nelem == 0 if (dfa->init_state->nodes.nelem == 0
&& dfa->init_state_word->nodes.nelem == 0 && dfa->init_state_word->nodes.nelem == 0
&& (dfa->init_state_nl->nodes.nelem == 0 && (dfa->init_state_nl->nodes.nelem == 0
|| !preg->newline_anchor)) || !preg->newline_anchor))
{ {
if (start != 0 && last_start != 0) if (start != 0 && last_start != 0)
skipping to change at line 677 skipping to change at line 666
goto free_return; goto free_return;
} }
mctx.state_log = re_malloc (re_dfastate_t *, mctx.input.bufs_len + 1); mctx.state_log = re_malloc (re_dfastate_t *, mctx.input.bufs_len + 1);
if (__glibc_unlikely (mctx.state_log == NULL)) if (__glibc_unlikely (mctx.state_log == NULL))
{ {
err = REG_ESPACE; err = REG_ESPACE;
goto free_return; goto free_return;
} }
} }
else
mctx.state_log = NULL;
match_first = start; match_first = start;
mctx.input.tip_context = (eflags & REG_NOTBOL) ? CONTEXT_BEGBUF mctx.input.tip_context = (eflags & REG_NOTBOL) ? CONTEXT_BEGBUF
: CONTEXT_NEWLINE | CONTEXT_BEGBUF; : CONTEXT_NEWLINE | CONTEXT_BEGBUF;
/* Check incrementally whether the input string matches. */ /* Check incrementally whether the input string matches. */
incr = (last_start < start) ? -1 : 1; incr = (last_start < start) ? -1 : 1;
left_lim = (last_start < start) ? last_start : start; left_lim = (last_start < start) ? last_start : start;
right_lim = (last_start < start) ? start : last_start; right_lim = (last_start < start) ? start : last_start;
sb = dfa->mb_cur_max == 1; sb = dfa->mb_cur_max == 1;
skipping to change at line 838 skipping to change at line 825
match_last = -1; match_last = -1;
} }
else else
break; /* We found a match. */ break; /* We found a match. */
} }
} }
match_ctx_clean (&mctx); match_ctx_clean (&mctx);
} }
#ifdef DEBUG DEBUG_ASSERT (match_last != -1);
assert (match_last != -1); DEBUG_ASSERT (err == REG_NOERROR);
assert (err == REG_NOERROR);
#endif
/* Set pmatch[] if we need. */ /* Set pmatch[] if we need. */
if (nmatch > 0) if (nmatch > 0)
{ {
Idx reg_idx; Idx reg_idx;
/* Initialize registers. */ /* Initialize registers. */
for (reg_idx = 1; reg_idx < nmatch; ++reg_idx) for (reg_idx = 1; reg_idx < nmatch; ++reg_idx)
pmatch[reg_idx].rm_so = pmatch[reg_idx].rm_eo = -1; pmatch[reg_idx].rm_so = pmatch[reg_idx].rm_eo = -1;
skipping to change at line 886 skipping to change at line 871
pmatch[reg_idx].rm_so = pmatch[reg_idx].rm_so =
(pmatch[reg_idx].rm_so == mctx.input.valid_len (pmatch[reg_idx].rm_so == mctx.input.valid_len
? mctx.input.valid_raw_len ? mctx.input.valid_raw_len
: mctx.input.offsets[pmatch[reg_idx].rm_so]); : mctx.input.offsets[pmatch[reg_idx].rm_so]);
pmatch[reg_idx].rm_eo = pmatch[reg_idx].rm_eo =
(pmatch[reg_idx].rm_eo == mctx.input.valid_len (pmatch[reg_idx].rm_eo == mctx.input.valid_len
? mctx.input.valid_raw_len ? mctx.input.valid_raw_len
: mctx.input.offsets[pmatch[reg_idx].rm_eo]); : mctx.input.offsets[pmatch[reg_idx].rm_eo]);
} }
#else #else
assert (mctx.input.offsets_needed == 0); DEBUG_ASSERT (mctx.input.offsets_needed == 0);
#endif #endif
pmatch[reg_idx].rm_so += match_first; pmatch[reg_idx].rm_so += match_first;
pmatch[reg_idx].rm_eo += match_first; pmatch[reg_idx].rm_eo += match_first;
} }
for (reg_idx = 0; reg_idx < extra_nmatch; ++reg_idx) for (reg_idx = 0; reg_idx < extra_nmatch; ++reg_idx)
{ {
pmatch[nmatch + reg_idx].rm_so = -1; pmatch[nmatch + reg_idx].rm_so = -1;
pmatch[nmatch + reg_idx].rm_eo = -1; pmatch[nmatch + reg_idx].rm_eo = -1;
} }
skipping to change at line 926 skipping to change at line 911
static reg_errcode_t static reg_errcode_t
__attribute_warn_unused_result__ __attribute_warn_unused_result__
prune_impossible_nodes (re_match_context_t *mctx) prune_impossible_nodes (re_match_context_t *mctx)
{ {
const re_dfa_t *const dfa = mctx->dfa; const re_dfa_t *const dfa = mctx->dfa;
Idx halt_node, match_last; Idx halt_node, match_last;
reg_errcode_t ret; reg_errcode_t ret;
re_dfastate_t **sifted_states; re_dfastate_t **sifted_states;
re_dfastate_t **lim_states = NULL; re_dfastate_t **lim_states = NULL;
re_sift_context_t sctx; re_sift_context_t sctx;
#ifdef DEBUG DEBUG_ASSERT (mctx->state_log != NULL);
assert (mctx->state_log != NULL);
#endif
match_last = mctx->match_last; match_last = mctx->match_last;
halt_node = mctx->last_node; halt_node = mctx->last_node;
/* Avoid overflow. */ /* Avoid overflow. */
if (__glibc_unlikely (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) if (__glibc_unlikely (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *))
<= match_last)) <= match_last))
return REG_ESPACE; return REG_ESPACE;
sifted_states = re_malloc (re_dfastate_t *, match_last + 1); sifted_states = re_malloc (re_dfastate_t *, match_last + 1);
if (__glibc_unlikely (sifted_states == NULL)) if (__glibc_unlikely (sifted_states == NULL))
skipping to change at line 1074 skipping to change at line 1057
Idx cur_str_idx = re_string_cur_idx (&mctx->input); Idx cur_str_idx = re_string_cur_idx (&mctx->input);
re_dfastate_t *cur_state; re_dfastate_t *cur_state;
bool at_init_state = p_match_first != NULL; bool at_init_state = p_match_first != NULL;
Idx next_start_idx = cur_str_idx; Idx next_start_idx = cur_str_idx;
err = REG_NOERROR; err = REG_NOERROR;
cur_state = acquire_init_state_context (&err, mctx, cur_str_idx); cur_state = acquire_init_state_context (&err, mctx, cur_str_idx);
/* An initial state must not be NULL (invalid). */ /* An initial state must not be NULL (invalid). */
if (__glibc_unlikely (cur_state == NULL)) if (__glibc_unlikely (cur_state == NULL))
{ {
assert (err == REG_ESPACE); DEBUG_ASSERT (err == REG_ESPACE);
return -2; return -2;
} }
if (mctx->state_log != NULL) if (mctx->state_log != NULL)
{ {
mctx->state_log[cur_str_idx] = cur_state; mctx->state_log[cur_str_idx] = cur_state;
/* Check OP_OPEN_SUBEXP in the initial state in case that we use them /* Check OP_OPEN_SUBEXP in the initial state in case that we use them
later. E.g. Processing back references. */ later. E.g. Processing back references. */
if (__glibc_unlikely (dfa->nbackref)) if (__glibc_unlikely (dfa->nbackref))
skipping to change at line 1129 skipping to change at line 1112
Idx next_char_idx = re_string_cur_idx (&mctx->input) + 1; Idx next_char_idx = re_string_cur_idx (&mctx->input) + 1;
if ((__glibc_unlikely (next_char_idx >= mctx->input.bufs_len) if ((__glibc_unlikely (next_char_idx >= mctx->input.bufs_len)
&& mctx->input.bufs_len < mctx->input.len) && mctx->input.bufs_len < mctx->input.len)
|| (__glibc_unlikely (next_char_idx >= mctx->input.valid_len) || (__glibc_unlikely (next_char_idx >= mctx->input.valid_len)
&& mctx->input.valid_len < mctx->input.len)) && mctx->input.valid_len < mctx->input.len))
{ {
err = extend_buffers (mctx, next_char_idx + 1); err = extend_buffers (mctx, next_char_idx + 1);
if (__glibc_unlikely (err != REG_NOERROR)) if (__glibc_unlikely (err != REG_NOERROR))
{ {
assert (err == REG_ESPACE); DEBUG_ASSERT (err == REG_ESPACE);
return -2; return -2;
} }
} }
cur_state = transit_state (&err, mctx, cur_state); cur_state = transit_state (&err, mctx, cur_state);
if (mctx->state_log != NULL) if (mctx->state_log != NULL)
cur_state = merge_state_with_log (&err, mctx, cur_state); cur_state = merge_state_with_log (&err, mctx, cur_state);
if (cur_state == NULL) if (cur_state == NULL)
{ {
skipping to change at line 1212 skipping to change at line 1195
/* Check the halt state STATE match the current context. /* Check the halt state STATE match the current context.
Return 0 if not match, if the node, STATE has, is a halt node and Return 0 if not match, if the node, STATE has, is a halt node and
match the context, return the node. */ match the context, return the node. */
static Idx static Idx
check_halt_state_context (const re_match_context_t *mctx, check_halt_state_context (const re_match_context_t *mctx,
const re_dfastate_t *state, Idx idx) const re_dfastate_t *state, Idx idx)
{ {
Idx i; Idx i;
unsigned int context; unsigned int context;
#ifdef DEBUG DEBUG_ASSERT (state->halt);
assert (state->halt);
#endif
context = re_string_context_at (&mctx->input, idx, mctx->eflags); context = re_string_context_at (&mctx->input, idx, mctx->eflags);
for (i = 0; i < state->nodes.nelem; ++i) for (i = 0; i < state->nodes.nelem; ++i)
if (check_halt_node_context (mctx->dfa, state->nodes.elems[i], context)) if (check_halt_node_context (mctx->dfa, state->nodes.elems[i], context))
return state->nodes.elems[i]; return state->nodes.elems[i];
return 0; return 0;
} }
/* Compute the next node to which "NFA" transit from NODE("NFA" is a NFA /* Compute the next node to which "NFA" transit from NODE("NFA" is a NFA
corresponding to the DFA). corresponding to the DFA).
Return the destination node, and update EPS_VIA_NODES; Return the destination node, and update EPS_VIA_NODES;
skipping to change at line 1285 skipping to change at line 1266
re_token_type_t type = dfa->nodes[node].type; re_token_type_t type = dfa->nodes[node].type;
#ifdef RE_ENABLE_I18N #ifdef RE_ENABLE_I18N
if (dfa->nodes[node].accept_mb) if (dfa->nodes[node].accept_mb)
naccepted = check_node_accept_bytes (dfa, node, &mctx->input, *pidx); naccepted = check_node_accept_bytes (dfa, node, &mctx->input, *pidx);
else else
#endif /* RE_ENABLE_I18N */ #endif /* RE_ENABLE_I18N */
if (type == OP_BACK_REF) if (type == OP_BACK_REF)
{ {
Idx subexp_idx = dfa->nodes[node].opr.idx + 1; Idx subexp_idx = dfa->nodes[node].opr.idx + 1;
naccepted = regs[subexp_idx].rm_eo - regs[subexp_idx].rm_so; if (subexp_idx < nregs)
naccepted = regs[subexp_idx].rm_eo - regs[subexp_idx].rm_so;
if (fs != NULL) if (fs != NULL)
{ {
if (regs[subexp_idx].rm_so == -1 || regs[subexp_idx].rm_eo == -1) if (subexp_idx >= nregs
|| regs[subexp_idx].rm_so == -1
|| regs[subexp_idx].rm_eo == -1)
return -1; return -1;
else if (naccepted) else if (naccepted)
{ {
char *buf = (char *) re_string_get_buffer (&mctx->input); char *buf = (char *) re_string_get_buffer (&mctx->input);
if (mctx->input.valid_len - *pidx < naccepted if (mctx->input.valid_len - *pidx < naccepted
|| (memcmp (buf + regs[subexp_idx].rm_so, buf + *pidx, || (memcmp (buf + regs[subexp_idx].rm_so, buf + *pidx,
naccepted) naccepted)
!= 0)) != 0))
return -1; return -1;
} }
skipping to change at line 1362 skipping to change at line 1346
memcpy (fs->stack[num].regs, regs, sizeof (regmatch_t) * nregs); memcpy (fs->stack[num].regs, regs, sizeof (regmatch_t) * nregs);
err = re_node_set_init_copy (&fs->stack[num].eps_via_nodes, eps_via_nodes); err = re_node_set_init_copy (&fs->stack[num].eps_via_nodes, eps_via_nodes);
return err; return err;
} }
static Idx static Idx
pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs, pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs,
regmatch_t *regs, re_node_set *eps_via_nodes) regmatch_t *regs, re_node_set *eps_via_nodes)
{ {
Idx num = --fs->num; Idx num = --fs->num;
assert (num >= 0); DEBUG_ASSERT (num >= 0);
*pidx = fs->stack[num].idx; *pidx = fs->stack[num].idx;
memcpy (regs, fs->stack[num].regs, sizeof (regmatch_t) * nregs); memcpy (regs, fs->stack[num].regs, sizeof (regmatch_t) * nregs);
re_node_set_free (eps_via_nodes); re_node_set_free (eps_via_nodes);
re_free (fs->stack[num].regs); re_free (fs->stack[num].regs);
*eps_via_nodes = fs->stack[num].eps_via_nodes; *eps_via_nodes = fs->stack[num].eps_via_nodes;
return fs->stack[num].node; return fs->stack[num].node;
} }
/* Set the positions where the subexpressions are starts/ends to registers /* Set the positions where the subexpressions are starts/ends to registers
PMATCH. PMATCH.
skipping to change at line 1389 skipping to change at line 1373
regmatch_t *pmatch, bool fl_backtrack) regmatch_t *pmatch, bool fl_backtrack)
{ {
const re_dfa_t *dfa = preg->buffer; const re_dfa_t *dfa = preg->buffer;
Idx idx, cur_node; Idx idx, cur_node;
re_node_set eps_via_nodes; re_node_set eps_via_nodes;
struct re_fail_stack_t *fs; struct re_fail_stack_t *fs;
struct re_fail_stack_t fs_body = { 0, 2, NULL }; struct re_fail_stack_t fs_body = { 0, 2, NULL };
regmatch_t *prev_idx_match; regmatch_t *prev_idx_match;
bool prev_idx_match_malloced = false; bool prev_idx_match_malloced = false;
#ifdef DEBUG DEBUG_ASSERT (nmatch > 1);
assert (nmatch > 1); DEBUG_ASSERT (mctx->state_log != NULL);
assert (mctx->state_log != NULL);
#endif
if (fl_backtrack) if (fl_backtrack)
{ {
fs = &fs_body; fs = &fs_body;
fs->stack = re_malloc (struct re_fail_stack_ent_t, fs->alloc); fs->stack = re_malloc (struct re_fail_stack_ent_t, fs->alloc);
if (fs->stack == NULL) if (fs->stack == NULL)
return REG_ESPACE; return REG_ESPACE;
} }
else else
fs = NULL; fs = NULL;
skipping to change at line 1578 skipping to change at line 1560
((state) != NULL && re_node_set_contains (&(state)->nodes, node)) ((state) != NULL && re_node_set_contains (&(state)->nodes, node))
static reg_errcode_t static reg_errcode_t
sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx) sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx)
{ {
reg_errcode_t err; reg_errcode_t err;
int null_cnt = 0; int null_cnt = 0;
Idx str_idx = sctx->last_str_idx; Idx str_idx = sctx->last_str_idx;
re_node_set cur_dest; re_node_set cur_dest;
#ifdef DEBUG DEBUG_ASSERT (mctx->state_log != NULL && mctx->state_log[str_idx] != NULL);
assert (mctx->state_log != NULL && mctx->state_log[str_idx] != NULL);
#endif
/* Build sifted state_log[str_idx]. It has the nodes which can epsilon /* Build sifted state_log[str_idx]. It has the nodes which can epsilon
transit to the last_node and the last_node itself. */ transit to the last_node and the last_node itself. */
err = re_node_set_init_1 (&cur_dest, sctx->last_node); err = re_node_set_init_1 (&cur_dest, sctx->last_node);
if (__glibc_unlikely (err != REG_NOERROR)) if (__glibc_unlikely (err != REG_NOERROR))
return err; return err;
err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest); err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest);
if (__glibc_unlikely (err != REG_NOERROR)) if (__glibc_unlikely (err != REG_NOERROR))
goto free_return; goto free_return;
skipping to change at line 1648 skipping to change at line 1628
'sifted_states[str_idx]' with 'cur_dest'. 'sifted_states[str_idx]' with 'cur_dest'.
Note: Note:
'cur_dest' is the sifted state from 'state_log[str_idx + 1]'. 'cur_dest' is the sifted state from 'state_log[str_idx + 1]'.
'cur_src' points the node_set of the old 'state_log[str_idx]' 'cur_src' points the node_set of the old 'state_log[str_idx]'
(with the epsilon nodes pre-filtered out). */ (with the epsilon nodes pre-filtered out). */
for (i = 0; i < cur_src->nelem; i++) for (i = 0; i < cur_src->nelem; i++)
{ {
Idx prev_node = cur_src->elems[i]; Idx prev_node = cur_src->elems[i];
int naccepted = 0; int naccepted = 0;
bool ok; bool ok;
DEBUG_ASSERT (!IS_EPSILON_NODE (dfa->nodes[prev_node].type));
#ifdef DEBUG
re_token_type_t type = dfa->nodes[prev_node].type;
assert (!IS_EPSILON_NODE (type));
#endif
#ifdef RE_ENABLE_I18N #ifdef RE_ENABLE_I18N
/* If the node may accept "multi byte". */ /* If the node may accept "multi byte". */
if (dfa->nodes[prev_node].accept_mb) if (dfa->nodes[prev_node].accept_mb)
naccepted = sift_states_iter_mb (mctx, sctx, prev_node, naccepted = sift_states_iter_mb (mctx, sctx, prev_node,
str_idx, sctx->last_str_idx); str_idx, sctx->last_str_idx);
#endif /* RE_ENABLE_I18N */ #endif /* RE_ENABLE_I18N */
/* We don't check backreferences here. /* We don't check backreferences here.
See update_cur_sifted_state(). */ See update_cur_sifted_state(). */
if (!naccepted if (!naccepted
skipping to change at line 2502 skipping to change at line 2479
if (naccepted == 0) if (naccepted == 0)
continue; continue;
/* The node can accepts 'naccepted' bytes. */ /* The node can accepts 'naccepted' bytes. */
dest_idx = re_string_cur_idx (&mctx->input) + naccepted; dest_idx = re_string_cur_idx (&mctx->input) + naccepted;
mctx->max_mb_elem_len = ((mctx->max_mb_elem_len < naccepted) ? naccepted mctx->max_mb_elem_len = ((mctx->max_mb_elem_len < naccepted) ? naccepted
: mctx->max_mb_elem_len); : mctx->max_mb_elem_len);
err = clean_state_log_if_needed (mctx, dest_idx); err = clean_state_log_if_needed (mctx, dest_idx);
if (__glibc_unlikely (err != REG_NOERROR)) if (__glibc_unlikely (err != REG_NOERROR))
return err; return err;
#ifdef DEBUG DEBUG_ASSERT (dfa->nexts[cur_node_idx] != -1);
assert (dfa->nexts[cur_node_idx] != -1);
#endif
new_nodes = dfa->eclosures + dfa->nexts[cur_node_idx]; new_nodes = dfa->eclosures + dfa->nexts[cur_node_idx];
dest_state = mctx->state_log[dest_idx]; dest_state = mctx->state_log[dest_idx];
if (dest_state == NULL) if (dest_state == NULL)
dest_nodes = *new_nodes; dest_nodes = *new_nodes;
else else
{ {
err = re_node_set_init_union (&dest_nodes, err = re_node_set_init_union (&dest_nodes,
dest_state->entrance_nodes, new_nodes); dest_state->entrance_nodes, new_nodes);
if (__glibc_unlikely (err != REG_NOERROR)) if (__glibc_unlikely (err != REG_NOERROR))
skipping to change at line 2568 skipping to change at line 2543
/* 'node' is a backreference. /* 'node' is a backreference.
Check the substring which the substring matched. */ Check the substring which the substring matched. */
bkc_idx = mctx->nbkref_ents; bkc_idx = mctx->nbkref_ents;
err = get_subexp (mctx, node_idx, cur_str_idx); err = get_subexp (mctx, node_idx, cur_str_idx);
if (__glibc_unlikely (err != REG_NOERROR)) if (__glibc_unlikely (err != REG_NOERROR))
goto free_return; goto free_return;
/* And add the epsilon closures (which is 'new_dest_nodes') of /* And add the epsilon closures (which is 'new_dest_nodes') of
the backreference to appropriate state_log. */ the backreference to appropriate state_log. */
#ifdef DEBUG DEBUG_ASSERT (dfa->nexts[node_idx] != -1);
assert (dfa->nexts[node_idx] != -1);
#endif
for (; bkc_idx < mctx->nbkref_ents; ++bkc_idx) for (; bkc_idx < mctx->nbkref_ents; ++bkc_idx)
{ {
Idx subexp_len; Idx subexp_len;
re_dfastate_t *dest_state; re_dfastate_t *dest_state;
struct re_backref_cache_entry *bkref_ent; struct re_backref_cache_entry *bkref_ent;
bkref_ent = mctx->bkref_ents + bkc_idx; bkref_ent = mctx->bkref_ents + bkc_idx;
if (bkref_ent->node != node_idx || bkref_ent->str_idx != cur_str_idx) if (bkref_ent->node != node_idx || bkref_ent->str_idx != cur_str_idx)
continue; continue;
subexp_len = bkref_ent->subexp_to - bkref_ent->subexp_from; subexp_len = bkref_ent->subexp_to - bkref_ent->subexp_from;
new_dest_nodes = (subexp_len == 0 new_dest_nodes = (subexp_len == 0
skipping to change at line 3029 skipping to change at line 3002
Idx cur_idx; Idx cur_idx;
#ifdef RE_ENABLE_I18N #ifdef RE_ENABLE_I18N
reg_errcode_t err = REG_NOERROR; reg_errcode_t err = REG_NOERROR;
#endif #endif
re_node_set union_set; re_node_set union_set;
re_node_set_init_empty (&union_set); re_node_set_init_empty (&union_set);
for (cur_idx = 0; cur_idx < cur_nodes->nelem; ++cur_idx) for (cur_idx = 0; cur_idx < cur_nodes->nelem; ++cur_idx)
{ {
int naccepted = 0; int naccepted = 0;
Idx cur_node = cur_nodes->elems[cur_idx]; Idx cur_node = cur_nodes->elems[cur_idx];
#ifdef DEBUG DEBUG_ASSERT (!IS_EPSILON_NODE (dfa->nodes[cur_node].type));
re_token_type_t type = dfa->nodes[cur_node].type;
assert (!IS_EPSILON_NODE (type));
#endif
#ifdef RE_ENABLE_I18N #ifdef RE_ENABLE_I18N
/* If the node may accept "multi byte". */ /* If the node may accept "multi byte". */
if (dfa->nodes[cur_node].accept_mb) if (dfa->nodes[cur_node].accept_mb)
{ {
naccepted = check_node_accept_bytes (dfa, cur_node, &mctx->input, naccepted = check_node_accept_bytes (dfa, cur_node, &mctx->input,
str_idx); str_idx);
if (naccepted > 1) if (naccepted > 1)
{ {
re_dfastate_t *dest_state; re_dfastate_t *dest_state;
Idx next_node = dfa->nexts[cur_node]; Idx next_node = dfa->nexts[cur_node];
skipping to change at line 3100 skipping to change at line 3071
- out of the sub expression whose number is EX_SUBEXP, if !FL_OPEN. - out of the sub expression whose number is EX_SUBEXP, if !FL_OPEN.
*/ */
static reg_errcode_t static reg_errcode_t
check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes, check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes,
Idx ex_subexp, int type) Idx ex_subexp, int type)
{ {
reg_errcode_t err; reg_errcode_t err;
Idx idx, outside_node; Idx idx, outside_node;
re_node_set new_nodes; re_node_set new_nodes;
#ifdef DEBUG DEBUG_ASSERT (cur_nodes->nelem);
assert (cur_nodes->nelem);
#endif
err = re_node_set_alloc (&new_nodes, cur_nodes->nelem); err = re_node_set_alloc (&new_nodes, cur_nodes->nelem);
if (__glibc_unlikely (err != REG_NOERROR)) if (__glibc_unlikely (err != REG_NOERROR))
return err; return err;
/* Create a new node set NEW_NODES with the nodes which are epsilon /* Create a new node set NEW_NODES with the nodes which are epsilon
closures of the node in CUR_NODES. */ closures of the node in CUR_NODES. */
for (idx = 0; idx < cur_nodes->nelem; ++idx) for (idx = 0; idx < cur_nodes->nelem; ++idx)
{ {
Idx cur_node = cur_nodes->elems[idx]; Idx cur_node = cur_nodes->elems[idx];
const re_node_set *eclosure = dfa->eclosures + cur_node; const re_node_set *eclosure = dfa->eclosures + cur_node;
skipping to change at line 3691 skipping to change at line 3660
if (j == ndests) if (j == ndests)
{ {
bitset_copy (dests_ch[ndests], accepts); bitset_copy (dests_ch[ndests], accepts);
err = re_node_set_init_1 (dests_node + ndests, cur_nodes->elems[i]); err = re_node_set_init_1 (dests_node + ndests, cur_nodes->elems[i]);
if (__glibc_unlikely (err != REG_NOERROR)) if (__glibc_unlikely (err != REG_NOERROR))
goto error_return; goto error_return;
++ndests; ++ndests;
bitset_empty (accepts); bitset_empty (accepts);
} }
} }
assume (ndests <= SBC_MAX);
return ndests; return ndests;
error_return: error_return:
for (j = 0; j < ndests; ++j) for (j = 0; j < ndests; ++j)
re_node_set_free (dests_node + j); re_node_set_free (dests_node + j);
return -1; return -1;
} }
#ifdef RE_ENABLE_I18N #ifdef RE_ENABLE_I18N
/* Check how many bytes the node 'dfa->nodes[node_idx]' accepts. /* Check how many bytes the node 'dfa->nodes[node_idx]' accepts.
Return the number of the bytes the node accepts. Return the number of the bytes the node accepts.
skipping to change at line 4266 skipping to change at line 4236
return -1; return -1;
} }
/* Register the node NODE, whose type is OP_OPEN_SUBEXP, and which matches /* Register the node NODE, whose type is OP_OPEN_SUBEXP, and which matches
at STR_IDX. */ at STR_IDX. */
static reg_errcode_t static reg_errcode_t
__attribute_warn_unused_result__ __attribute_warn_unused_result__
match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx) match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx)
{ {
#ifdef DEBUG DEBUG_ASSERT (mctx->sub_tops != NULL);
assert (mctx->sub_tops != NULL); DEBUG_ASSERT (mctx->asub_tops > 0);
assert (mctx->asub_tops > 0);
#endif
if (__glibc_unlikely (mctx->nsub_tops == mctx->asub_tops)) if (__glibc_unlikely (mctx->nsub_tops == mctx->asub_tops))
{ {
Idx new_asub_tops = mctx->asub_tops * 2; Idx new_asub_tops = mctx->asub_tops * 2;
re_sub_match_top_t **new_array = re_realloc (mctx->sub_tops, re_sub_match_top_t **new_array = re_realloc (mctx->sub_tops,
re_sub_match_top_t *, re_sub_match_top_t *,
new_asub_tops); new_asub_tops);
if (__glibc_unlikely (new_array == NULL)) if (__glibc_unlikely (new_array == NULL))
return REG_ESPACE; return REG_ESPACE;
mctx->sub_tops = new_array; mctx->sub_tops = new_array;
mctx->asub_tops = new_asub_tops; mctx->asub_tops = new_asub_tops;
 End of changes. 28 change blocks. 
62 lines changed or deleted 29 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)