PUSHSTACK renovation
Joshua Pritikin [Fri, 26 Jun 1998 09:34:34 +0000 (05:34 -0400)]
Message-Id: <H00000e500081d23@MHS>

p4raw-id: //depot/perl@1254

av.c
cop.h
gv.c
mg.c
perl.c
pp_ctl.c
pp_sys.c
sv.c
util.c

diff --git a/av.c b/av.c
index 36bfa9c..6e41c2e 100644 (file)
--- a/av.c
+++ b/av.c
@@ -53,14 +53,14 @@ av_extend(AV *av, I32 key)
        dSP;
        ENTER;
        SAVETMPS;
-       PUSHSTACK(SI_MAGIC);
+       PUSHSTACKi(SI_MAGIC);
        PUSHMARK(SP);
        EXTEND(SP,2);
        PUSHs(mg->mg_obj);
        PUSHs(sv_2mortal(newSViv(key+1)));
         PUTBACK;
        perl_call_method("EXTEND", G_SCALAR|G_DISCARD);
-       POPSTACK();
+       POPSTACK;
        FREETMPS;
        LEAVE;
        return;
@@ -399,7 +399,7 @@ av_push(register AV *av, SV *val)
 
     if (SvRMAGICAL(av) && (mg = mg_find((SV*)av,'P'))) {
        dSP;
-       PUSHSTACK(SI_MAGIC);
+       PUSHSTACKi(SI_MAGIC);
        PUSHMARK(SP);
        EXTEND(SP,2);
        PUSHs(mg->mg_obj);
@@ -408,7 +408,7 @@ av_push(register AV *av, SV *val)
        ENTER;
        perl_call_method("PUSH", G_SCALAR|G_DISCARD);
        LEAVE;
-       POPSTACK();
+       POPSTACK;
        return;
     }
     av_store(av,AvFILLp(av)+1,val);
@@ -426,7 +426,7 @@ av_pop(register AV *av)
        croak(no_modify);
     if (SvRMAGICAL(av) && (mg = mg_find((SV*)av,'P'))) {
        dSP;    
-       PUSHSTACK(SI_MAGIC);
+       PUSHSTACKi(SI_MAGIC);
        PUSHMARK(SP);
        XPUSHs(mg->mg_obj);
        PUTBACK;
@@ -437,7 +437,7 @@ av_pop(register AV *av)
            retval = &sv_undef;
        }
        LEAVE;
-       POPSTACK();
+       POPSTACK;
        return retval;
     }
     retval = AvARRAY(av)[AvFILLp(av)];
@@ -461,7 +461,7 @@ av_unshift(register AV *av, register I32 num)
 
     if (SvRMAGICAL(av) && (mg = mg_find((SV*)av,'P'))) {
        dSP;
-       PUSHSTACK(SI_MAGIC);
+       PUSHSTACKi(SI_MAGIC);
        PUSHMARK(SP);
        EXTEND(SP,1+num);
        PUSHs(mg->mg_obj);
@@ -472,7 +472,7 @@ av_unshift(register AV *av, register I32 num)
        ENTER;
        perl_call_method("UNSHIFT", G_SCALAR|G_DISCARD);
        LEAVE;
-       POPSTACK();
+       POPSTACK;
        return;
     }
 
@@ -512,7 +512,7 @@ av_shift(register AV *av)
        croak(no_modify);
     if (SvRMAGICAL(av) && (mg = mg_find((SV*)av,'P'))) {
        dSP;
-       PUSHSTACK(SI_MAGIC);
+       PUSHSTACKi(SI_MAGIC);
        PUSHMARK(SP);
        XPUSHs(mg->mg_obj);
        PUTBACK;
@@ -523,7 +523,7 @@ av_shift(register AV *av)
            retval = &sv_undef;
        }     
        LEAVE;
-       POPSTACK();
+       POPSTACK;
        return retval;
     }
     retval = *AvARRAY(av);
