This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Tie::Hash::NamedCapture::* shouldn't abort if passed bad input [RT #71828]
[perl5.git] / scope.h
diff --git a/scope.h b/scope.h
index fc639af..64e7e27 100644 (file)
--- a/scope.h
+++ b/scope.h
 #define SAVEt_COMPILE_WARNINGS 43
 #define SAVEt_STACK_CXPOS      44
 #define SAVEt_PARSER           45
+#define SAVEt_ADELETE          46
 
 #define SAVEf_SETMAGIC         1
+#define SAVEf_KEEPOLDELEM      2
 
+#define save_aelem(av,idx,sptr)        save_aelem_flags(av,idx,sptr,SAVEf_SETMAGIC)
 #define save_helem(hv,key,sptr)        save_helem_flags(hv,key,sptr,SAVEf_SETMAGIC)
 
 #ifndef SCOPE_SAVES_SIGNAL_MASK
@@ -97,6 +100,20 @@ Opening bracket on a callback.  See C<LEAVE> and L<perlcall>.
 =for apidoc Ams||LEAVE
 Closing bracket on a callback.  See C<ENTER> and L<perlcall>.
 
+=over
+
+=item ENTER_with_name(name)
+
+Same as C<ENTER>, but when debugging is enabled it also associates the
+given literal string with the new scope.
+
+=item LEAVE_with_name(name)
+
+Same as C<LEAVE>, but when debugging is enabled it first checks that the
+scope has the given name. Name must be a literal string.
+
+=back
+
 =cut
 */
 
@@ -114,9 +131,28 @@ Closing bracket on a callback.  See C<ENTER> and L<perlcall>.
        DEBUG_SCOPE("LEAVE")                                    \
        pop_scope();                                            \
     } STMT_END
+#define ENTER_with_name(name)                                          \
+    STMT_START {                                                       \
+       push_scope();                                                   \
+       if (PL_scopestack_name)                                         \
+           PL_scopestack_name[PL_scopestack_ix-1] = name;              \
+       DEBUG_SCOPE("ENTER \"" name "\"")                               \
+    } STMT_END
+#define LEAVE_with_name(name)                                          \
+    STMT_START {                                                       \
+       DEBUG_SCOPE("LEAVE \"" name "\"")                               \
+       if (PL_scopestack_name) {                                       \
+           assert(((char*)PL_scopestack_name[PL_scopestack_ix-1]       \
+                       == (char*)name)                                 \
+                   || strEQ(PL_scopestack_name[PL_scopestack_ix-1], name));        \
+       }                                                               \
+       pop_scope();                                                    \
+    } STMT_END
 #else
 #define ENTER push_scope()
 #define LEAVE pop_scope()
+#define ENTER_with_name(name) ENTER
+#define LEAVE_with_name(name) LEAVE
 #endif
 #define LEAVE_SCOPE(old) if (PL_savestack_ix > old) leave_scope(old)
 
@@ -142,6 +178,10 @@ Closing bracket on a callback.  See C<ENTER> and L<perlcall>.
 #define SAVESETSVFLAGS(sv,mask,val)    save_set_svflags(sv,mask,val)
 #define SAVEDELETE(h,k,l) \
          save_delete(MUTABLE_HV(h), (char*)(k), (I32)(l))
+#define SAVEHDELETE(h,s) \
+         save_hdelete(MUTABLE_HV(h), (s))
+#define SAVEADELETE(a,k) \
+         save_adelete(MUTABLE_AV(a), (I32)(k))
 #define SAVEDESTRUCTOR(f,p) \
          save_destructor((DESTRUCTORFUNC_NOCONTEXT_t)(f), (void*)(p))
 
@@ -157,22 +197,7 @@ Closing bracket on a callback.  See C<ENTER> and L<perlcall>.
 
 #define SAVEOP()       save_op()
 
-#define SAVEHINTS() \
-    STMT_START {                                       \
-       SSCHECK(4);                                     \
-       if (PL_hints & HINT_LOCALIZE_HH) {              \
-           SSPUSHPTR(GvHV(PL_hintgv));                 \
-           GvHV(PL_hintgv) = Perl_hv_copy_hints_hv(aTHX_ GvHV(PL_hintgv)); \
-       }                                               \
-       if (PL_compiling.cop_hints_hash) {              \
-           HINTS_REFCNT_LOCK;                          \
-           PL_compiling.cop_hints_hash->refcounted_he_refcnt++;        \
-           HINTS_REFCNT_UNLOCK;                        \
-       }                                               \
-       SSPUSHPTR(PL_compiling.cop_hints_hash);         \
-       SSPUSHINT(PL_hints);                            \
-       SSPUSHINT(SAVEt_HINTS);                         \
-    } STMT_END
+#define SAVEHINTS()    save_hints()
 
 #define SAVECOMPPAD() save_pushptr(MUTABLE_SV(PL_comppad), SAVEt_COMPPAD)
 
@@ -183,13 +208,7 @@ Closing bracket on a callback.  See C<ENTER> and L<perlcall>.
        PL_curstackinfo->si_stack = (t);                \
     } STMT_END
 
-#define SAVECOPARYBASE(c) \
-    STMT_START {                                       \
-       SSCHECK(3);                                     \
-       SSPUSHINT(CopARYBASE_get(c));                   \
-       SSPUSHPTR(c);                                   \
-       SSPUSHINT(SAVEt_COP_ARYBASE);                   \
-    } STMT_END
+#define SAVECOPARYBASE(c) save_pushi32ptr(CopARYBASE_get(c), c, SAVEt_COP_ARYBASE);
 
 /* Need to do the cop warnings like this, rather than a "SAVEFREESHAREDPV",
    because realloc() means that the value can actually change. Possibly
@@ -236,7 +255,7 @@ Closing bracket on a callback.  See C<ENTER> and L<perlcall>.
 #define SSNEW(size)             Perl_save_alloc(aTHX_ (size), 0)
 #define SSNEWt(n,t)             SSNEW((n)*sizeof(t))
 #define SSNEWa(size,align)     Perl_save_alloc(aTHX_ (size), \
-    (align - ((int)((caddr_t)&PL_savestack[PL_savestack_ix]) % align)) % align)
+    (I32)(align - ((size_t)((caddr_t)&PL_savestack[PL_savestack_ix]) % align)) % align)
 #define SSNEWat(n,t,align)     SSNEWa((n)*sizeof(t), align)
 
 #define SSPTR(off,type)         ((type)  ((char*)PL_savestack + off))