From f65e70f560c80556143956eb9980619a9dfbe2f4 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Fri, 31 May 2013 21:39:01 +0100 Subject: [PATCH] make PL_reg_curpm global Currently PL_reg_curpm is actually #deffed to a field within PL_reg_state; promote it into a fully autonomous perl-interpreter variable. PL_reg_curpm points to a fake PMOP that's used to temporarily point PL_curpm to, that we can hang the current regex off, so that this works: "a" =~ /^(.)(?{ print $1 })/ # prints 'a' It turns out that it doesn't need to be saved and restored when we recursively enter the regex engine; that is already handled by saving and restoring which regex is currently attached to PL_reg_curpm. So we just need a single global (per interpreter) placeholder. Since we're shortly going to get rid of PL_reg_state, we need to move it out of that struct. --- embedvar.h | 1 + intrpvar.h | 3 +++ perl.c | 3 --- regexec.c | 4 ++++ regexp.h | 2 -- sv.c | 5 +---- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/embedvar.h b/embedvar.h index e689c5e..ee41546 100644 --- a/embedvar.h +++ b/embedvar.h @@ -245,6 +245,7 @@ #define PL_ptr_table (vTHX->Iptr_table) #define PL_reentrant_buffer (vTHX->Ireentrant_buffer) #define PL_reentrant_retint (vTHX->Ireentrant_retint) +#define PL_reg_curpm (vTHX->Ireg_curpm) #define PL_reg_state (vTHX->Ireg_state) #define PL_regdummy (vTHX->Iregdummy) #define PL_regex_pad (vTHX->Iregex_pad) diff --git a/intrpvar.h b/intrpvar.h index a148a3c..32a9983 100644 --- a/intrpvar.h +++ b/intrpvar.h @@ -121,6 +121,9 @@ PERLVAR(I, sv_arenaroot, SV *) /* list of areas for garbage collection */ PERLVAR(I, reg_state, struct re_save_state) +/* fake PMOP that PL_curpm points to while in (?{}) so $1 et al are visible */ +PERLVARI(I, reg_curpm, PMOP*, NULL) + /* the currently active slab in a chain of slabs of regmatch states, * and the currently active state within that slab */ diff --git a/perl.c b/perl.c index 726f571..fe0c02b 100644 --- a/perl.c +++ b/perl.c @@ -3622,9 +3622,6 @@ S_init_interp(pTHX) # undef PERLVARIC #endif - /* As these are inside a structure, PERLVARI isn't capable of initialising - them */ - PL_reg_curpm = NULL; } STATIC void diff --git a/regexec.c b/regexec.c index a144138..13dce3f 100644 --- a/regexec.c +++ b/regexec.c @@ -7576,6 +7576,10 @@ S_setup_eval_state(pTHX_ regmatch_info *const reginfo) eval_state->pos_magic = NULL; if (!PL_reg_curpm) { + /* PL_reg_curpm is a fake PMOP that we can attach the current + * regex to and point PL_curpm at, so that $1 et al are visible + * within a /(?{})/. It's just allocated once per interpreter the + * first time its needed */ Newxz(PL_reg_curpm, 1, PMOP); #ifdef USE_ITHREADS { diff --git a/regexp.h b/regexp.h index 01c8f36..bd3aeb6 100644 --- a/regexp.h +++ b/regexp.h @@ -828,11 +828,9 @@ typedef struct regmatch_slab { struct regmatch_slab *prev, *next; } regmatch_slab; -#define PL_reg_curpm PL_reg_state.re_state_reg_curpm #define PL_reg_starttry PL_reg_state.re_state_reg_starttry struct re_save_state { - PMOP *re_state_reg_curpm; /* from regexec.c */ char *re_state_reg_starttry; /* from regexec.c */ }; diff --git a/sv.c b/sv.c index 66b58e0..a56d9bd 100644 --- a/sv.c +++ b/sv.c @@ -12900,10 +12900,6 @@ Perl_ss_dup(pTHX_ PerlInterpreter *proto_perl, CLONE_PARAMS* param) Copy(old_state, new_state, 1, struct re_save_state); ix -= SAVESTACK_ALLOC_FOR_RE_SAVE_STATE; - - new_state->re_state_reg_curpm - = (PMOP*) any_dup(old_state->re_state_reg_curpm, - proto_perl); break; } case SAVEt_COMPILE_WARNINGS: @@ -13165,6 +13161,7 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags, /* RE engine related */ Zero(&PL_reg_state, 1, struct re_save_state); PL_regmatch_slab = NULL; + PL_reg_curpm = NULL; PL_sub_generation = proto_perl->Isub_generation; -- 1.8.3.1