@@ -555,14 +555,14 @@ av_fill(register AV *av, I32 fill)
        dSP;            
        ENTER;
        SAVETMPS;
-       PUSHSTACK(SI_MAGIC);
+       PUSHSTACKi(SI_MAGIC);
        PUSHMARK(SP);
        EXTEND(SP,2);
        PUSHs(mg->mg_obj);
        PUSHs(sv_2mortal(newSViv(fill+1)));
        PUTBACK;
        perl_call_method("STORESIZE", G_SCALAR|G_DISCARD);
-       POPSTACK();
+       POPSTACK;
        FREETMPS;
        LEAVE;
        return;
diff --git a/cop.h b/cop.h
index 4e14c88..478bfd4 100644 (file)
--- a/cop.h
+++ b/cop.h
@@ -292,6 +292,7 @@ struct context {
  * This ensures magic doesn't invalidate local stack and cx pointers.
  */
 
+#define SI_UNKNOWN     -1
 #define SI_UNDEF       0
 #define SI_MAIN                1
 #define SI_MAGIC       2
@@ -301,6 +302,7 @@ struct context {
 #define SI_DESTROY     6
 #define SI_WARNHOOK    7
 #define SI_DIEHOOK     8
+#define SI_REQUIRE     9
 
 struct stackinfo {
     AV *               si_stack;       /* stack for current runlevel */
@@ -327,7 +329,7 @@ typedef struct stackinfo PERL_SI;
 #  define      SET_MARKBASE NOOP
 #endif
 
-#define PUSHSTACK(type) \
+#define PUSHSTACKi(type) \
     STMT_START {                                                       \
        PERL_SI *next = curstackinfo->si_next;                          \
        if (!next) {                                                    \
@@ -343,7 +345,9 @@ typedef struct stackinfo PERL_SI;
        SET_MARKBASE;                                                   \
     } STMT_END
 
-#define POPSTACK() \
+#define PUSHSTACK PUSHSTACKi(SI_UNKNOWN)
+
+#define POPSTACK \
     STMT_START {                                                       \
        PERL_SI *prev = curstackinfo->si_prev;                          \
        if (!prev) {                                                    \
@@ -359,6 +363,6 @@ typedef struct stackinfo PERL_SI;
     STMT_START {                                                       \
        while (curstack != s) {                                         \
            dounwind(-1);                                               \
-           POPSTACK();                                                 \
+           POPSTACK;                                                   \
        }                                                               \
     } STMT_END
diff --git a/gv.c b/gv.c
index ea78d20..9358ba3 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -1356,7 +1356,7 @@ amagic_call(SV *left, SV *right, int method, int flags)
     myop.op_next = Nullop;
     myop.op_flags = OPf_WANT_SCALAR | OPf_STACKED;
 
-    PUSHSTACK(SI_OVERLOAD);
+    PUSHSTACKi(SI_OVERLOAD);
     ENTER;
     SAVEOP();
     op = (OP *) &myop;
@@ -1381,7 +1381,7 @@ amagic_call(SV *left, SV *right, int method, int flags)
     SPAGAIN;
 
     res=POPs;
-    POPSTACK();
+    POPSTACK;
     CATCH_SET(oldcatch);
 
     if (postpr) {
diff --git a/mg.c b/mg.c
index d6ea1d2..def57c4 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -1030,13 +1030,13 @@ magic_methpack(SV *sv, MAGIC *mg, char *meth)
 
     ENTER;
     SAVETMPS;
-    PUSHSTACK(SI_MAGIC);
+    PUSHSTACKi(SI_MAGIC);
 
     if (magic_methcall(mg, meth, G_SCALAR, 2, NULL)) {
        sv_setsv(sv, *stack_sp--);
     }
 
-    POPSTACK();
+    POPSTACK;
     FREETMPS;
     LEAVE;
     return 0;
@@ -1056,9 +1056,9 @@ magic_setpack(SV *sv, MAGIC *mg)
 {
     dSP;
     ENTER;
-    PUSHSTACK(SI_MAGIC);
+    PUSHSTACKi(SI_MAGIC);
     magic_methcall(mg, "STORE", G_SCALAR|G_DISCARD, 3, sv);
-    POPSTACK();
+    POPSTACK;
     LEAVE;
     return 0;
 }
@@ -1078,12 +1078,12 @@ magic_sizepack(SV *sv, MAGIC *mg)
 
     ENTER;
     SAVETMPS;
-    PUSHSTACK(SI_MAGIC);
+    PUSHSTACKi(SI_MAGIC);
     if (magic_methcall(mg, "FETCHSIZE", G_SCALAR, 2, NULL)) {
        sv = *stack_sp--;
        retval = (U32) SvIV(sv)-1;
     }
-    POPSTACK();
+    POPSTACK;
     FREETMPS;
     LEAVE;
     return retval;
@@ -1094,12 +1094,12 @@ int magic_wipepack(SV *sv, MAGIC *mg)
     dSP;
 
     ENTER;
-    PUSHSTACK(SI_MAGIC);
+    PUSHSTACKi(SI_MAGIC);
     PUSHMARK(SP);
     XPUSHs(mg->mg_obj);
     PUTBACK;
     perl_call_method("CLEAR", G_SCALAR|G_DISCARD);
-    POPSTACK();
+    POPSTACK;
     LEAVE;
     return 0;
 }
@@ -1112,7 +1112,7 @@ magic_nextpack(SV *sv, MAGIC *mg, SV *key)
 
     ENTER;
     SAVETMPS;
-    PUSHSTACK(SI_MAGIC);
+    PUSHSTACKi(SI_MAGIC);
     PUSHMARK(SP);
     EXTEND(SP, 2);
     PUSHs(mg->mg_obj);
@@ -1123,7 +1123,7 @@ magic_nextpack(SV *sv, MAGIC *mg, SV *key)
     if (perl_call_method(meth, G_SCALAR))
        sv_setsv(key, *stack_sp--);
 
-    POPSTACK();
+    POPSTACK;
     FREETMPS;
     LEAVE;
     return 0;
@@ -1996,14 +1996,14 @@ sighandler(int sig)
        sv_setpv(sv,sig_name[sig]);
     }
 
-    PUSHSTACK(SI_SIGNAL);
+    PUSHSTACKi(SI_SIGNAL);
     PUSHMARK(SP);
     PUSHs(sv);
     PUTBACK;
 
     perl_call_sv((SV*)cv, G_DISCARD);
 
-    POPSTACK();
+    POPSTACK;
 cleanup:
     if (flags & 1)
        savestack_ix -= 8; /* Unprotect save in progress. */
diff --git a/perl.c b/perl.c
index db78b4e..0a675ea 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -1434,11 +1434,17 @@ perl_eval_pv(char *p, I32 croak_on_error)
 void
 perl_require_pv(char *pv)
 {
-    SV* sv = sv_newmortal();
+    SV* sv;
+    dSP;
+    PUSHSTACKi(SI_REQUIRE);
+    PUTBACK;
+    sv = sv_newmortal();
     sv_setpv(sv, "require '");
     sv_catpv(sv, pv);
     sv_catpv(sv, "'");
     perl_eval_sv(sv, G_DISCARD);
+    SPAGAIN;
+    POPSTACK;
 }
 
 void
index 5263320..f35546c 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -720,7 +720,7 @@ PP(pp_sort)
            SAVEOP();
 
            CATCH_SET(TRUE);
-           PUSHSTACK(SI_SORT);
+           PUSHSTACKi(SI_SORT);
            if (sortstash != stash) {
                firstgv = gv_fetchpv("a", TRUE, SVt_PV);
                secondgv = gv_fetchpv("b", TRUE, SVt_PV);
@@ -743,7 +743,7 @@ PP(pp_sort)
            qsortsv((myorigmark+1), max, FUNC_NAME_TO_PTR(sortcv));
 
            POPBLOCK(cx,curpm);
-           POPSTACK();
+           POPSTACK;
            CATCH_SET(oldcatch);
        }
     }
@@ -1076,7 +1076,7 @@ die_where(char *message)
 
        while ((cxix = dopoptoeval(cxstack_ix)) < 0 && curstackinfo->si_prev) {
            dounwind(-1);
-           POPSTACK();
+           POPSTACK;
        }
 
        if (cxix >= 0) {
index df2b7ae..6fb7cb5 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -554,7 +554,7 @@ PP(pp_tie)
     items = SP - MARK++;
     if (sv_isobject(*MARK)) {
        ENTER;
-       PUSHSTACK(SI_MAGIC);
+       PUSHSTACKi(SI_MAGIC);
        PUSHMARK(SP);
        EXTEND(SP,items);
        while (items--)
@@ -572,7 +572,7 @@ PP(pp_tie)
                 methname, SvPV(*MARK,na));                   
        }
        ENTER;
-       PUSHSTACK(SI_MAGIC);
+       PUSHSTACKi(SI_MAGIC);
        PUSHMARK(SP);
        EXTEND(SP,items);
        while (items--)
@@ -583,7 +583,7 @@ PP(pp_tie)
     SPAGAIN;
 
     sv = TOPs;
-    POPSTACK();
+    POPSTACK;
     if (sv_isobject(sv)) {
        sv_unmagic(varsv, how);            
        sv_magic(varsv, sv, how, Nullch, 0);
diff --git a/sv.c b/sv.c
index 8b0ce6d..94fb230 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -2799,7 +2799,7 @@ sv_clear(register SV *sv)
                destructor = gv_fetchmethod(SvSTASH(sv), "DESTROY");
                if (destructor) {
                    ENTER;
-                   PUSHSTACK(SI_DESTROY);
+                   PUSHSTACKi(SI_DESTROY);
                    SvRV(&tmpref) = SvREFCNT_inc(sv);
                    EXTEND(SP, 2);
                    PUSHMARK(SP);
@@ -2808,7 +2808,7 @@ sv_clear(register SV *sv)
                    perl_call_sv((SV*)GvCV(destructor),
                                 G_DISCARD|G_EVAL|G_KEEPERR);
                    SvREFCNT(sv)--;
-                   POPSTACK();
+                   POPSTACK;
                    LEAVE;
                }
            } while (SvOBJECT(sv) && SvSTASH(sv) != stash);
diff --git a/util.c b/util.c
index 7a173ee..f61b66d 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1289,12 +1289,12 @@ die(const char* pat, ...)
                msg = ERRSV;
            }
 
-           PUSHSTACK(SI_DIEHOOK);
+           PUSHSTACKi(SI_DIEHOOK);
            PUSHMARK(SP);
            XPUSHs(msg);
            PUTBACK;
            perl_call_sv((SV*)cv, G_DISCARD);
-           POPSTACK();
+           POPSTACK;
            LEAVE;
        }
     }
@@ -1343,12 +1343,12 @@ croak(const char* pat, ...)
            SvREADONLY_on(msg);
            SAVEFREESV(msg);
 
-           PUSHSTACK(SI_DIEHOOK);
+           PUSHSTACKi(SI_DIEHOOK);
            PUSHMARK(SP);
            XPUSHs(msg);
            PUTBACK;
            perl_call_sv((SV*)cv, G_DISCARD);
-           POPSTACK();
+           POPSTACK;
            LEAVE;
        }
     }
@@ -1392,12 +1392,12 @@ warn(const char* pat,...)
            SvREADONLY_on(msg);
            SAVEFREESV(msg);
 
-           PUSHSTACK(SI_WARNHOOK);
+           PUSHSTACKi(SI_WARNHOOK);
            PUSHMARK(SP);
            XPUSHs(msg);
            PUTBACK;
            perl_call_sv((SV*)cv, G_DISCARD);
-           POPSTACK();
+           POPSTACK;
            LEAVE;
            return;
        }