Lines Matching refs:mctx

22 static void match_ctx_clean (re_match_context_t *mctx);
26 static Idx search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx);
27 static reg_errcode_t match_ctx_add_subtop (re_match_context_t *mctx, Idx node,
52 static reg_errcode_t prune_impossible_nodes (re_match_context_t *mctx);
53 static Idx check_matching (re_match_context_t *mctx, bool fl_longest_match,
55 static Idx check_halt_state_context (const re_match_context_t *mctx,
65 const re_match_context_t *mctx,
71 static int sift_states_iter_mb (const re_match_context_t *mctx,
75 static reg_errcode_t sift_states_backward (const re_match_context_t *mctx,
77 static reg_errcode_t build_sifted_states (const re_match_context_t *mctx,
80 static reg_errcode_t update_cur_sifted_state (const re_match_context_t *mctx,
87 static bool check_dst_limits (const re_match_context_t *mctx,
91 static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx,
94 static int check_dst_limits_calc_pos (const re_match_context_t *mctx,
104 static reg_errcode_t sift_states_bkref (const re_match_context_t *mctx,
111 re_match_context_t *mctx);
113 re_match_context_t *mctx,
116 re_match_context_t *mctx,
118 static reg_errcode_t check_subexp_matching_top (re_match_context_t *mctx,
123 re_match_context_t *mctx,
127 static reg_errcode_t transit_state_mb (re_match_context_t *mctx,
130 static reg_errcode_t transit_state_bkref (re_match_context_t *mctx,
132 static reg_errcode_t get_subexp (re_match_context_t *mctx,
134 static reg_errcode_t get_subexp_sub (re_match_context_t *mctx,
140 static reg_errcode_t check_arrival (re_match_context_t *mctx,
144 static reg_errcode_t check_arrival_add_next_nodes (re_match_context_t *mctx,
155 static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx,
171 static bool check_node_accept (const re_match_context_t *mctx,
173 static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len);
601 re_match_context_t mctx = { .dfa = dfa }; in re_search_internal() local
636 err = re_string_allocate (&mctx.input, string, length, dfa->nodes_len + 1, in re_search_internal()
641 mctx.input.stop = stop; in re_search_internal()
642 mctx.input.raw_stop = stop; in re_search_internal()
643 mctx.input.newline_anchor = preg->newline_anchor; in re_search_internal()
645 err = match_ctx_init (&mctx, eflags, dfa->nbackref * 2); in re_search_internal()
657 <= mctx.input.bufs_len))) in re_search_internal()
663 mctx.state_log = re_malloc (re_dfastate_t *, mctx.input.bufs_len + 1); in re_search_internal()
664 if (__glibc_unlikely (mctx.state_log == NULL)) in re_search_internal()
672 mctx.input.tip_context = (eflags & REG_NOTBOL) ? CONTEXT_BEGBUF in re_search_internal()
750 __re_size_t offset = match_first - mctx.input.raw_mbs_idx; in re_search_internal()
752 >= (__re_size_t) mctx.input.valid_raw_len)) in re_search_internal()
754 err = re_string_reconstruct (&mctx.input, match_first, in re_search_internal()
759 offset = match_first - mctx.input.raw_mbs_idx; in re_search_internal()
762 ch = (offset < mctx.input.valid_len in re_search_internal()
763 ? re_string_byte_at (&mctx.input, offset) : 0); in re_search_internal()
778 err = re_string_reconstruct (&mctx.input, match_first, eflags); in re_search_internal()
785 if (!sb && !re_string_first_byte (&mctx.input, 0)) in re_search_internal()
791 mctx.state_log_top = mctx.nbkref_ents = mctx.max_mb_elem_len = 0; in re_search_internal()
792 match_last = check_matching (&mctx, fl_longest_match, in re_search_internal()
803 mctx.match_last = match_last; in re_search_internal()
806 re_dfastate_t *pstate = mctx.state_log[match_last]; in re_search_internal()
807 mctx.last_node = check_halt_state_context (&mctx, pstate, in re_search_internal()
813 err = prune_impossible_nodes (&mctx); in re_search_internal()
825 match_ctx_clean (&mctx); in re_search_internal()
842 pmatch[0].rm_eo = mctx.match_last; in re_search_internal()
849 err = set_regs (preg, &mctx, nmatch, pmatch, in re_search_internal()
862 if (__glibc_unlikely (mctx.input.offsets_needed != 0)) in re_search_internal()
865 (pmatch[reg_idx].rm_so == mctx.input.valid_len in re_search_internal()
866 ? mctx.input.valid_raw_len in re_search_internal()
867 : mctx.input.offsets[pmatch[reg_idx].rm_so]); in re_search_internal()
869 (pmatch[reg_idx].rm_eo == mctx.input.valid_len in re_search_internal()
870 ? mctx.input.valid_raw_len in re_search_internal()
871 : mctx.input.offsets[pmatch[reg_idx].rm_eo]); in re_search_internal()
874 DEBUG_ASSERT (mctx.input.offsets_needed == 0); in re_search_internal()
897 re_free (mctx.state_log); in re_search_internal()
899 match_ctx_free (&mctx); in re_search_internal()
900 re_string_destruct (&mctx.input); in re_search_internal()
906 prune_impossible_nodes (re_match_context_t *mctx) in prune_impossible_nodes() argument
908 const re_dfa_t *const dfa = mctx->dfa; in prune_impossible_nodes()
914 DEBUG_ASSERT (mctx->state_log != NULL); in prune_impossible_nodes()
915 match_last = mctx->match_last; in prune_impossible_nodes()
916 halt_node = mctx->last_node; in prune_impossible_nodes()
943 ret = sift_states_backward (mctx, &sctx); in prune_impossible_nodes()
957 } while (mctx->state_log[match_last] == NULL in prune_impossible_nodes()
958 || !mctx->state_log[match_last]->halt); in prune_impossible_nodes()
959 halt_node = check_halt_state_context (mctx, in prune_impossible_nodes()
960 mctx->state_log[match_last], in prune_impossible_nodes()
973 ret = sift_states_backward (mctx, &sctx); in prune_impossible_nodes()
983 re_free (mctx->state_log); in prune_impossible_nodes()
984 mctx->state_log = sifted_states; in prune_impossible_nodes()
986 mctx->last_node = halt_node; in prune_impossible_nodes()
987 mctx->match_last = match_last; in prune_impossible_nodes()
1001 acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx, in acquire_init_state_context() argument
1004 const re_dfa_t *const dfa = mctx->dfa; in acquire_init_state_context()
1008 context = re_string_context_at (&mctx->input, idx - 1, mctx->eflags); in acquire_init_state_context()
1043 check_matching (re_match_context_t *mctx, bool fl_longest_match, in check_matching() argument
1046 const re_dfa_t *const dfa = mctx->dfa; in check_matching()
1050 Idx cur_str_idx = re_string_cur_idx (&mctx->input); in check_matching()
1056 cur_state = acquire_init_state_context (&err, mctx, cur_str_idx); in check_matching()
1064 if (mctx->state_log != NULL) in check_matching()
1066 mctx->state_log[cur_str_idx] = cur_state; in check_matching()
1073 err = check_subexp_matching_top (mctx, &cur_state->nodes, 0); in check_matching()
1079 err = transit_state_bkref (mctx, &cur_state->nodes); in check_matching()
1090 || check_halt_state_context (mctx, cur_state, cur_str_idx)) in check_matching()
1102 while (!re_string_eoi (&mctx->input)) in check_matching()
1105 Idx next_char_idx = re_string_cur_idx (&mctx->input) + 1; in check_matching()
1107 if ((__glibc_unlikely (next_char_idx >= mctx->input.bufs_len) in check_matching()
1108 && mctx->input.bufs_len < mctx->input.len) in check_matching()
1109 || (__glibc_unlikely (next_char_idx >= mctx->input.valid_len) in check_matching()
1110 && mctx->input.valid_len < mctx->input.len)) in check_matching()
1112 err = extend_buffers (mctx, next_char_idx + 1); in check_matching()
1120 cur_state = transit_state (&err, mctx, cur_state); in check_matching()
1121 if (mctx->state_log != NULL) in check_matching()
1122 cur_state = merge_state_with_log (&err, mctx, cur_state); in check_matching()
1132 if (mctx->state_log == NULL in check_matching()
1134 || (cur_state = find_recover_state (&err, mctx)) == NULL) in check_matching()
1151 || check_halt_state_context (mctx, cur_state, in check_matching()
1152 re_string_cur_idx (&mctx->input))) in check_matching()
1155 match_last = re_string_cur_idx (&mctx->input); in check_matching()
1193 check_halt_state_context (const re_match_context_t *mctx, in check_halt_state_context() argument
1199 context = re_string_context_at (&mctx->input, idx, mctx->eflags); in check_halt_state_context()
1201 if (check_halt_node_context (mctx->dfa, state->nodes.elems[i], context)) in check_halt_state_context()
1212 proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs, in proceed_next_node() argument
1217 const re_dfa_t *const dfa = mctx->dfa; in proceed_next_node()
1220 re_node_set *cur_nodes = &mctx->state_log[*pidx]->nodes; in proceed_next_node()
1266 naccepted = check_node_accept_bytes (dfa, node, &mctx->input, *pidx); in proceed_next_node()
1282 char *buf = (char *) re_string_get_buffer (&mctx->input); in proceed_next_node()
1283 if (mctx->input.valid_len - *pidx < naccepted in proceed_next_node()
1298 if (re_node_set_contains (&mctx->state_log[*pidx]->nodes, in proceed_next_node()
1305 || check_node_accept (mctx, dfa->nodes + node, *pidx)) in proceed_next_node()
1309 if (fs && (*pidx > mctx->match_last || mctx->state_log[*pidx] == NULL in proceed_next_node()
1310 || !re_node_set_contains (&mctx->state_log[*pidx]->nodes, in proceed_next_node()
1380 set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, in set_regs() argument
1392 DEBUG_ASSERT (mctx->state_log != NULL); in set_regs()
1419 if ((idx == pmatch[0].rm_eo && cur_node == mctx->last_node) in set_regs()
1443 cur_node = proceed_next_node (mctx, nmatch, pmatch, prev_idx_match, in set_regs()
1560 sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx) in sift_states_backward() argument
1567 DEBUG_ASSERT (mctx->state_log != NULL && mctx->state_log[str_idx] != NULL); in sift_states_backward()
1574 err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest); in sift_states_backward()
1583 if (null_cnt > mctx->max_mb_elem_len) in sift_states_backward()
1593 if (mctx->state_log[str_idx]) in sift_states_backward()
1595 err = build_sifted_states (mctx, sctx, str_idx, &cur_dest); in sift_states_backward()
1604 err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest); in sift_states_backward()
1616 build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx, in build_sifted_states() argument
1619 const re_dfa_t *const dfa = mctx->dfa; in build_sifted_states()
1620 const re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes; in build_sifted_states()
1640 naccepted = sift_states_iter_mb (mctx, sctx, prev_node, in build_sifted_states()
1647 && check_node_accept (mctx, dfa->nodes + prev_node, str_idx) in build_sifted_states()
1658 if (check_dst_limits (mctx, &sctx->limits, in build_sifted_states()
1674 clean_state_log_if_needed (re_match_context_t *mctx, Idx next_state_log_idx) in clean_state_log_if_needed() argument
1676 Idx top = mctx->state_log_top; in clean_state_log_if_needed()
1678 if ((next_state_log_idx >= mctx->input.bufs_len in clean_state_log_if_needed()
1679 && mctx->input.bufs_len < mctx->input.len) in clean_state_log_if_needed()
1680 || (next_state_log_idx >= mctx->input.valid_len in clean_state_log_if_needed()
1681 && mctx->input.valid_len < mctx->input.len)) in clean_state_log_if_needed()
1684 err = extend_buffers (mctx, next_state_log_idx + 1); in clean_state_log_if_needed()
1691 memset (mctx->state_log + top + 1, '\0', in clean_state_log_if_needed()
1693 mctx->state_log_top = next_state_log_idx; in clean_state_log_if_needed()
1725 update_cur_sifted_state (const re_match_context_t *mctx, in update_cur_sifted_state() argument
1729 const re_dfa_t *const dfa = mctx->dfa; in update_cur_sifted_state()
1732 candidates = ((mctx->state_log[str_idx] == NULL) ? NULL in update_cur_sifted_state()
1733 : &mctx->state_log[str_idx]->nodes); in update_cur_sifted_state()
1751 mctx->bkref_ents, str_idx); in update_cur_sifted_state()
1762 if (candidates && mctx->state_log[str_idx]->has_backref) in update_cur_sifted_state()
1764 err = sift_states_bkref (mctx, sctx, str_idx, candidates); in update_cur_sifted_state()
1849 check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits, in check_dst_limits() argument
1852 const re_dfa_t *const dfa = mctx->dfa; in check_dst_limits()
1855 Idx dst_bkref_idx = search_cur_bkref_entry (mctx, dst_idx); in check_dst_limits()
1856 Idx src_bkref_idx = search_cur_bkref_entry (mctx, src_idx); in check_dst_limits()
1861 ent = mctx->bkref_ents + limits->elems[lim_idx]; in check_dst_limits()
1864 dst_pos = check_dst_limits_calc_pos (mctx, limits->elems[lim_idx], in check_dst_limits()
1867 src_pos = check_dst_limits_calc_pos (mctx, limits->elems[lim_idx], in check_dst_limits()
1884 check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries, in check_dst_limits_calc_pos_1() argument
1887 const re_dfa_t *const dfa = mctx->dfa; in check_dst_limits_calc_pos_1()
1901 struct re_backref_cache_entry *ent = mctx->bkref_ents + bkref_idx; in check_dst_limits_calc_pos_1()
1931 check_dst_limits_calc_pos_1 (mctx, boundaries, subexp_idx, in check_dst_limits_calc_pos_1()
1965 check_dst_limits_calc_pos (const re_match_context_t *mctx, Idx limit, in check_dst_limits_calc_pos() argument
1969 struct re_backref_cache_entry *lim = mctx->bkref_ents + limit; in check_dst_limits_calc_pos()
1986 return check_dst_limits_calc_pos_1 (mctx, boundaries, subexp_idx, in check_dst_limits_calc_pos()
2082 sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx, in sift_states_bkref() argument
2085 const re_dfa_t *const dfa = mctx->dfa; in sift_states_bkref()
2089 Idx first_idx = search_cur_bkref_entry (mctx, str_idx); in sift_states_bkref()
2109 entry = mctx->bkref_ents + first_idx; in sift_states_bkref()
2129 || check_dst_limits (mctx, &sctx->limits, node, in sift_states_bkref()
2149 err = sift_states_backward (mctx, &local_sctx); in sift_states_bkref()
2164 entry = mctx->bkref_ents + enabled_idx; in sift_states_bkref()
2181 sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx, in sift_states_iter_mb() argument
2184 const re_dfa_t *const dfa = mctx->dfa; in sift_states_iter_mb()
2187 naccepted = check_node_accept_bytes (dfa, node_idx, &mctx->input, str_idx); in sift_states_iter_mb()
2212 transit_state (reg_errcode_t *err, re_match_context_t *mctx, in transit_state() argument
2222 *err = transit_state_mb (mctx, state); in transit_state()
2232 return transit_state_sb (err, mctx, state); in transit_state()
2236 ch = re_string_fetch_byte (&mctx->input); in transit_state()
2248 = re_string_context_at (&mctx->input, in transit_state()
2249 re_string_cur_idx (&mctx->input) - 1, in transit_state()
2250 mctx->eflags); in transit_state()
2257 if (!build_trtable (mctx->dfa, state)) in transit_state()
2269 merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx, in merge_state_with_log() argument
2272 const re_dfa_t *const dfa = mctx->dfa; in merge_state_with_log()
2273 Idx cur_idx = re_string_cur_idx (&mctx->input); in merge_state_with_log()
2275 if (cur_idx > mctx->state_log_top) in merge_state_with_log()
2277 mctx->state_log[cur_idx] = next_state; in merge_state_with_log()
2278 mctx->state_log_top = cur_idx; in merge_state_with_log()
2280 else if (mctx->state_log[cur_idx] == 0) in merge_state_with_log()
2282 mctx->state_log[cur_idx] = next_state; in merge_state_with_log()
2293 pstate = mctx->state_log[cur_idx]; in merge_state_with_log()
2308 context = re_string_context_at (&mctx->input, in merge_state_with_log()
2309 re_string_cur_idx (&mctx->input) - 1, in merge_state_with_log()
2310 mctx->eflags); in merge_state_with_log()
2311 next_state = mctx->state_log[cur_idx] in merge_state_with_log()
2325 *err = check_subexp_matching_top (mctx, &next_state->nodes, in merge_state_with_log()
2333 *err = transit_state_bkref (mctx, &next_state->nodes); in merge_state_with_log()
2336 next_state = mctx->state_log[cur_idx]; in merge_state_with_log()
2347 find_recover_state (reg_errcode_t *err, re_match_context_t *mctx) in find_recover_state() argument
2352 Idx max = mctx->state_log_top; in find_recover_state()
2353 Idx cur_str_idx = re_string_cur_idx (&mctx->input); in find_recover_state()
2359 re_string_skip_bytes (&mctx->input, 1); in find_recover_state()
2361 while (mctx->state_log[cur_str_idx] == NULL); in find_recover_state()
2363 cur_state = merge_state_with_log (err, mctx, NULL); in find_recover_state()
2377 check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes, in check_subexp_matching_top() argument
2380 const re_dfa_t *const dfa = mctx->dfa; in check_subexp_matching_top()
2397 err = match_ctx_add_subtop (mctx, node, str_idx); in check_subexp_matching_top()
2410 transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx,
2413 const re_dfa_t *const dfa = mctx->dfa;
2416 Idx node_cnt, cur_str_idx = re_string_cur_idx (&mctx->input);
2425 if (check_node_accept (mctx, dfa->nodes + cur_node, cur_str_idx))
2436 context = re_string_context_at (&mctx->input, cur_str_idx, mctx->eflags);
2442 re_string_skip_bytes (&mctx->input, 1);
2449 transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate) in transit_state_mb() argument
2451 const re_dfa_t *const dfa = mctx->dfa; in transit_state_mb()
2469 context = re_string_context_at (&mctx->input, in transit_state_mb()
2470 re_string_cur_idx (&mctx->input), in transit_state_mb()
2471 mctx->eflags); in transit_state_mb()
2478 naccepted = check_node_accept_bytes (dfa, cur_node_idx, &mctx->input, in transit_state_mb()
2479 re_string_cur_idx (&mctx->input)); in transit_state_mb()
2484 dest_idx = re_string_cur_idx (&mctx->input) + naccepted; in transit_state_mb()
2485 mctx->max_mb_elem_len = ((mctx->max_mb_elem_len < naccepted) ? naccepted in transit_state_mb()
2486 : mctx->max_mb_elem_len); in transit_state_mb()
2487 err = clean_state_log_if_needed (mctx, dest_idx); in transit_state_mb()
2493 dest_state = mctx->state_log[dest_idx]; in transit_state_mb()
2503 context = re_string_context_at (&mctx->input, dest_idx - 1, in transit_state_mb()
2504 mctx->eflags); in transit_state_mb()
2505 mctx->state_log[dest_idx] in transit_state_mb()
2509 if (__glibc_unlikely (mctx->state_log[dest_idx] == NULL in transit_state_mb()
2518 transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes) in transit_state_bkref() argument
2520 const re_dfa_t *const dfa = mctx->dfa; in transit_state_bkref()
2523 Idx cur_str_idx = re_string_cur_idx (&mctx->input); in transit_state_bkref()
2539 context = re_string_context_at (&mctx->input, cur_str_idx, in transit_state_bkref()
2540 mctx->eflags); in transit_state_bkref()
2547 bkc_idx = mctx->nbkref_ents; in transit_state_bkref()
2548 err = get_subexp (mctx, node_idx, cur_str_idx); in transit_state_bkref()
2555 for (; bkc_idx < mctx->nbkref_ents; ++bkc_idx) in transit_state_bkref()
2560 bkref_ent = mctx->bkref_ents + bkc_idx; in transit_state_bkref()
2569 context = re_string_context_at (&mctx->input, dest_str_idx - 1, in transit_state_bkref()
2570 mctx->eflags); in transit_state_bkref()
2571 dest_state = mctx->state_log[dest_str_idx]; in transit_state_bkref()
2572 prev_nelem = ((mctx->state_log[cur_str_idx] == NULL) ? 0 in transit_state_bkref()
2573 : mctx->state_log[cur_str_idx]->nodes.nelem); in transit_state_bkref()
2577 mctx->state_log[dest_str_idx] in transit_state_bkref()
2580 if (__glibc_unlikely (mctx->state_log[dest_str_idx] == NULL in transit_state_bkref()
2595 mctx->state_log[dest_str_idx] in transit_state_bkref()
2598 if (__glibc_unlikely (mctx->state_log[dest_str_idx] == NULL in transit_state_bkref()
2605 && mctx->state_log[cur_str_idx]->nodes.nelem > prev_nelem) in transit_state_bkref()
2607 err = check_subexp_matching_top (mctx, new_dest_nodes, in transit_state_bkref()
2611 err = transit_state_bkref (mctx, new_dest_nodes); in transit_state_bkref()
2630 get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx) in get_subexp() argument
2632 const re_dfa_t *const dfa = mctx->dfa; in get_subexp()
2634 const char *buf = (const char *) re_string_get_buffer (&mctx->input); in get_subexp()
2636 Idx cache_idx = search_cur_bkref_entry (mctx, bkref_str_idx); in get_subexp()
2640 = mctx->bkref_ents + cache_idx; in get_subexp()
2650 for (sub_top_idx = 0; sub_top_idx < mctx->nsub_tops; ++sub_top_idx) in get_subexp()
2653 re_sub_match_top_t *sub_top = mctx->sub_tops[sub_top_idx]; in get_subexp()
2674 > mctx->input.valid_len)) in get_subexp()
2677 if (bkref_str_off + sl_str_diff > mctx->input.len) in get_subexp()
2680 err = clean_state_log_if_needed (mctx, in get_subexp()
2685 buf = (const char *) re_string_get_buffer (&mctx->input); in get_subexp()
2693 err = get_subexp_sub (mctx, sub_top, sub_last, bkref_node, in get_subexp()
2698 buf = (const char *) re_string_get_buffer (&mctx->input); in get_subexp()
2721 if (__glibc_unlikely (bkref_str_off >= mctx->input.valid_len)) in get_subexp()
2724 if (bkref_str_off >= mctx->input.len) in get_subexp()
2727 err = extend_buffers (mctx, bkref_str_off + 1); in get_subexp()
2731 buf = (const char *) re_string_get_buffer (&mctx->input); in get_subexp()
2737 if (mctx->state_log[sl_str] == NULL) in get_subexp()
2740 nodes = &mctx->state_log[sl_str]->nodes; in get_subexp()
2754 err = check_arrival (mctx, sub_top->path, sub_top->node, in get_subexp()
2764 err = get_subexp_sub (mctx, sub_top, sub_last, bkref_node, in get_subexp()
2766 buf = (const char *) re_string_get_buffer (&mctx->input); in get_subexp()
2783 get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top, in get_subexp_sub() argument
2789 err = check_arrival (mctx, &sub_last->path, sub_last->node, in get_subexp_sub()
2794 err = match_ctx_add_entry (mctx, bkref_node, bkref_str, sub_top->str_idx, in get_subexp_sub()
2799 return clean_state_log_if_needed (mctx, to_idx); in get_subexp_sub()
2834 check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, in check_arrival() argument
2837 const re_dfa_t *const dfa = mctx->dfa; in check_arrival()
2847 if (__glibc_unlikely (path->alloc < last_str + mctx->max_mb_elem_len + 1)) in check_arrival()
2851 Idx incr_alloc = last_str + mctx->max_mb_elem_len + 1; in check_arrival()
2870 backup_state_log = mctx->state_log; in check_arrival()
2871 backup_cur_idx = mctx->input.cur_idx; in check_arrival()
2872 mctx->state_log = path->array; in check_arrival()
2873 mctx->input.cur_idx = str_idx; in check_arrival()
2876 context = re_string_context_at (&mctx->input, str_idx - 1, mctx->eflags); in check_arrival()
2891 cur_state = mctx->state_log[str_idx]; in check_arrival()
2905 err = expand_bkref_cache (mctx, &next_nodes, str_idx, in check_arrival()
2919 mctx->state_log[str_idx] = cur_state; in check_arrival()
2922 for (null_cnt = 0; str_idx < last_str && null_cnt <= mctx->max_mb_elem_len;) in check_arrival()
2925 if (mctx->state_log[str_idx + 1]) in check_arrival()
2928 &mctx->state_log[str_idx + 1]->nodes); in check_arrival()
2937 err = check_arrival_add_next_nodes (mctx, str_idx, in check_arrival()
2955 err = expand_bkref_cache (mctx, &next_nodes, str_idx, in check_arrival()
2963 context = re_string_context_at (&mctx->input, str_idx - 1, mctx->eflags); in check_arrival()
2970 mctx->state_log[str_idx] = cur_state; in check_arrival()
2974 cur_nodes = (mctx->state_log[last_str] == NULL ? NULL in check_arrival()
2975 : &mctx->state_log[last_str]->nodes); in check_arrival()
2979 mctx->state_log = backup_state_log; in check_arrival()
2980 mctx->input.cur_idx = backup_cur_idx; in check_arrival()
2999 check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx, in check_arrival_add_next_nodes() argument
3002 const re_dfa_t *const dfa = mctx->dfa; in check_arrival_add_next_nodes()
3020 naccepted = check_node_accept_bytes (dfa, cur_node, &mctx->input, in check_arrival_add_next_nodes()
3027 dest_state = mctx->state_log[next_idx]; in check_arrival_add_next_nodes()
3044 mctx->state_log[next_idx] = re_acquire_state (&err, dfa, in check_arrival_add_next_nodes()
3046 if (__glibc_unlikely (mctx->state_log[next_idx] == NULL in check_arrival_add_next_nodes()
3056 || check_node_accept (mctx, dfa->nodes + cur_node, str_idx)) in check_arrival_add_next_nodes()
3173 expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, in expand_bkref_cache() argument
3176 const re_dfa_t *const dfa = mctx->dfa; in expand_bkref_cache()
3178 Idx cache_idx_start = search_cur_bkref_entry (mctx, cur_str); in expand_bkref_cache()
3185 ent = mctx->bkref_ents + cache_idx_start; in expand_bkref_cache()
3224 if (mctx->state_log[to_idx]) in expand_bkref_cache()
3227 if (re_node_set_contains (&mctx->state_log[to_idx]->nodes, in expand_bkref_cache()
3231 &mctx->state_log[to_idx]->nodes); in expand_bkref_cache()
3246 mctx->state_log[to_idx] = re_acquire_state (&err, dfa, &union_set); in expand_bkref_cache()
3248 if (__glibc_unlikely (mctx->state_log[to_idx] == NULL in expand_bkref_cache()
3936 check_node_accept (const re_match_context_t *mctx, const re_token_t *node, in check_node_accept() argument
3940 ch = re_string_byte_at (&mctx->input, idx); in check_node_accept()
3960 if ((ch == '\n' && !(mctx->dfa->syntax & RE_DOT_NEWLINE)) in check_node_accept()
3961 || (ch == '\0' && (mctx->dfa->syntax & RE_DOT_NOT_NULL))) in check_node_accept()
3973 unsigned int context = re_string_context_at (&mctx->input, idx, in check_node_accept()
3974 mctx->eflags); in check_node_accept()
3986 extend_buffers (re_match_context_t *mctx, int min_len) in extend_buffers() argument
3989 re_string_t *pstr = &mctx->input; in extend_buffers()
4003 if (mctx->state_log != NULL) in extend_buffers()
4009 re_dfastate_t **new_array = re_realloc (mctx->state_log, re_dfastate_t *, in extend_buffers()
4013 mctx->state_log = new_array; in extend_buffers()
4052 match_ctx_init (re_match_context_t *mctx, int eflags, Idx n) in match_ctx_init() argument
4054 mctx->eflags = eflags; in match_ctx_init()
4055 mctx->match_last = -1; in match_ctx_init()
4065 mctx->bkref_ents = re_malloc (struct re_backref_cache_entry, n); in match_ctx_init()
4066 mctx->sub_tops = re_malloc (re_sub_match_top_t *, n); in match_ctx_init()
4067 if (__glibc_unlikely (mctx->bkref_ents == NULL || mctx->sub_tops == NULL)) in match_ctx_init()
4075 mctx->abkref_ents = n; in match_ctx_init()
4076 mctx->max_mb_elem_len = 1; in match_ctx_init()
4077 mctx->asub_tops = n; in match_ctx_init()
4086 match_ctx_clean (re_match_context_t *mctx) in match_ctx_clean() argument
4089 for (st_idx = 0; st_idx < mctx->nsub_tops; ++st_idx) in match_ctx_clean()
4092 re_sub_match_top_t *top = mctx->sub_tops[st_idx]; in match_ctx_clean()
4108 mctx->nsub_tops = 0; in match_ctx_clean()
4109 mctx->nbkref_ents = 0; in match_ctx_clean()
4115 match_ctx_free (re_match_context_t *mctx) in match_ctx_free() argument
4118 match_ctx_clean (mctx); in match_ctx_free()
4119 re_free (mctx->sub_tops); in match_ctx_free()
4120 re_free (mctx->bkref_ents); in match_ctx_free()
4130 match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from, in match_ctx_add_entry() argument
4133 if (mctx->nbkref_ents >= mctx->abkref_ents) in match_ctx_add_entry()
4136 new_entry = re_realloc (mctx->bkref_ents, struct re_backref_cache_entry, in match_ctx_add_entry()
4137 mctx->abkref_ents * 2); in match_ctx_add_entry()
4140 re_free (mctx->bkref_ents); in match_ctx_add_entry()
4143 mctx->bkref_ents = new_entry; in match_ctx_add_entry()
4144 memset (mctx->bkref_ents + mctx->nbkref_ents, '\0', in match_ctx_add_entry()
4145 sizeof (struct re_backref_cache_entry) * mctx->abkref_ents); in match_ctx_add_entry()
4146 mctx->abkref_ents *= 2; in match_ctx_add_entry()
4148 if (mctx->nbkref_ents > 0 in match_ctx_add_entry()
4149 && mctx->bkref_ents[mctx->nbkref_ents - 1].str_idx == str_idx) in match_ctx_add_entry()
4150 mctx->bkref_ents[mctx->nbkref_ents - 1].more = 1; in match_ctx_add_entry()
4152 mctx->bkref_ents[mctx->nbkref_ents].node = node; in match_ctx_add_entry()
4153 mctx->bkref_ents[mctx->nbkref_ents].str_idx = str_idx; in match_ctx_add_entry()
4154 mctx->bkref_ents[mctx->nbkref_ents].subexp_from = from; in match_ctx_add_entry()
4155 mctx->bkref_ents[mctx->nbkref_ents].subexp_to = to; in match_ctx_add_entry()
4165 mctx->bkref_ents[mctx->nbkref_ents].eps_reachable_subexps_map in match_ctx_add_entry()
4168 mctx->bkref_ents[mctx->nbkref_ents++].more = 0; in match_ctx_add_entry()
4169 if (mctx->max_mb_elem_len < to - from) in match_ctx_add_entry()
4170 mctx->max_mb_elem_len = to - from; in match_ctx_add_entry()
4178 search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx) in search_cur_bkref_entry() argument
4181 last = right = mctx->nbkref_ents; in search_cur_bkref_entry()
4185 if (mctx->bkref_ents[mid].str_idx < str_idx) in search_cur_bkref_entry()
4190 if (left < last && mctx->bkref_ents[left].str_idx == str_idx) in search_cur_bkref_entry()
4201 match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx) in match_ctx_add_subtop() argument
4203 DEBUG_ASSERT (mctx->sub_tops != NULL); in match_ctx_add_subtop()
4204 DEBUG_ASSERT (mctx->asub_tops > 0); in match_ctx_add_subtop()
4205 if (__glibc_unlikely (mctx->nsub_tops == mctx->asub_tops)) in match_ctx_add_subtop()
4207 Idx new_asub_tops = mctx->asub_tops * 2; in match_ctx_add_subtop()
4208 re_sub_match_top_t **new_array = re_realloc (mctx->sub_tops, in match_ctx_add_subtop()
4213 mctx->sub_tops = new_array; in match_ctx_add_subtop()
4214 mctx->asub_tops = new_asub_tops; in match_ctx_add_subtop()
4216 mctx->sub_tops[mctx->nsub_tops] = calloc (1, sizeof (re_sub_match_top_t)); in match_ctx_add_subtop()
4217 if (__glibc_unlikely (mctx->sub_tops[mctx->nsub_tops] == NULL)) in match_ctx_add_subtop()
4219 mctx->sub_tops[mctx->nsub_tops]->node = node; in match_ctx_add_subtop()
4220 mctx->sub_tops[mctx->nsub_tops++]->str_idx = str_idx; in match_ctx_add_subtop()