#define FBMrf_MULTILINE 1
+struct regmatch_state;
+struct regmatch_slab;
-/* saved state when executing a regex that contains code blocks.
- * These need restoring at the end of the match, or on croak().
- * These fields can't be stored in regmatch_info since the latter is
- * allocated directly on the stack in regexec_flags(), and they need to
- * exist during a croak() after the stack has been unwound */
+/* like regmatch_info_aux, but contains extra fields only needed if the
+ * pattern contains (?{}). If used, is snuck into the second slot in the
+ * regmatch_state stack at the start of execution */
typedef struct {
regexp *rex;
STRLEN subcoffset; /* saved subcoffset field from rex */
MAGIC *pos_magic; /* pos() magic attached to $_ */
I32 pos; /* the original value of pos() in pos_magic */
- bool restored; /* we have already undone the save */
- bool direct; /* we are calling the destructor directly */
-} regmatch_eval_state;
+} regmatch_info_aux_eval;
+
+
+/* fields that logically live in regmatch_info, but which need cleaning
+ * up on croak(), and so are instead are snuck into the first slot in
+ * the regmatch_state stack at the start of execution */
+
+typedef struct {
+ regmatch_info_aux_eval *info_aux_eval;
+ struct regmatch_state *old_regmatch_state; /* saved PL_regmatch_state */
+ struct regmatch_slab *old_regmatch_slab; /* saved PL_regmatch_slab */
+ char *poscache; /* S-L cache of fail positions of WHILEMs */
+} regmatch_info_aux;
+
/* some basic information about the current match that is created by
- * Perl_regexec_flags and then passed to regtry(), regmatch() etc */
+ * Perl_regexec_flags and then passed to regtry(), regmatch() etc.
+ * It is allocated as a local var on the stack, so nothing should be
+ * stored in it that needs preserving or clearing up on croak().
+ * For that, see the aux_info and aux_info_eval members of the
+ * regmatch_state union. */
typedef struct {
- REGEXP *prog;
+ REGEXP *prog; /* the regex being executed */
const char * strbeg; /* real start of string */
- char *strend; /* one byte beyond last char of match string */
- char *till;
- SV *sv;
- char *ganch;
- char *cutpoint;
- regmatch_eval_state *eval_state; /* extra saved state for (?{}) */
+ char *strend; /* one byte beyond last char of match string */
+ char *till; /* matches shorter than this fail (see minlen arg) */
+ SV *sv; /* the SV string currently being matched */
+ char *ganch; /* position of \G anchor */
+ char *cutpoint; /* (*COMMIT) position (if any) */
+ regmatch_info_aux *info_aux; /* extra fields that need cleanup */
+ regmatch_info_aux_eval *info_aux_eval; /* extra saved state for (?{}) */
+ I32 poscache_maxiter; /* how many whilems todo before S-L cache kicks in */
+ I32 poscache_iter; /* current countdown from _maxiter to zero */
+ STRLEN poscache_size; /* size of regmatch_info_aux.poscache */
bool intuit; /* re_intuit_start() is the top-level caller */
bool is_utf8_pat; /* regex is utf8 */
bool is_utf8_target; /* string being matched is utf8 */
union {
+ /* the 'info_aux' and 'info_aux_eval' union members are cuckoos in
+ * the nest. They aren't saved backtrack state; rather they
+ * represent one or two extra chunks of data that need allocating
+ * at the start of a match. These fields would logically live in
+ * the regmatch_info struct, except that is allocated on the
+ * C stack, and these fields are all things that require cleanup
+ * after a croak(), when the stack is lost.
+ * As a convenience, we just use the first 1 or 2 regmatch_state
+ * slots to store this info, as we will be allocating a slab of
+ * these anyway. Otherwise we'd have to malloc and then free them,
+ * or allocate them on the save stack (where they will get
+ * realloced if the save stack grows).
+ * info_aux contains the extra fields that are always needed;
+ * info_aux_eval contains extra fields that only needed if
+ * the pattern contains code blocks
+ * We split them into two separate structs to avoid increasing
+ * the size of the union.
+ */
+
+ regmatch_info_aux info_aux;
+
+ regmatch_info_aux_eval info_aux_eval;
+
/* this is a fake union member that matches the first element
* of each member that needs to store positive backtrack
* information */
struct regmatch_slab *prev, *next;
} regmatch_slab;
-#define PL_reg_curpm PL_reg_state.re_state_reg_curpm
-#define PL_reg_maxiter PL_reg_state.re_state_reg_maxiter
-#define PL_reg_leftiter PL_reg_state.re_state_reg_leftiter
-#define PL_reg_poscache PL_reg_state.re_state_reg_poscache
-#define PL_reg_poscache_size PL_reg_state.re_state_reg_poscache_size
-#define PL_reg_starttry PL_reg_state.re_state_reg_starttry
-
-struct re_save_state {
- I32 re_state_reg_maxiter; /* max wait until caching pos */
- I32 re_state_reg_leftiter; /* wait until caching pos */
- PMOP *re_state_reg_curpm; /* from regexec.c */
- STRLEN re_state_reg_poscache_size; /* size of pos cache of WHILEM */
- char *re_state_reg_poscache; /* cache of pos of WHILEM */
- char *re_state_reg_starttry; /* from regexec.c */
-};
-#define SAVESTACK_ALLOC_FOR_RE_SAVE_STATE \
- (1 + ((sizeof(struct re_save_state) - 1) / sizeof(*PL_savestack)))
/*
* Local variables: