This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
eliminate PL_regsize
[perl5.git] / cop.h
diff --git a/cop.h b/cop.h
index 9f3762e..0a682f1 100644 (file)
--- a/cop.h
+++ b/cop.h
@@ -387,7 +387,8 @@ struct cop {
     line_t      cop_line;       /* line # of this command */
     /* label for this construct is now stored in cop_hints_hash */
 #ifdef USE_ITHREADS
-    PADOFFSET  cop_stashoff;   /* package line was compiled in */
+    PADOFFSET  cop_stashoff;   /* offset into PL_stashpad, for the
+                                  package the line was compiled in */
     char *     cop_file;       /* file name the following line # is from */
 #else
     HV *       cop_stash;      /* package line was compiled in */
@@ -419,12 +420,8 @@ struct cop {
                                 ? GvSV(gv_fetchfile(CopFILE(c))) : NULL)
 #  define CopFILEAV(c)         (CopFILE(c) \
                                 ? GvAV(gv_fetchfile(CopFILE(c))) : NULL)
-#  ifdef DEBUGGING
-#    define CopFILEAVx(c)      (assert(CopFILE(c)), \
+#  define CopFILEAVx(c)                (assert_(CopFILE(c)) \
                                   GvAV(gv_fetchfile(CopFILE(c))))
-#  else
-#    define CopFILEAVx(c)      (GvAV(gv_fetchfile(CopFILE(c))))
-#  endif
 
 #  define CopSTASH(c)           PL_stashpad[(c)->cop_stashoff]
 #  define CopSTASH_set(c,hv)   ((c)->cop_stashoff = (hv)               \
@@ -547,7 +544,6 @@ be zero.
 /* OutCopFILE() is CopFILE for output (caller, die, warn, etc.) */
 #define OutCopFILE(c) CopFILE(c)
 
-/* FIXME NATIVE_HINTS if this is changed from op_private (see perl.h)  */
 #define CopHINTS_get(c)                ((c)->cop_hints + 0)
 #define CopHINTS_set(c, h)     STMT_START {                            \
                                    (c)->cop_hints = (h);               \
