]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blobdiff - Upper.xs
Silence a gcc warning
[perl/modules/Scope-Upper.git] / Upper.xs
index ba8b7b4a53cf5599d9fb561482f42039d60e4514..92f9e65b4f0e09573b28c7dd9e8ab6bf54b44607 100644 (file)
--- a/Upper.xs
+++ b/Upper.xs
@@ -380,6 +380,9 @@ STATIC void su_ud_localize_init(pTHX_ su_ud_localize *ud, SV *sv, SV *val, SV *e
    t = SvTYPE(SvRV(val));
    deref = 1;
   }
+ } else if (SvROK(sv)) {
+  croak("Invalid %s reference as the localization target",
+                 sv_reftype(SvRV(sv), 0));
  } else {
   STRLEN len, l;
   const char *p = SvPV_const(sv, len), *s;
@@ -537,36 +540,22 @@ STATIC void su_pop(pTHX_ void *ud) {
  SU_UD_DEPTH(ud) = --depth;
 
  if (depth > 0) {
-  I32 i = 1, pad;
+  I32 pad;
 
-  if (pad = SU_UD_PAD(ud)) {
+  if ((pad = SU_UD_PAD(ud))) {
    dMY_CXT;
    do {
+    SU_D(PerlIO_printf(Perl_debug_log,
+          "%p: push a pad slot at depth=%2d scope_ix=%2d save_ix=%2d\n",
+           ud,                       depth, PL_scopestack_ix, PL_savestack_ix));
     save_int(&MY_CXT.stack_placeholder);
    } while (--pad);
   }
-  SAVEDESTRUCTOR_X(su_pop, ud);
-
-  /* Skip depths corresponding to scopes for which leave_scope() might not be
-   * called. */
-  while (depth > 1 && PL_scopestack_ix >= i) {
-   I32 j = PL_scopestack[PL_scopestack_ix - i];
-
-   if (j < PL_savestack_ix)
-    break;
-
-   SU_D(PerlIO_printf(Perl_debug_log,
-    "%p: skip scope%*cat depth=%2d scope_ix=%2d new_top=%2d >= cur_base=%2d\n",
-     ud,           6, ' ',   depth, PL_scopestack_ix - i, j, PL_savestack_ix));
-
-   SU_UD_DEPTH(ud) = --depth;
-
-   ++i;
-  }
 
   SU_D(PerlIO_printf(Perl_debug_log,
           "%p: push destructor at depth=%2d scope_ix=%2d save_ix=%2d\n",
            ud,                       depth, PL_scopestack_ix, PL_savestack_ix));
+  SAVEDESTRUCTOR_X(su_pop, ud);
  } else {
   SU_UD_HANDLER(ud)(aTHX_ ud);
  }
@@ -1031,11 +1020,17 @@ PREINIT:
  I32 cxix;
  su_ud_localize *ud;
 CODE:
+ if (SvTYPE(sv) >= SVt_PVGV)
+  croak("Can't infer the element localization type from a glob and the value");
  SU_GET_CONTEXT(3, 3);
  Newx(ud, 1, su_ud_localize);
  SU_UD_ORIGIN(ud)  = NULL;
  SU_UD_HANDLER(ud) = su_localize;
  su_ud_localize_init(ud, sv, val, elem);
+ if (ud->type != SVt_PVAV && ud->type != SVt_PVHV) {
+  Safefree(ud);
+  croak("Can't localize an element of something that isn't an array or a hash");
+ }
  su_init(cxix, ud, 4);
 
 void