X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fregexec.c;h=827b676df3e31a161babe7830e87a2541f37fd0a;hb=f58f44a2f9c2e9b8fc9ea2ca910bd070d1f8bd48;hp=96e0aa4c17983491c127d51f3486ba469a57deb8;hpb=79d7833a0789532be2c572578d82227f7dcd52dc;p=gnulib.git diff --git a/lib/regexec.c b/lib/regexec.c index 96e0aa4c1..827b676df 100644 --- a/lib/regexec.c +++ b/lib/regexec.c @@ -51,32 +51,21 @@ static int re_search_stub (struct re_pattern_buffer *bufp, 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, @@ -100,9 +89,6 @@ static reg_errcode_t update_cur_sifted_state (re_match_context_t *mctx, 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; @@ -122,8 +108,6 @@ static reg_errcode_t check_subexp_limits (re_dfa_t *dfa, 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, @@ -209,16 +193,14 @@ static reg_errcode_t extend_buffers (re_match_context_t *mctx) internal_function We return 0 if we find a match and REG_NOMATCH if not. */ int -regexec (preg, string, nmatch, pmatch, eflags) - const regex_t *__restrict preg; - const char *__restrict string; - size_t nmatch; - regmatch_t pmatch[]; - int eflags; +regexec (const regex_t *__restrict preg, const char *__restrict string, + size_t nmatch, regmatch_t pmatch[], int eflags) { reg_errcode_t err; int start, length; - re_dfa_t *dfa = (re_dfa_t *)preg->buffer; +#ifdef _LIBC + re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer; +#endif if (eflags & ~(REG_NOTBOL | REG_NOTEOL | REG_STARTEND)) return REG_BADPAT; @@ -235,7 +217,7 @@ regexec (preg, string, nmatch, pmatch, eflags) } __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 @@ -285,7 +267,7 @@ compat_symbol (libc, __compat_regexec, regexec, GLIBC_2_0); 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.) @@ -295,11 +277,8 @@ compat_symbol (libc, __compat_regexec, regexec, GLIBC_2_0); match was found and -2 indicates an internal error. */ int -re_match (bufp, string, length, start, regs) - struct re_pattern_buffer *bufp; - const char *string; - int length, start; - struct re_registers *regs; +re_match (struct re_pattern_buffer *bufp, const char *string, + int length, int start, struct re_registers *regs) { return re_search_stub (bufp, string, length, start, 0, length, regs, 1); } @@ -308,11 +287,8 @@ weak_alias (__re_match, re_match) #endif int -re_search (bufp, string, length, start, range, regs) - struct re_pattern_buffer *bufp; - const char *string; - int length, start, range; - struct re_registers *regs; +re_search (struct re_pattern_buffer *bufp, const char *string, + int length, int start, int range, struct re_registers *regs) { return re_search_stub (bufp, string, length, start, range, length, regs, 0); } @@ -321,11 +297,10 @@ weak_alias (__re_search, re_search) #endif int -re_match_2 (bufp, string1, length1, string2, length2, start, regs, stop) - struct re_pattern_buffer *bufp; - const char *string1, *string2; - int length1, length2, start, stop; - struct re_registers *regs; +re_match_2 (struct re_pattern_buffer *bufp, + const char *string1, int length1, + const char *string2, int length2, + int start, struct re_registers *regs, int stop) { return re_search_2_stub (bufp, string1, length1, string2, length2, start, 0, regs, stop, 1); @@ -335,11 +310,10 @@ weak_alias (__re_match_2, re_match_2) #endif int -re_search_2 (bufp, string1, length1, string2, length2, start, range, regs, stop) - struct re_pattern_buffer *bufp; - const char *string1, *string2; - int length1, length2, start, range, stop; - struct re_registers *regs; +re_search_2 (struct re_pattern_buffer *bufp, + const char *string1, int length1, + const char *string2, int length2, + int start, int range, struct re_registers *regs, int stop) { return re_search_2_stub (bufp, string1, length1, string2, length2, start, range, regs, stop, 0); @@ -349,12 +323,12 @@ weak_alias (__re_search_2, re_search_2) #endif static int -re_search_2_stub (bufp, string1, length1, string2, length2, start, range, regs, - stop, ret_len) - struct re_pattern_buffer *bufp; - const char *string1, *string2; - int length1, length2, start, range, stop, ret_len; - struct re_registers *regs; +internal_function +re_search_2_stub (struct re_pattern_buffer *bufp, + const char *string1, int length1, + const char *string2, int length2, + int start, int range, struct re_registers *regs, int stop, + int ret_len) { const char *str; int rval; @@ -395,17 +369,19 @@ re_search_2_stub (bufp, string1, length1, string2, length2, start, range, regs, otherwise the position of the match is returned. */ static int -re_search_stub (bufp, string, length, start, range, stop, regs, ret_len) - struct re_pattern_buffer *bufp; - const char *string; - int length, start, range, stop, ret_len; - struct re_registers *regs; +internal_function +re_search_stub (struct re_pattern_buffer *bufp, + const char *string, int length, + int start, int range, int stop, struct re_registers *regs, + int ret_len) { reg_errcode_t result; regmatch_t *pmatch; int nregs, rval; int eflags = 0; - re_dfa_t *dfa = (re_dfa_t *)bufp->buffer; +#ifdef _LIBC + re_dfa_t *dfa = (re_dfa_t *) bufp->re_buffer; +#endif /* Check for out-of-range. */ if (BE (start < 0 || start > length, 0)) @@ -417,23 +393,23 @@ re_search_stub (bufp, string, length, start, range, stop, regs, ret_len) __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. */ @@ -461,9 +437,9 @@ re_search_stub (bufp, string, length, start, range, stop, regs, ret_len) 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; } @@ -484,57 +460,57 @@ re_search_stub (bufp, string, length, start, range, stop, regs, ret_len) } static unsigned -re_copy_regs (regs, pmatch, nregs, regs_allocated) - struct re_registers *regs; - regmatch_t *pmatch; - int nregs, regs_allocated; +internal_function +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; } @@ -553,24 +529,21 @@ re_copy_regs (regs, pmatch, nregs, regs_allocated) freeing the old data. */ void -re_set_registers (bufp, regs, num_regs, starts, ends) - struct re_pattern_buffer *bufp; - struct re_registers *regs; - unsigned num_regs; - regoff_t *starts, *ends; +re_set_registers (struct re_pattern_buffer *bufp, struct re_registers *regs, + unsigned int num_regs, regoff_t *starts, regoff_t *ends) { 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 @@ -604,16 +577,15 @@ re_exec (s) (START + RANGE >= 0 && START + RANGE <= LENGTH) */ static reg_errcode_t -re_search_internal (preg, string, length, start, range, stop, nmatch, pmatch, - eflags) - const regex_t *preg; - const char *string; - int length, start, range, stop, eflags; - size_t nmatch; - regmatch_t pmatch[]; +internal_function +re_search_internal (const regex_t *preg, + const char *string, int length, + int start, int range, int stop, + size_t nmatch, regmatch_t pmatch[], + 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; @@ -623,9 +595,10 @@ re_search_internal (preg, string, length, start, range, stop, nmatch, pmatch, #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)); @@ -636,7 +609,7 @@ re_search_internal (preg, string, length, start, range, stop, nmatch, pmatch, 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; @@ -647,12 +620,12 @@ re_search_internal (preg, string, length, start, range, stop, nmatch, pmatch, #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; @@ -663,12 +636,13 @@ re_search_internal (preg, string, length, start, range, stop, nmatch, pmatch, 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)) @@ -701,7 +675,7 @@ re_search_internal (preg, string, length, start, range, stop, nmatch, pmatch, 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); @@ -823,13 +797,13 @@ re_search_internal (preg, string, length, start, range, stop, nmatch, pmatch, 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); @@ -865,7 +839,7 @@ re_search_internal (preg, string, length, start, range, stop, nmatch, pmatch, 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); @@ -923,8 +897,8 @@ re_search_internal (preg, string, length, start, range, stop, nmatch, pmatch, } static reg_errcode_t -prune_impossible_nodes (mctx) - re_match_context_t *mctx; +internal_function +prune_impossible_nodes (re_match_context_t *mctx) { re_dfa_t *const dfa = mctx->dfa; int halt_node, match_last; @@ -1009,10 +983,9 @@ prune_impossible_nodes (mctx) since initial states may have constraints like "\<", "^", etc.. */ static inline re_dfastate_t * -acquire_init_state_context (err, mctx, idx) - reg_errcode_t *err; - const re_match_context_t *mctx; - int idx; +__attribute ((always_inline)) internal_function +acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx, + int idx) { re_dfa_t *const dfa = mctx->dfa; if (dfa->init_state->has_constraint) @@ -1052,10 +1025,9 @@ acquire_init_state_context (err, mctx, idx) index of the buffer. */ static int -check_matching (mctx, fl_longest_match, p_match_first) - re_match_context_t *mctx; - int fl_longest_match; - int *p_match_first; +internal_function +check_matching (re_match_context_t *mctx, int fl_longest_match, + int *p_match_first) { re_dfa_t *const dfa = mctx->dfa; reg_errcode_t err; @@ -1184,10 +1156,9 @@ check_matching (mctx, fl_longest_match, p_match_first) /* Check NODE match the current context. */ -static int check_halt_node_context (dfa, node, context) - const re_dfa_t *dfa; - int node; - unsigned int context; +static int +internal_function +check_halt_node_context (const re_dfa_t *dfa, int node, unsigned int context) { re_token_type_t type = dfa->nodes[node].type; unsigned int constraint = dfa->nodes[node].constraint; @@ -1205,10 +1176,9 @@ static int check_halt_node_context (dfa, node, context) match the context, return the node. */ static int -check_halt_state_context (mctx, state, idx) - const re_match_context_t *mctx; - const re_dfastate_t *state; - int idx; +internal_function +check_halt_state_context (const re_match_context_t *mctx, + const re_dfastate_t *state, int idx) { int i; unsigned int context; @@ -1228,12 +1198,10 @@ check_halt_state_context (mctx, state, idx) of errors. */ static int -proceed_next_node (mctx, nregs, regs, pidx, node, eps_via_nodes, fs) - const re_match_context_t *mctx; - regmatch_t *regs; - int nregs, *pidx, node; - re_node_set *eps_via_nodes; - struct re_fail_stack_t *fs; +internal_function +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) { re_dfa_t *const dfa = mctx->dfa; int i, err; @@ -1330,19 +1298,16 @@ proceed_next_node (mctx, nregs, regs, pidx, node, eps_via_nodes, fs) } static reg_errcode_t -push_fail_stack (fs, str_idx, dest_node, nregs, regs, eps_via_nodes) - struct re_fail_stack_t *fs; - int str_idx, dest_node, nregs; - regmatch_t *regs; - re_node_set *eps_via_nodes; +internal_function +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) { reg_errcode_t err; 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; @@ -1359,11 +1324,9 @@ push_fail_stack (fs, str_idx, dest_node, nregs, regs, eps_via_nodes) } static int -pop_fail_stack (fs, pidx, nregs, regs, eps_via_nodes) - struct re_fail_stack_t *fs; - int *pidx, nregs; - regmatch_t *regs; - re_node_set *eps_via_nodes; +internal_function +pop_fail_stack (struct re_fail_stack_t *fs, int *pidx, + int nregs, regmatch_t *regs, re_node_set *eps_via_nodes) { int num = --fs->num; assert (num >= 0); @@ -1381,19 +1344,17 @@ pop_fail_stack (fs, pidx, nregs, regs, eps_via_nodes) pmatch[i].rm_so == pmatch[i].rm_eo == -1 for 0 < i < nmatch. */ static reg_errcode_t -set_regs (preg, mctx, nmatch, pmatch, fl_backtrack) - const regex_t *preg; - const re_match_context_t *mctx; - size_t nmatch; - regmatch_t *pmatch; - int fl_backtrack; +internal_function +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); @@ -1412,7 +1373,18 @@ set_regs (preg, mctx, nmatch, pmatch, fl_backtrack) 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 ;) @@ -1430,6 +1402,8 @@ set_regs (preg, mctx, nmatch, pmatch, fl_backtrack) 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, @@ -1438,6 +1412,8 @@ set_regs (preg, mctx, nmatch, pmatch, fl_backtrack) else { re_node_set_free (&eps_via_nodes); + if (prev_idx_match_malloced) + re_free (prev_idx_match); return REG_NOERROR; } } @@ -1451,6 +1427,8 @@ set_regs (preg, mctx, nmatch, pmatch, fl_backtrack) 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; } @@ -1460,17 +1438,21 @@ set_regs (preg, mctx, nmatch, pmatch, fl_backtrack) 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); } static reg_errcode_t -free_fail_stack_return (fs) - struct re_fail_stack_t *fs; +internal_function +free_fail_stack_return (struct re_fail_stack_t *fs) { if (fs) { @@ -1486,10 +1468,9 @@ free_fail_stack_return (fs) } static void -update_regs (dfa, pmatch, prev_idx_match, cur_node, cur_idx, nmatch) - re_dfa_t *dfa; - regmatch_t *pmatch, *prev_idx_match; - int cur_node, cur_idx, nmatch; +internal_function +update_regs (re_dfa_t *dfa, regmatch_t *pmatch, regmatch_t *prev_idx_match, + int cur_node, int cur_idx, int nmatch) { int type = dfa->nodes[cur_node].type; if (type == OP_OPEN_SUBEXP) @@ -1559,9 +1540,8 @@ update_regs (dfa, pmatch, prev_idx_match, cur_node, cur_idx, nmatch) ((state) != NULL && re_node_set_contains (&(state)->nodes, node)) static reg_errcode_t -sift_states_backward (mctx, sctx) - re_match_context_t *mctx; - re_sift_context_t *sctx; +internal_function +sift_states_backward (re_match_context_t *mctx, re_sift_context_t *sctx) { reg_errcode_t err; int null_cnt = 0; @@ -1618,11 +1598,9 @@ sift_states_backward (mctx, sctx) } static reg_errcode_t -build_sifted_states (mctx, sctx, str_idx, cur_dest) - re_match_context_t *mctx; - re_sift_context_t *sctx; - int str_idx; - re_node_set *cur_dest; +internal_function +build_sifted_states (re_match_context_t *mctx, re_sift_context_t *sctx, + int str_idx, re_node_set *cur_dest) { re_dfa_t *const dfa = mctx->dfa; re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes; @@ -1682,9 +1660,8 @@ build_sifted_states (mctx, sctx, str_idx, cur_dest) /* Helper functions. */ static reg_errcode_t -clean_state_log_if_needed (mctx, next_state_log_idx) - re_match_context_t *mctx; - int next_state_log_idx; +internal_function +clean_state_log_if_needed (re_match_context_t *mctx, int next_state_log_idx) { int top = mctx->state_log_top; @@ -1708,11 +1685,9 @@ clean_state_log_if_needed (mctx, next_state_log_idx) } static reg_errcode_t -merge_state_array (dfa, dst, src, num) - re_dfa_t *dfa; - re_dfastate_t **dst; - re_dfastate_t **src; - int num; +internal_function +merge_state_array (re_dfa_t *dfa, re_dfastate_t **dst, re_dfastate_t **src, + int num) { int st_idx; reg_errcode_t err; @@ -1737,11 +1712,9 @@ merge_state_array (dfa, dst, src, num) } static reg_errcode_t -update_cur_sifted_state (mctx, sctx, str_idx, dest_nodes) - re_match_context_t *mctx; - re_sift_context_t *sctx; - int str_idx; - re_node_set *dest_nodes; +internal_function +update_cur_sifted_state (re_match_context_t *mctx, re_sift_context_t *sctx, + int str_idx, re_node_set *dest_nodes) { re_dfa_t *const dfa = mctx->dfa; reg_errcode_t err; @@ -1786,10 +1759,9 @@ update_cur_sifted_state (mctx, sctx, str_idx, dest_nodes) } static reg_errcode_t -add_epsilon_src_nodes (dfa, dest_nodes, candidates) - re_dfa_t *dfa; - re_node_set *dest_nodes; - const re_node_set *candidates; +internal_function +add_epsilon_src_nodes (re_dfa_t *dfa, re_node_set *dest_nodes, + const re_node_set *candidates) { reg_errcode_t err = REG_NOERROR; int i; @@ -1812,11 +1784,9 @@ add_epsilon_src_nodes (dfa, dest_nodes, candidates) } static reg_errcode_t -sub_epsilon_src_nodes (dfa, node, dest_nodes, candidates) - re_dfa_t *dfa; - int node; - re_node_set *dest_nodes; - const re_node_set *candidates; +internal_function +sub_epsilon_src_nodes (re_dfa_t *dfa, int node, re_node_set *dest_nodes, + const re_node_set *candidates) { int ecl_idx; reg_errcode_t err; @@ -1863,10 +1833,9 @@ sub_epsilon_src_nodes (dfa, node, dest_nodes, candidates) } static int -check_dst_limits (mctx, limits, dst_node, dst_idx, src_node, src_idx) - re_match_context_t *mctx; - re_node_set *limits; - int dst_node, dst_idx, src_node, src_idx; +internal_function +check_dst_limits (re_match_context_t *mctx, re_node_set *limits, + int dst_node, int dst_idx, int src_node, int src_idx) { re_dfa_t *const dfa = mctx->dfa; int lim_idx, src_pos, dst_pos; @@ -1900,9 +1869,9 @@ check_dst_limits (mctx, limits, dst_node, dst_idx, src_node, src_idx) } static int -check_dst_limits_calc_pos_1 (mctx, boundaries, subexp_idx, from_node, bkref_idx) - re_match_context_t *mctx; - int boundaries, subexp_idx, from_node, bkref_idx; +internal_function +check_dst_limits_calc_pos_1 (re_match_context_t *mctx, int boundaries, + int subexp_idx, int from_node, int bkref_idx) { re_dfa_t *const dfa = mctx->dfa; re_node_set *eclosures = dfa->eclosures + from_node; @@ -1978,9 +1947,9 @@ check_dst_limits_calc_pos_1 (mctx, boundaries, subexp_idx, from_node, bkref_idx) } static int -check_dst_limits_calc_pos (mctx, limit, subexp_idx, from_node, str_idx, bkref_idx) - re_match_context_t *mctx; - int limit, subexp_idx, from_node, str_idx, bkref_idx; +internal_function +check_dst_limits_calc_pos (re_match_context_t *mctx, int limit, int subexp_idx, + int from_node, int str_idx, int bkref_idx) { struct re_backref_cache_entry *lim = mctx->bkref_ents + limit; int boundaries; @@ -2007,13 +1976,10 @@ check_dst_limits_calc_pos (mctx, limit, subexp_idx, from_node, str_idx, bkref_id which are against limitations from DEST_NODES. */ static reg_errcode_t -check_subexp_limits (dfa, dest_nodes, candidates, limits, bkref_ents, str_idx) - re_dfa_t *dfa; - re_node_set *dest_nodes; - const re_node_set *candidates; - re_node_set *limits; - struct re_backref_cache_entry *bkref_ents; - int str_idx; +internal_function +check_subexp_limits (re_dfa_t *dfa, re_node_set *dest_nodes, + const re_node_set *candidates, re_node_set *limits, + struct re_backref_cache_entry *bkref_ents, int str_idx) { reg_errcode_t err; int node_idx, lim_idx; @@ -2098,11 +2064,9 @@ check_subexp_limits (dfa, dest_nodes, candidates, limits, bkref_ents, str_idx) } static reg_errcode_t -sift_states_bkref (mctx, sctx, str_idx, candidates) - re_match_context_t *mctx; - re_sift_context_t *sctx; - int str_idx; - const re_node_set *candidates; +internal_function +sift_states_bkref (re_match_context_t *mctx, re_sift_context_t *sctx, + int str_idx, const re_node_set *candidates) { re_dfa_t *const dfa = mctx->dfa; reg_errcode_t err; @@ -2132,7 +2096,7 @@ sift_states_bkref (mctx, sctx, str_idx, candidates) 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) @@ -2158,8 +2122,8 @@ sift_states_bkref (mctx, sctx, str_idx, candidates) } 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; @@ -2197,10 +2161,9 @@ sift_states_bkref (mctx, sctx, str_idx, candidates) #ifdef RE_ENABLE_I18N static int -sift_states_iter_mb (mctx, sctx, node_idx, str_idx, max_str_idx) - const re_match_context_t *mctx; - re_sift_context_t *sctx; - int node_idx, str_idx, max_str_idx; +internal_function +sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx, + int node_idx, int str_idx, int max_str_idx) { re_dfa_t *const dfa = mctx->dfa; int naccepted; @@ -2228,10 +2191,9 @@ sift_states_iter_mb (mctx, sctx, node_idx, str_idx, max_str_idx) update the destination of STATE_LOG. */ static re_dfastate_t * -transit_state (err, mctx, state) - reg_errcode_t *err; - re_match_context_t *mctx; - re_dfastate_t *state; +internal_function +transit_state (reg_errcode_t *err, re_match_context_t *mctx, + re_dfastate_t *state) { re_dfastate_t **trtable; unsigned char ch; @@ -2287,10 +2249,9 @@ transit_state (err, mctx, state) /* Update the state_log if we need */ re_dfastate_t * -merge_state_with_log (err, mctx, next_state) - reg_errcode_t *err; - re_match_context_t *mctx; - re_dfastate_t *next_state; +internal_function +merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx, + re_dfastate_t *next_state) { re_dfa_t *const dfa = mctx->dfa; int cur_idx = re_string_cur_idx (&mctx->input); @@ -2366,10 +2327,9 @@ merge_state_with_log (err, mctx, next_state) /* Skip bytes in the input that correspond to part of a multi-byte match, then look in the log for a state from which to restart matching. */ -re_dfastate_t * -find_recover_state (err, mctx) - reg_errcode_t *err; - re_match_context_t *mctx; +static re_dfastate_t * +internal_function +find_recover_state (reg_errcode_t *err, re_match_context_t *mctx) { re_dfastate_t *cur_state = NULL; do @@ -2387,7 +2347,7 @@ find_recover_state (err, mctx) 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; } @@ -2399,10 +2359,9 @@ find_recover_state (err, mctx) correspoding back references. */ static reg_errcode_t -check_subexp_matching_top (mctx, cur_nodes, str_idx) - re_match_context_t *mctx; - re_node_set *cur_nodes; - int str_idx; +internal_function +check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes, + int str_idx) { re_dfa_t *const dfa = mctx->dfa; int node_idx; @@ -2474,9 +2433,8 @@ transit_state_sb (err, mctx, state) #ifdef RE_ENABLE_I18N static reg_errcode_t -transit_state_mb (mctx, pstate) - re_match_context_t *mctx; - re_dfastate_t *pstate; +internal_function +transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate) { re_dfa_t *const dfa = mctx->dfa; reg_errcode_t err; @@ -2544,9 +2502,8 @@ transit_state_mb (mctx, pstate) #endif /* RE_ENABLE_I18N */ static reg_errcode_t -transit_state_bkref (mctx, nodes) - re_match_context_t *mctx; - const re_node_set *nodes; +internal_function +transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes) { re_dfa_t *const dfa = mctx->dfa; reg_errcode_t err; @@ -2659,9 +2616,8 @@ transit_state_bkref (mctx, nodes) delay these checking for prune_impossible_nodes(). */ static reg_errcode_t -get_subexp (mctx, bkref_node, bkref_str_idx) - re_match_context_t *mctx; - int bkref_node, bkref_str_idx; +internal_function +get_subexp (re_match_context_t *mctx, int bkref_node, int bkref_str_idx) { re_dfa_t *const dfa = mctx->dfa; int subexp_num, sub_top_idx; @@ -2773,8 +2729,8 @@ get_subexp (mctx, bkref_node, bkref_str_idx) 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; } @@ -2805,11 +2761,9 @@ get_subexp (mctx, bkref_node, bkref_str_idx) and SUB_LAST. */ static reg_errcode_t -get_subexp_sub (mctx, sub_top, sub_last, bkref_node, bkref_str) - re_match_context_t *mctx; - const re_sub_match_top_t *sub_top; - re_sub_match_last_t *sub_last; - int bkref_node, bkref_str; +internal_function +get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top, + re_sub_match_last_t *sub_last, int bkref_node, int bkref_str) { reg_errcode_t err; int to_idx; @@ -2835,10 +2789,9 @@ get_subexp_sub (mctx, sub_top, sub_last, bkref_node, bkref_str) E.g. RE: (a){2} */ static int -find_subexp_node (dfa, nodes, subexp_idx, type) - const re_dfa_t *dfa; - const re_node_set *nodes; - int subexp_idx, type; +internal_function +find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes, + int subexp_idx, int type) { int cls_idx; for (cls_idx = 0; cls_idx < nodes->nelem; ++cls_idx) @@ -2858,11 +2811,10 @@ find_subexp_node (dfa, nodes, subexp_idx, type) Return REG_NOERROR if it can arrive, or REG_NOMATCH otherwise. */ static reg_errcode_t -check_arrival (mctx, path, top_node, top_str, last_node, last_str, - type) - re_match_context_t *mctx; - state_array_t *path; - int top_node, top_str, last_node, last_str, type; +internal_function +check_arrival (re_match_context_t *mctx, state_array_t *path, + int top_node, int top_str, int last_node, int last_str, + int type) { re_dfa_t *const dfa = mctx->dfa; reg_errcode_t err; @@ -3020,10 +2972,10 @@ check_arrival (mctx, path, top_node, top_str, last_node, last_str, Can't we unify them? */ static reg_errcode_t -check_arrival_add_next_nodes (mctx, str_idx, cur_nodes, next_nodes) - re_match_context_t *mctx; - int str_idx; - re_node_set *cur_nodes, *next_nodes; +internal_function +check_arrival_add_next_nodes (re_match_context_t *mctx, int str_idx, + re_node_set *cur_nodes, + re_node_set *next_nodes) { re_dfa_t *const dfa = mctx->dfa; int result; @@ -3100,10 +3052,9 @@ check_arrival_add_next_nodes (mctx, str_idx, cur_nodes, next_nodes) */ static reg_errcode_t -check_arrival_expand_ecl (dfa, cur_nodes, ex_subexp, type) - re_dfa_t *dfa; - re_node_set *cur_nodes; - int ex_subexp, type; +internal_function +check_arrival_expand_ecl (re_dfa_t *dfa, re_node_set *cur_nodes, + int ex_subexp, int type) { reg_errcode_t err; int idx, outside_node; @@ -3154,10 +3105,9 @@ check_arrival_expand_ecl (dfa, cur_nodes, ex_subexp, type) problematic append it to DST_NODES. */ static reg_errcode_t -check_arrival_expand_ecl_sub (dfa, dst_nodes, target, ex_subexp, type) - re_dfa_t *dfa; - int target, ex_subexp, type; - re_node_set *dst_nodes; +internal_function +check_arrival_expand_ecl_sub (re_dfa_t *dfa, re_node_set *dst_nodes, + int target, int ex_subexp, int type) { int cur_node; for (cur_node = target; !re_node_set_contains (dst_nodes, cur_node);) @@ -3182,11 +3132,12 @@ check_arrival_expand_ecl_sub (dfa, dst_nodes, target, ex_subexp, type) 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]; } @@ -3199,11 +3150,9 @@ check_arrival_expand_ecl_sub (dfa, dst_nodes, target, ex_subexp, type) in MCTX->BKREF_ENTS. */ static reg_errcode_t -expand_bkref_cache (mctx, cur_nodes, cur_str, subexp_num, - type) - re_match_context_t *mctx; - int cur_str, subexp_num, type; - re_node_set *cur_nodes; +internal_function +expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, + int cur_str, int subexp_num, int type) { re_dfa_t *const dfa = mctx->dfa; reg_errcode_t err; @@ -3290,9 +3239,8 @@ expand_bkref_cache (mctx, cur_nodes, cur_str, subexp_num, Return 1 if succeeded, otherwise return NULL. */ static int -build_trtable (dfa, state) - re_dfa_t *dfa; - re_dfastate_t *state; +internal_function +build_trtable (re_dfa_t *dfa, re_dfastate_t *state) { reg_errcode_t err; int i, j, ch, need_word_trtable = 0; @@ -3309,12 +3257,10 @@ build_trtable (dfa, state) 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); @@ -3337,8 +3283,7 @@ build_trtable (dfa, state) /* 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; @@ -3348,13 +3293,11 @@ build_trtable (dfa, state) 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 *)); @@ -3426,8 +3369,7 @@ out_free: 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; @@ -3457,8 +3399,7 @@ 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; @@ -3516,11 +3457,9 @@ out_free: to DEST_CH[i]. This function return the number of destinations. */ static int -group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch) - re_dfa_t *dfa; - const re_dfastate_t *state; - re_node_set *dests_node; - bitset *dests_ch; +internal_function +group_nodes_into_DFAstates (re_dfa_t *dfa, const re_dfastate_t *state, + re_node_set *dests_node, bitset *dests_ch) { reg_errcode_t err; int result; @@ -3553,18 +3492,18 @@ group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch) 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 @@ -3708,10 +3647,9 @@ group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch) can only accept one byte. */ static int -check_node_accept_bytes (dfa, node_idx, input, str_idx) - re_dfa_t *dfa; - int node_idx, str_idx; - const re_string_t *input; +internal_function +check_node_accept_bytes (re_dfa_t *dfa, int node_idx, + const re_string_t *input, int str_idx) { const re_token_t *node = dfa->nodes + node_idx; int char_len, elem_len; @@ -3776,9 +3714,9 @@ check_node_accept_bytes (dfa, node_idx, input, str_idx) /* 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; @@ -4009,10 +3947,9 @@ find_collation_sequence_value (mbs, mbs_len) byte of the INPUT. */ static int -check_node_accept (mctx, node, idx) - const re_match_context_t *mctx; - const re_token_t *node; - int idx; +internal_function +check_node_accept (const re_match_context_t *mctx, const re_token_t *node, + int idx) { unsigned char ch; ch = re_string_byte_at (&mctx->input, idx); @@ -4035,8 +3972,8 @@ check_node_accept (mctx, node, idx) /* 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; @@ -4060,8 +3997,8 @@ check_node_accept (mctx, node, idx) /* Extend the buffers, if the buffers have run out. */ static reg_errcode_t -extend_buffers (mctx) - re_match_context_t *mctx; +internal_function +extend_buffers (re_match_context_t *mctx) { reg_errcode_t ret; re_string_t *pstr = &mctx->input; @@ -4119,9 +4056,8 @@ extend_buffers (mctx) /* Initialize MCTX. */ static reg_errcode_t -match_ctx_init (mctx, eflags, n) - re_match_context_t *mctx; - int eflags, n; +internal_function +match_ctx_init (re_match_context_t *mctx, int eflags, int n) { mctx->eflags = eflags; mctx->match_last = -1; @@ -4148,8 +4084,8 @@ match_ctx_init (mctx, eflags, n) of the input, or changes the input string. */ static void -match_ctx_clean (mctx) - re_match_context_t *mctx; +internal_function +match_ctx_clean (re_match_context_t *mctx) { int st_idx; for (st_idx = 0; st_idx < mctx->nsub_tops; ++st_idx) @@ -4178,8 +4114,8 @@ match_ctx_clean (mctx) /* Free all the memory associated with MCTX. */ static void -match_ctx_free (mctx) - re_match_context_t *mctx; +internal_function +match_ctx_free (re_match_context_t *mctx) { /* First, free all the memory associated with MCTX->SUB_TOPS. */ match_ctx_clean (mctx); @@ -4193,9 +4129,9 @@ match_ctx_free (mctx) */ static reg_errcode_t -match_ctx_add_entry (mctx, node, str_idx, from, to) - re_match_context_t *mctx; - int node, str_idx, from, to; +internal_function +match_ctx_add_entry (re_match_context_t *mctx, int node, int str_idx, + int from, int to) { if (mctx->nbkref_ents >= mctx->abkref_ents) { @@ -4242,9 +4178,8 @@ match_ctx_add_entry (mctx, node, str_idx, from, to) found. Note that MCTX->BKREF_ENTS is already sorted by MCTX->STR_IDX. */ static int -search_cur_bkref_entry (mctx, str_idx) - re_match_context_t *mctx; - int str_idx; +internal_function +search_cur_bkref_entry (re_match_context_t *mctx, int str_idx) { int left, right, mid, last; last = right = mctx->nbkref_ents; @@ -4266,9 +4201,8 @@ search_cur_bkref_entry (mctx, str_idx) at STR_IDX. */ static reg_errcode_t -match_ctx_add_subtop (mctx, node, str_idx) - re_match_context_t *mctx; - int node, str_idx; +internal_function +match_ctx_add_subtop (re_match_context_t *mctx, int node, int str_idx) { #ifdef DEBUG assert (mctx->sub_tops != NULL); @@ -4285,7 +4219,7 @@ match_ctx_add_subtop (mctx, node, str_idx) 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; @@ -4297,9 +4231,8 @@ match_ctx_add_subtop (mctx, node, str_idx) at STR_IDX, whose corresponding OP_OPEN_SUBEXP is SUB_TOP. */ static re_sub_match_last_t * -match_ctx_add_sublast (subtop, node, str_idx) - re_sub_match_top_t *subtop; - int node, str_idx; +internal_function +match_ctx_add_sublast (re_sub_match_top_t *subtop, int node, int str_idx) { re_sub_match_last_t *new_entry; if (BE (subtop->nlasts == subtop->alasts, 0)) @@ -4313,7 +4246,7 @@ match_ctx_add_sublast (subtop, node, str_idx) 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; @@ -4325,10 +4258,11 @@ match_ctx_add_sublast (subtop, node, str_idx) } static void -sift_ctx_init (sctx, sifted_sts, limited_sts, last_node, last_str_idx) - re_sift_context_t *sctx; - re_dfastate_t **sifted_sts, **limited_sts; - int last_node, last_str_idx; +internal_function +sift_ctx_init (re_sift_context_t *sctx, + re_dfastate_t **sifted_sts, + re_dfastate_t **limited_sts, + int last_node, int last_str_idx) { sctx->sifted_states = sifted_sts; sctx->limited_states = limited_sts;