@@ -626,6 +622,8 @@ struct block_format {
        cx->blk_format.gv = gv;                                         \
        cx->blk_format.retop = (retop);                                 \
        cx->blk_format.dfoutgv = PL_defoutgv;                           \
+       if (!CvDEPTH(cv)) SvREFCNT_inc_simple_void_NN(cv);              \
+       CvDEPTH(cv)++;                                                  \
        SvREFCNT_inc_void(cx->blk_format.dfoutgv)
 
 #define POP_SAVEARRAY()                                                \
@@ -655,7 +653,7 @@ struct block_format {
            /* abandon @_ if it got reified */                          \
            if (AvREAL(cx->blk_sub.argarray)) {                         \
                const SSize_t fill = AvFILLp(cx->blk_sub.argarray);     \
-               SvREFCNT_dec(cx->blk_sub.argarray);                     \
+               SvREFCNT_dec_NN(cx->blk_sub.argarray);                  \
                cx->blk_sub.argarray = newAV();                         \
                av_extend(cx->blk_sub.argarray, fill);                  \
                AvREIFY_only(cx->blk_sub.argarray);                     \
@@ -678,7 +676,10 @@ struct block_format {
 
 #define POPFORMAT(cx)                                                  \
        setdefout(cx->blk_format.dfoutgv);                              \
-       SvREFCNT_dec(cx->blk_format.dfoutgv);
+       CvDEPTH(cx->blk_format.cv)--;                                   \
+       if (!CvDEPTH(cx->blk_format.cv))                                \
+           SvREFCNT_dec_NN(cx->blk_format.cv);                         \
+       SvREFCNT_dec_NN(cx->blk_format.dfoutgv);
 
 /* eval context */
 struct block_eval {
@@ -716,6 +717,8 @@ struct block_eval {
        PL_in_eval = CxOLD_IN_EVAL(cx);                                 \
        optype = CxOLD_OP_TYPE(cx);                                     \
        PL_eval_root = cx->blk_eval.old_eval_root;                      \
+       if (cx->blk_eval.cur_text && SvSCREAM(cx->blk_eval.cur_text))   \
+           SvREFCNT_dec_NN(cx->blk_eval.cur_text);                     \
        if (cx->blk_eval.old_namesv)                                    \
            sv_2mortal(cx->blk_eval.old_namesv);                        \
     } STMT_END
@@ -781,8 +784,8 @@ struct block_loop {
 
 #define POPLOOP(cx)                                                    \
        if (CxTYPE(cx) == CXt_LOOP_LAZYSV) {                            \
-           SvREFCNT_dec(cx->blk_loop.state_u.lazysv.cur);              \
-           SvREFCNT_dec(cx->blk_loop.state_u.lazysv.end);              \
+           SvREFCNT_dec_NN(cx->blk_loop.state_u.lazysv.cur);           \
+           SvREFCNT_dec_NN(cx->blk_loop.state_u.lazysv.end);           \
        }                                                               \
        if (CxTYPE(cx) == CXt_LOOP_FOR)                                 \
            SvREFCNT_dec(cx->blk_loop.state_u.ary.ary);
@@ -1179,10 +1182,16 @@ See L<perlcall/LIGHTWEIGHT CALLBACKS>.
     U8 hasargs = 0             /* used by PUSHSUB */
 
 #define PUSH_MULTICALL(the_cv) \
+    PUSH_MULTICALL_WITHDEPTH(the_cv, 1);
+
+/* Like PUSH_MULTICALL, but allows you to specify the CvDEPTH increment,
+ * rather than the default of 1 (this isn't part of the public API) */
+
+#define PUSH_MULTICALL_WITHDEPTH(the_cv, depth) \
     STMT_START {                                                       \
        CV * const _nOnclAshIngNamE_ = the_cv;                          \
        CV * const cv = _nOnclAshIngNamE_;                              \
-       AV * const padlist = CvPADLIST(cv);                             \
+       PADLIST * const padlist = CvPADLIST(cv);                        \
        ENTER;                                                          \
        multicall_oldcatch = CATCH_GET;                                 \
        SAVETMPS; SAVEVPTR(PL_op);                                      \
@@ -1190,7 +1199,8 @@ See L<perlcall/LIGHTWEIGHT CALLBACKS>.
        PUSHSTACKi(PERLSI_SORT);                                        \
        PUSHBLOCK(cx, CXt_SUB|CXp_MULTICALL, PL_stack_sp);              \
        PUSHSUB(cx);                                                    \
-       if (++CvDEPTH(cv) >= 2) {                                       \
+       CvDEPTH(cv) += depth;                                           \
+       if (CvDEPTH(cv) >= 2) {                                         \
            PERL_STACK_OVERFLOW_CHECK();                                \
            Perl_pad_push(aTHX_ padlist, CvDEPTH(cv));                  \
        }                                                               \
@@ -1208,8 +1218,10 @@ See L<perlcall/LIGHTWEIGHT CALLBACKS>.
 
 #define POP_MULTICALL \
     STMT_START {                                                       \
-       if (! --CvDEPTH(multicall_cv))                                  \
-           LEAVESUB(multicall_cv);                                     \
+       cx = &cxstack[cxstack_ix];                                      \
+        if (! ((CvDEPTH(multicall_cv) = cx->blk_sub.olddepth)) ) {     \
+               LEAVESUB(multicall_cv);                                 \
+       }                                                               \
        POPBLOCK(cx,PL_curpm);                                          \
        POPSTACK;                                                       \
        CATCH_SET(multicall_oldcatch);                                  \
@@ -1217,6 +1229,31 @@ See L<perlcall/LIGHTWEIGHT CALLBACKS>.
        SPAGAIN;                                                        \
     } STMT_END
 
+/* Change the CV of an already-pushed MULTICALL CxSUB block.
+ * (this isn't part of the public API) */
+
+#define CHANGE_MULTICALL_WITHDEPTH(the_cv, depth) \
+    STMT_START {                                                       \
+       CV * const _nOnclAshIngNamE_ = the_cv;                          \
+       CV * const cv = _nOnclAshIngNamE_;                              \
+       PADLIST * const padlist = CvPADLIST(cv);                        \
+       cx = &cxstack[cxstack_ix];                                      \
+       assert(cx->cx_type & CXp_MULTICALL);                            \
+       if (! ((CvDEPTH(multicall_cv) = cx->blk_sub.olddepth)) ) {      \
+               LEAVESUB(multicall_cv);                                 \
+       }                                                               \
+       cx->cx_type &= ~CXp_HASARGS;                                    \
+       PUSHSUB(cx);                                                    \
+       CvDEPTH(cv) += depth;                                           \
+       if (CvDEPTH(cv) >= 2) {                                         \
+           PERL_STACK_OVERFLOW_CHECK();                                \
+           Perl_pad_push(aTHX_ padlist, CvDEPTH(cv));                  \
+       }                                                               \
+       SAVECOMPPAD();                                                  \
+       PAD_SET_CUR_NOSAVE(padlist, CvDEPTH(cv));                       \
+       multicall_cv = cv;                                              \
+       multicall_cop = CvSTART(cv);                                    \
+    } STMT_END
 /*
  * Local variables:
  * c-indentation-style: bsd