]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - Magic.xs
Simplify the current temp test in the unmortalizer
[perl/modules/Variable-Magic.git] / Magic.xs
index 0bd0bfd2ba1d45668266d373b0d04f0c4f884abd..858c80fcb3c831bebe0d1f0c70b9241f7b45a771 100644 (file)
--- a/Magic.xs
+++ b/Magic.xs
@@ -1028,8 +1028,16 @@ STATIC int vmg_wizard_free(pTHX_ SV *wiz, MAGIC *mg) {
   if (hv_delete(MY_CXT.wizards, buf, sprintf(buf, "%u", w->sig), 0) != wiz)
    return 0;
  }
- SvFLAGS(wiz) |= SVf_BREAK;
- FREETMPS;
+
+ /* Unmortalize the wizard to avoid it being freed in weird places. */
+ if (SvTEMP(wiz) && !SvREFCNT(wiz)) {
+  const I32 myfloor = PL_tmps_floor;
+  I32 i;
+  for (i = PL_tmps_ix; i > myfloor; --i) {
+   if (PL_tmps_stack[i] == wiz)
+    PL_tmps_stack[i] = NULL;
+  }
+ }
 
  if (w->cb_data)   SvREFCNT_dec(SvRV(w->cb_data));
  if (w->cb_get)    SvREFCNT_dec(SvRV(w->cb_get));