int ret_len) internal_function;
static unsigned re_copy_regs (struct re_registers *regs, regmatch_t *pmatch,
int nregs, int regs_allocated) internal_function;
-static inline re_dfastate_t *acquire_init_state_context
- (reg_errcode_t *err, const re_match_context_t *mctx, int idx)
- __attribute ((always_inline)) internal_function;
static reg_errcode_t prune_impossible_nodes (re_match_context_t *mctx)
internal_function;
static int check_matching (re_match_context_t *mctx, int fl_longest_match,
int *p_match_first)
internal_function;
-static int check_halt_node_context (const re_dfa_t *dfa, int node,
- unsigned int context) internal_function;
static int check_halt_state_context (const re_match_context_t *mctx,
const re_dfastate_t *state, int idx)
internal_function;
static void update_regs (re_dfa_t *dfa, regmatch_t *pmatch,
regmatch_t *prev_idx_match, int cur_node,
int cur_idx, int nmatch) internal_function;
-static int proceed_next_node (const re_match_context_t *mctx,
- int nregs, regmatch_t *regs,
- int *pidx, int node, re_node_set *eps_via_nodes,
- struct re_fail_stack_t *fs) internal_function;
static reg_errcode_t push_fail_stack (struct re_fail_stack_t *fs,
int str_idx, int dest_node, int nregs,
regmatch_t *regs,
re_node_set *eps_via_nodes) internal_function;
-static int pop_fail_stack (struct re_fail_stack_t *fs, int *pidx, int nregs,
- regmatch_t *regs, re_node_set *eps_via_nodes) internal_function;
static reg_errcode_t set_regs (const regex_t *preg,
const re_match_context_t *mctx,
size_t nmatch, regmatch_t *pmatch,
static reg_errcode_t add_epsilon_src_nodes (re_dfa_t *dfa,
re_node_set *dest_nodes,
const re_node_set *candidates) internal_function;
-static reg_errcode_t sub_epsilon_src_nodes (re_dfa_t *dfa, int node,
- re_node_set *dest_nodes,
- const re_node_set *and_nodes) internal_function;
static int check_dst_limits (re_match_context_t *mctx, re_node_set *limits,
int dst_node, int dst_idx, int src_node,
int src_idx) internal_function;
static reg_errcode_t sift_states_bkref (re_match_context_t *mctx,
re_sift_context_t *sctx,
int str_idx, const re_node_set *candidates) internal_function;
-static reg_errcode_t clean_state_log_if_needed (re_match_context_t *mctx,
- int next_state_log_idx) internal_function;
static reg_errcode_t merge_state_array (re_dfa_t *dfa, re_dfastate_t **dst,
re_dfastate_t **src, int num) internal_function;
static re_dfastate_t *find_recover_state (reg_errcode_t *err,
reg_errcode_t err;
int start, length;
#ifdef _LIBC
- re_dfa_t *dfa = (re_dfa_t *)preg->buffer;
+ re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
#endif
if (eflags & ~(REG_NOTBOL | REG_NOTEOL | REG_STARTEND))
}
__libc_lock_lock (dfa->lock);
- if (preg->no_sub)
+ if (preg->re_no_sub)
err = re_search_internal (preg, string, length, start, length - start,
length, 0, NULL, eflags);
else
the first STOP characters of the concatenation of the strings should be
concerned.
- If REGS is not NULL, and BUFP->no_sub is not set, the offsets of the match
+ If REGS is not NULL, and BUFP->re_no_sub is not set, the offsets of the match
and all groups is stroed in REGS. (For the "_2" variants, the offsets are
computed relative to the concatenation, not relative to the individual
strings.)
int nregs, rval;
int eflags = 0;
#ifdef _LIBC
- re_dfa_t *dfa = (re_dfa_t *)bufp->buffer;
+ re_dfa_t *dfa = (re_dfa_t *) bufp->re_buffer;
#endif
/* Check for out-of-range. */
__libc_lock_lock (dfa->lock);
- eflags |= (bufp->not_bol) ? REG_NOTBOL : 0;
- eflags |= (bufp->not_eol) ? REG_NOTEOL : 0;
+ eflags |= (bufp->re_not_bol) ? REG_NOTBOL : 0;
+ eflags |= (bufp->re_not_eol) ? REG_NOTEOL : 0;
/* Compile fastmap if we haven't yet. */
- if (range > 0 && bufp->fastmap != NULL && !bufp->fastmap_accurate)
+ if (range > 0 && bufp->re_fastmap != NULL && !bufp->re_fastmap_accurate)
re_compile_fastmap (bufp);
- if (BE (bufp->no_sub, 0))
+ if (BE (bufp->re_no_sub, 0))
regs = NULL;
/* We need at least 1 register. */
if (regs == NULL)
nregs = 1;
- else if (BE (bufp->regs_allocated == REGS_FIXED &&
- regs->num_regs < bufp->re_nsub + 1, 0))
+ else if (BE (bufp->re_regs_allocated == REG_FIXED
+ && regs->rm_num_regs < bufp->re_nsub + 1, 0))
{
- nregs = regs->num_regs;
+ nregs = regs->rm_num_regs;
if (BE (nregs < 1, 0))
{
/* Nothing can be copied to regs. */
else if (regs != NULL)
{
/* If caller wants register contents data back, copy them. */
- bufp->regs_allocated = re_copy_regs (regs, pmatch, nregs,
- bufp->regs_allocated);
- if (BE (bufp->regs_allocated == REGS_UNALLOCATED, 0))
+ bufp->re_regs_allocated = re_copy_regs (regs, pmatch, nregs,
+ bufp->re_regs_allocated);
+ if (BE (bufp->re_regs_allocated == REG_UNALLOCATED, 0))
rval = -2;
}
re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, int nregs,
int regs_allocated)
{
- int rval = REGS_REALLOCATE;
+ int rval = REG_REALLOCATE;
int i;
int need_regs = nregs + 1;
- /* We need one extra element beyond `num_regs' for the `-1' marker GNU code
+ /* We need one extra element beyond `rm_num_regs' for the `-1' marker GNU code
uses. */
/* Have the register data arrays been allocated? */
- if (regs_allocated == REGS_UNALLOCATED)
+ if (regs_allocated == REG_UNALLOCATED)
{ /* No. So allocate them with malloc. */
- regs->start = re_malloc (regoff_t, need_regs);
- regs->end = re_malloc (regoff_t, need_regs);
- if (BE (regs->start == NULL, 0) || BE (regs->end == NULL, 0))
- return REGS_UNALLOCATED;
- regs->num_regs = need_regs;
+ regs->rm_start = re_malloc (regoff_t, need_regs);
+ regs->rm_end = re_malloc (regoff_t, need_regs);
+ if (BE (regs->rm_start == NULL, 0) || BE (regs->rm_end == NULL, 0))
+ return REG_UNALLOCATED;
+ regs->rm_num_regs = need_regs;
}
- else if (regs_allocated == REGS_REALLOCATE)
+ else if (regs_allocated == REG_REALLOCATE)
{ /* Yes. If we need more elements than were already
allocated, reallocate them. If we need fewer, just
leave it alone. */
- if (BE (need_regs > regs->num_regs, 0))
+ if (BE (need_regs > regs->rm_num_regs, 0))
{
- regoff_t *new_start = re_realloc (regs->start, regoff_t, need_regs);
- regoff_t *new_end = re_realloc (regs->end, regoff_t, need_regs);
+ regoff_t *new_start =
+ re_realloc (regs->rm_start, regoff_t, need_regs);
+ regoff_t *new_end = re_realloc (regs->rm_end, regoff_t, need_regs);
if (BE (new_start == NULL, 0) || BE (new_end == NULL, 0))
- return REGS_UNALLOCATED;
- regs->start = new_start;
- regs->end = new_end;
- regs->num_regs = need_regs;
+ return REG_UNALLOCATED;
+ regs->rm_start = new_start;
+ regs->rm_end = new_end;
+ regs->rm_num_regs = need_regs;
}
}
else
{
- assert (regs_allocated == REGS_FIXED);
- /* This function may not be called with REGS_FIXED and nregs too big. */
- assert (regs->num_regs >= nregs);
- rval = REGS_FIXED;
+ assert (regs_allocated == REG_FIXED);
+ /* This function may not be called with REG_FIXED and nregs too big. */
+ assert (regs->rm_num_regs >= nregs);
+ rval = REG_FIXED;
}
/* Copy the regs. */
for (i = 0; i < nregs; ++i)
{
- regs->start[i] = pmatch[i].rm_so;
- regs->end[i] = pmatch[i].rm_eo;
+ regs->rm_start[i] = pmatch[i].rm_so;
+ regs->rm_end[i] = pmatch[i].rm_eo;
}
- for ( ; i < regs->num_regs; ++i)
- regs->start[i] = regs->end[i] = -1;
+ for ( ; i < regs->rm_num_regs; ++i)
+ regs->rm_start[i] = regs->rm_end[i] = -1;
return rval;
}
{
if (num_regs)
{
- bufp->regs_allocated = REGS_REALLOCATE;
- regs->num_regs = num_regs;
- regs->start = starts;
- regs->end = ends;
+ bufp->re_regs_allocated = REG_REALLOCATE;
+ regs->rm_num_regs = num_regs;
+ regs->rm_start = starts;
+ regs->rm_end = ends;
}
else
{
- bufp->regs_allocated = REGS_UNALLOCATED;
- regs->num_regs = 0;
- regs->start = regs->end = (regoff_t *) 0;
+ bufp->re_regs_allocated = REG_UNALLOCATED;
+ regs->rm_num_regs = 0;
+ regs->rm_start = regs->rm_end = NULL;
}
}
#ifdef _LIBC
int eflags)
{
reg_errcode_t err;
- re_dfa_t *dfa = (re_dfa_t *)preg->buffer;
+ re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
int left_lim, right_lim, incr;
int fl_longest_match, match_first, match_kind, match_last = -1;
int extra_nmatch;
#else
re_match_context_t mctx;
#endif
- char *fastmap = (preg->fastmap != NULL && preg->fastmap_accurate
- && range && !preg->can_be_null) ? preg->fastmap : NULL;
- unsigned RE_TRANSLATE_TYPE t = (unsigned RE_TRANSLATE_TYPE) preg->translate;
+ char *fastmap = (preg->re_fastmap != NULL && preg->re_fastmap_accurate
+ && range && !preg->re_can_be_null) ? preg->re_fastmap : NULL;
+ unsigned REG_TRANSLATE_TYPE t =
+ (unsigned REG_TRANSLATE_TYPE) preg->re_translate;
#if !(defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
memset (&mctx, '\0', sizeof (re_match_context_t));
nmatch -= extra_nmatch;
/* Check if the DFA haven't been compiled. */
- if (BE (preg->used == 0 || dfa->init_state == NULL
+ if (BE (preg->re_used == 0 || dfa->init_state == NULL
|| dfa->init_state_word == NULL || dfa->init_state_nl == NULL
|| dfa->init_state_begbuf == NULL, 0))
return REG_NOMATCH;
#endif
/* 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->re_newline_anchor is set,
we'll never use init_state_nl, so do not check it. */
if (dfa->init_state->nodes.nelem == 0
&& dfa->init_state_word->nodes.nelem == 0
&& (dfa->init_state_nl->nodes.nelem == 0
- || !preg->newline_anchor))
+ || !preg->re_newline_anchor))
{
if (start != 0 && start + range != 0)
return REG_NOMATCH;
fl_longest_match = (nmatch != 0 || dfa->nbackref);
err = re_string_allocate (&mctx.input, string, length, dfa->nodes_len + 1,
- preg->translate, preg->syntax & RE_ICASE, dfa);
+ preg->re_translate,
+ preg->re_syntax & REG_IGNORE_CASE, dfa);
if (BE (err != REG_NOERROR, 0))
goto free_return;
mctx.input.stop = stop;
mctx.input.raw_stop = stop;
- mctx.input.newline_anchor = preg->newline_anchor;
+ mctx.input.newline_anchor = preg->re_newline_anchor;
err = match_ctx_init (&mctx, eflags, dfa->nbackref * 2);
if (BE (err != REG_NOERROR, 0))
sb = dfa->mb_cur_max == 1;
match_kind =
(fastmap
- ? ((sb || !(preg->syntax & RE_ICASE || t) ? 4 : 0)
+ ? ((sb || !(preg->re_syntax & REG_IGNORE_CASE || t) ? 4 : 0)
| (range >= 0 ? 2 : 0)
| (t != NULL ? 1 : 0))
: 8);
else
{
mctx.match_last = match_last;
- if ((!preg->no_sub && nmatch > 1) || dfa->nbackref)
+ if ((!preg->re_no_sub && nmatch > 1) || dfa->nbackref)
{
re_dfastate_t *pstate = mctx.state_log[match_last];
mctx.last_node = check_halt_state_context (&mctx, pstate,
match_last);
}
- if ((!preg->no_sub && nmatch > 1 && dfa->has_plural_match)
+ if ((!preg->re_no_sub && nmatch > 1 && dfa->has_plural_match)
|| dfa->nbackref)
{
err = prune_impossible_nodes (&mctx);
pmatch[0].rm_so = 0;
pmatch[0].rm_eo = mctx.match_last;
- if (!preg->no_sub && nmatch > 1)
+ if (!preg->re_no_sub && nmatch > 1)
{
err = set_regs (preg, &mctx, nmatch, pmatch,
dfa->has_plural_match && dfa->nbackref > 0);
since initial states may have constraints like "\<", "^", etc.. */
static inline re_dfastate_t *
-internal_function
+__attribute ((always_inline)) internal_function
acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx,
int idx)
{
int num = fs->num++;
if (fs->num == fs->alloc)
{
- struct re_fail_stack_ent_t *new_array;
- new_array = realloc (fs->stack, (sizeof (struct re_fail_stack_ent_t)
- * fs->alloc * 2));
+ struct re_fail_stack_ent_t *new_array =
+ re_realloc (fs->stack, struct re_fail_stack_ent_t, fs->alloc * 2);
if (new_array == NULL)
return REG_ESPACE;
fs->alloc *= 2;
set_regs (const regex_t *preg, const re_match_context_t *mctx,
size_t nmatch, regmatch_t *pmatch, int fl_backtrack)
{
- re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+ re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
int idx, cur_node;
re_node_set eps_via_nodes;
struct re_fail_stack_t *fs;
struct re_fail_stack_t fs_body = { 0, 2, NULL };
regmatch_t *prev_idx_match;
+ int prev_idx_match_malloced = 0;
#ifdef DEBUG
assert (nmatch > 1);
cur_node = dfa->init_node;
re_node_set_init_empty (&eps_via_nodes);
- prev_idx_match = (regmatch_t *) alloca (sizeof (regmatch_t) * nmatch);
+ if (__libc_use_alloca (nmatch * sizeof (regmatch_t)))
+ prev_idx_match = (regmatch_t *) alloca (nmatch * sizeof (regmatch_t));
+ else
+ {
+ prev_idx_match = re_malloc (regmatch_t, nmatch);
+ if (prev_idx_match == NULL)
+ {
+ free_fail_stack_return (fs);
+ return REG_ESPACE;
+ }
+ prev_idx_match_malloced = 1;
+ }
memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch);
for (idx = pmatch[0].rm_so; idx <= pmatch[0].rm_eo ;)
if (reg_idx == nmatch)
{
re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
return free_fail_stack_return (fs);
}
cur_node = pop_fail_stack (fs, &idx, nmatch, pmatch,
else
{
re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
return REG_NOERROR;
}
}
if (BE (cur_node == -2, 0))
{
re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
free_fail_stack_return (fs);
return REG_ESPACE;
}
else
{
re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
return REG_NOMATCH;
}
}
}
re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
return free_fail_stack_return (fs);
}
enabled_idx = first_idx;
do
{
- int subexp_len, to_idx, dst_node;
+ int subexp_len, to_idx, dst_node, ret;
re_dfastate_t *cur_state;
if (entry->node != node)
}
local_sctx.last_node = node;
local_sctx.last_str_idx = str_idx;
- err = re_node_set_insert (&local_sctx.limits, enabled_idx);
- if (BE (err < 0, 0))
+ ret = re_node_set_insert (&local_sctx.limits, enabled_idx);
+ if (BE (ret < 0, 0))
{
err = REG_ESPACE;
goto free_return;
cur_state = merge_state_with_log (err, mctx, NULL);
}
- while (err == REG_NOERROR && cur_state == NULL);
+ while (*err == REG_NOERROR && cur_state == NULL);
return cur_state;
}
continue; /* No. */
if (sub_top->path == NULL)
{
- sub_top->path = calloc (sizeof (state_array_t),
- sl_str - sub_top->str_idx + 1);
+ sub_top->path = re_calloc (state_array_t,
+ sl_str - sub_top->str_idx + 1);
if (sub_top->path == NULL)
return REG_ESPACE;
}
break;
if (dfa->edests[cur_node].nelem == 2)
{
- err = check_arrival_expand_ecl_sub (dfa, dst_nodes,
- dfa->edests[cur_node].elems[1],
- ex_subexp, type);
- if (BE (err != REG_NOERROR, 0))
- return err;
+ reg_errcode_t ret =
+ check_arrival_expand_ecl_sub (dfa, dst_nodes,
+ dfa->edests[cur_node].elems[1],
+ ex_subexp, type);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
}
cur_node = dfa->edests[cur_node].elems[0];
}
from `state'. `dests_node[i]' represents the nodes which i-th
destination state contains, and `dests_ch[i]' represents the
characters which i-th destination state accepts. */
-#ifdef _LIBC
if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX))
dests_node = (re_node_set *)
alloca ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX);
else
-#endif
{
dests_node = (re_node_set *)
malloc ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX);
/* Return 0 in case of an error, 1 otherwise. */
if (ndests == 0)
{
- state->trtable = (re_dfastate_t **)
- calloc (sizeof (re_dfastate_t *), SBC_MAX);
+ state->trtable = re_calloc (re_dfastate_t *, SBC_MAX);
return 1;
}
return 0;
if (BE (err != REG_NOERROR, 0))
goto out_free;
-#ifdef _LIBC
if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX
+ ndests * 3 * sizeof (re_dfastate_t *)))
dest_states = (re_dfastate_t **)
alloca (ndests * 3 * sizeof (re_dfastate_t *));
else
-#endif
{
dest_states = (re_dfastate_t **)
malloc (ndests * 3 * sizeof (re_dfastate_t *));
character, or we are in a single-byte character set so we can
discern by looking at the character code: allocate a
256-entry transition table. */
- trtable = state->trtable =
- (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX);
+ trtable = state->trtable = re_calloc (re_dfastate_t *, SBC_MAX);
if (BE (trtable == NULL, 0))
goto out_free;
by looking at the character code: build two 256-entry
transition tables, one starting at trtable[0] and one
starting at trtable[SBC_MAX]. */
- trtable = state->word_trtable =
- (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX);
+ trtable = state->word_trtable = re_calloc (re_dfastate_t *, 2 * SBC_MAX);
if (BE (trtable == NULL, 0))
goto out_free;
else
#endif
bitset_set_all (accepts);
- if (!(dfa->syntax & RE_DOT_NEWLINE))
+ if (!(dfa->syntax & REG_DOT_NEWLINE))
bitset_clear (accepts, '\n');
- if (dfa->syntax & RE_DOT_NOT_NULL)
+ if (dfa->syntax & REG_DOT_NOT_NULL)
bitset_clear (accepts, '\0');
}
#ifdef RE_ENABLE_I18N
else if (type == OP_UTF8_PERIOD)
{
memset (accepts, 255, sizeof (unsigned int) * BITSET_UINTS / 2);
- if (!(dfa->syntax & RE_DOT_NEWLINE))
+ if (!(dfa->syntax & REG_DOT_NEWLINE))
bitset_clear (accepts, '\n');
- if (dfa->syntax & RE_DOT_NOT_NULL)
+ if (dfa->syntax & REG_DOT_NOT_NULL)
bitset_clear (accepts, '\0');
}
#endif
/* FIXME: I don't think this if is needed, as both '\n'
and '\0' are char_len == 1. */
/* '.' accepts any one character except the following two cases. */
- if ((!(dfa->syntax & RE_DOT_NEWLINE) &&
+ if ((!(dfa->syntax & REG_DOT_NEWLINE) &&
re_string_byte_at (input, str_idx) == '\n') ||
- ((dfa->syntax & RE_DOT_NOT_NULL) &&
+ ((dfa->syntax & REG_DOT_NOT_NULL) &&
re_string_byte_at (input, str_idx) == '\0'))
return 0;
return char_len;
/* FALLTHROUGH */
#endif
case OP_PERIOD:
- if ((ch == '\n' && !(mctx->dfa->syntax & RE_DOT_NEWLINE))
- || (ch == '\0' && (mctx->dfa->syntax & RE_DOT_NOT_NULL)))
+ if ((ch == '\n' && !(mctx->dfa->syntax & REG_DOT_NEWLINE))
+ || (ch == '\0' && (mctx->dfa->syntax & REG_DOT_NOT_NULL)))
return 0;
break;
mctx->sub_tops = new_array;
mctx->asub_tops = new_asub_tops;
}
- mctx->sub_tops[mctx->nsub_tops] = calloc (1, sizeof (re_sub_match_top_t));
+ mctx->sub_tops[mctx->nsub_tops] = re_calloc (re_sub_match_top_t, 1);
if (BE (mctx->sub_tops[mctx->nsub_tops] == NULL, 0))
return REG_ESPACE;
mctx->sub_tops[mctx->nsub_tops]->node = node;
subtop->lasts = new_array;
subtop->alasts = new_alasts;
}
- new_entry = calloc (1, sizeof (re_sub_match_last_t));
+ new_entry = re_calloc (re_sub_match_last_t, 1);
if (BE (new_entry != NULL, 1))
{
subtop->lasts[subtop->nlasts] = new_entry;