This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
eliminate PL_reg_state
authorDavid Mitchell <davem@iabyn.com>
Fri, 31 May 2013 21:35:40 +0000 (22:35 +0100)
committerDavid Mitchell <davem@iabyn.com>
Sun, 2 Jun 2013 21:28:55 +0000 (22:28 +0100)
This is a struct that holds all the global state of the current regex
match.
The previous set of commits have gradually removed all the fields of this
struct (by making things local rather than global state). Since the struct
is now empty, the PL_reg_state var can be removed, along with the
SAVEt_RE_STATE save type which was used to save and restore those fields
on recursive re-entry to the regex engine.

embedvar.h
intrpvar.h
regcomp.c
regexec.c
regexp.h
scope.c
scope.h
sv.c

index ee41546..523874c 100644 (file)
 #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)
 #define PL_regex_padav         (vTHX->Iregex_padav)
index 32a9983..27058d7 100644 (file)
@@ -119,8 +119,6 @@ PERLVAR(I, sv_objcount,     IV)             /* DEPRECATED AND UNMAINTAINED.
 PERLVAR(I, sv_root,    SV *)           /* storage for SVs belonging to interp */
 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)
 
index 03d5d50..9ed4510 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -15458,17 +15458,6 @@ Perl_save_re_context(pTHX)
 {
     dVAR;
 
-    struct re_save_state *state;
-
-    SAVEVPTR(PL_curcop);
-    SSGROW(SAVESTACK_ALLOC_FOR_RE_SAVE_STATE + 1);
-
-    state = (struct re_save_state *)(PL_savestack + PL_savestack_ix);
-    PL_savestack_ix += SAVESTACK_ALLOC_FOR_RE_SAVE_STATE;
-    SSPUSHUV(SAVEt_RE_STATE);
-
-    Copy(&PL_reg_state, state, 1, struct re_save_state);
-
     /* Save $1..$n (#18107: UTF-8 s/(\w+)/uc($1)/e); AMS 20021106. */
     if (PL_curpm) {
        const REGEXP * const rx = PM_GETRE(PL_curpm);
index 449a1e5..eb95d22 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -2821,7 +2821,7 @@ phooey:
 }
 
 
-/* Set which rex is pointed to by PL_reg_state, handling ref counting.
+/* Set which rex is pointed to by PL_reg_curpm, handling ref counting.
  * Do inc before dec, in case old and new rex are the same */
 #define SET_reg_curpm(Re2) \
     if (reginfo->info_aux_eval) {                   \
@@ -4836,29 +4836,12 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
                OP * const oop = PL_op;
                COP * const ocurcop = PL_curcop;
                OP *nop;
-               struct re_save_state saved_state;
                CV *newcv;
 
                /* save *all* paren positions */
                regcppush(rex, 0, maxopenparen);
                REGCP_SET(runops_cp);
 
-               /* To not corrupt the existing regex state while executing the
-                * eval we would normally put it on the save stack, like with
-                * save_re_context. However, re-evals have a weird scoping so we
-                * can't just add ENTER/LEAVE here. With that, things like
-                *
-                *    (?{$a=2})(a(?{local$a=$a+1}))*aak*c(?{$b=$a})
-                *
-                * would break, as they expect the localisation to be unwound
-                * only when the re-engine backtracks through the bit that
-                * localised it.
-                *
-                * What we do instead is just saving the state in a local c
-                * variable.
-                */
-               Copy(&PL_reg_state, &saved_state, 1, struct re_save_state);
-
                if (!caller_cv)
                    caller_cv = find_runcv(NULL);
 
@@ -5007,8 +4990,6 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
 
                }
 
-               Copy(&saved_state, &PL_reg_state, 1, struct re_save_state);
-
                /* *** Note that at this point we don't restore
                 * PL_comppad, (or pop the CxSUB) on the assumption it may
                 * be used again soon. This is safe as long as nothing
index 8256c8d..5422bd1 100644 (file)
--- a/regexp.h
+++ b/regexp.h
@@ -829,13 +829,6 @@ typedef struct regmatch_slab {
 } regmatch_slab;
 
 
-struct re_save_state {
-    /* temporarily give the struct a member till we delete the whole thing */
-    int dummy;
-};
-
-#define SAVESTACK_ALLOC_FOR_RE_SAVE_STATE \
-       (1 + ((sizeof(struct re_save_state) - 1) / sizeof(*PL_savestack)))
 
 /*
  * Local variables:
diff --git a/scope.c b/scope.c
index 2d3810f..d2ae04a 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -1225,17 +1225,6 @@ Perl_leave_scope(pTHX_ I32 base)
 
            PL_compiling.cop_warnings = (STRLEN*)ARG0_PTR;
            break;
-       case SAVEt_RE_STATE:
-           {
-               const struct re_save_state *const state
-                   = (struct re_save_state *)
-                   (PL_savestack + PL_savestack_ix
-                    - SAVESTACK_ALLOC_FOR_RE_SAVE_STATE);
-               PL_savestack_ix -= SAVESTACK_ALLOC_FOR_RE_SAVE_STATE;
-
-               Copy(state, &PL_reg_state, 1, struct re_save_state);
-           }
-           break;
        case SAVEt_PARSER:
            parser_free((yy_parser *) ARG0_PTR);
            break;
diff --git a/scope.h b/scope.h
index 22c728d..a9ef542 100644 (file)
--- a/scope.h
+++ b/scope.h
@@ -16,7 +16,7 @@
 #define SAVEt_CLEARPADRANGE    1
 #define SAVEt_CLEARSV          2
 #define SAVEt_REGCONTEXT       3
-#define SAVEt_RE_STATE         4
+/*** SPARE                     4 ***/
 
 #define SAVEt_ARG0_MAX         4
 
diff --git a/sv.c b/sv.c
index a56d9bd..98a6b36 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -12889,19 +12889,6 @@ Perl_ss_dup(pTHX_ PerlInterpreter *proto_perl, CLONE_PARAMS* param)
            sv = (const SV *)POPPTR(ss,ix);
            TOPPTR(nss,ix) = sv_dup(sv, param);
            break;
-       case SAVEt_RE_STATE:
-           {
-               const struct re_save_state *const old_state
-                   = (struct re_save_state *)
-                   (ss + ix - SAVESTACK_ALLOC_FOR_RE_SAVE_STATE);
-               struct re_save_state *const new_state
-                   = (struct re_save_state *)
-                   (nss + ix - SAVESTACK_ALLOC_FOR_RE_SAVE_STATE);
-
-               Copy(old_state, new_state, 1, struct re_save_state);
-               ix -= SAVESTACK_ALLOC_FOR_RE_SAVE_STATE;
-               break;
-           }
        case SAVEt_COMPILE_WARNINGS:
            ptr = POPPTR(ss,ix);
            TOPPTR(nss,ix) = DUP_WARNINGS((STRLEN*)ptr);
@@ -13159,7 +13146,6 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags,
 #endif
 
     /* RE engine related */
-    Zero(&PL_reg_state, 1, struct re_save_state);
     PL_regmatch_slab   = NULL;
     PL_reg_curpm       = NULL;