]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blobdiff - Upper.xs
A somewhat more robust handling of debugging frames
[perl/modules/Scope-Upper.git] / Upper.xs
index 89083850cd9209579c880f9bade1d22e89bfbb74..42f457e4302a5f46294c457612e79477aafb1634 100644 (file)
--- a/Upper.xs
+++ b/Upper.xs
 # define SvPV_nolen_const(S) SvPV_nolen(S)
 #endif
 
+#ifndef SvREFCNT_inc_simple_void
+# define SvREFCNT_inc_simple_void(sv) SvREFCNT_inc(sv)
+#endif
+
 #ifndef HvNAME_get
 # define HvNAME_get(H) HvNAME(H)
 #endif
@@ -176,7 +180,7 @@ STATIC void su_save_adelete(pTHX_ AV *av, I32 idx) {
  Newx(ud, 1, su_ud_adelete);
  ud->av  = av;
  ud->idx = idx;
- SvREFCNT_inc(av);
+ SvREFCNT_inc_simple_void(av);
 
  SAVEDESTRUCTOR_X(su_adelete, ud);
 }
@@ -352,7 +356,7 @@ STATIC void su_ud_localize_init(pTHX_ su_ud_localize *ud, SV *sv, SV *val, SV *e
  UV deref = 0;
  svtype t = SVt_NULL;
 
- SvREFCNT_inc(sv);
+ SvREFCNT_inc_simple_void(sv);
 
  if (SvTYPE(sv) >= SVt_PVGV) {
   if (!val || !SvROK(val)) { /* local *x; or local *x = $val; */
@@ -397,6 +401,7 @@ STATIC void su_ud_localize_init(pTHX_ su_ud_localize *ud, SV *sv, SV *val, SV *e
   case SVt_PVCV:
   case SVt_PVGV:
    deref = 0;
+  default:
    break;
  }
  /* When deref is set, val isn't NULL */
@@ -701,18 +706,21 @@ STATIC void su_unwind(pTHX_ void *ud_) {
 
 #define SU_SKIP_DB(C) \
  STMT_START {         \
-  I32 i = 1;          \
-  PERL_CONTEXT *cx = cxstack + (C); \
-  do {                              \
-   if (CxTYPE(cx) == CXt_BLOCK && (C) >= i) { \
-    --cx;                                     \
-    if (CxTYPE(cx) == CXt_SUB && cx->blk_sub.cv == GvCV(PL_DBsub)) { \
-     (C) -= i + 1;                 \
-     break;                        \
-    }                              \
-   } else                          \
-    break;                         \
-  } while (++i <= SU_SKIP_DB_MAX); \
+  I32 skipped = 0;    \
+  PERL_CONTEXT *base = cxstack;      \
+  PERL_CONTEXT *cx   = base + (C);   \
+  while (cx >= base && (C) > skipped && CxTYPE(cx) == CXt_BLOCK) \
+   --cx, ++skipped;                  \
+  if (cx >= base && (C) > skipped) { \
+   switch (CxTYPE(cx)) {  \
+    case CXt_SUB:         \
+     if (skipped <= SU_SKIP_DB_MAX && cx->blk_sub.cv == GvCV(PL_DBsub)) \
+      (C) -= skipped + 1; \
+      break;              \
+    default:              \
+     break;               \
+   }                      \
+  }                       \
  } STMT_END
 
 #define SU_GET_CONTEXT(A, B)   \