]> git.vpit.fr Git - perl/modules/Variable-Magic.git/commitdiff
Empty the global pointer table at the end of a thread
authorVincent Pit <vince@profvince.com>
Thu, 26 Nov 2009 21:10:19 +0000 (22:10 +0100)
committerVincent Pit <vince@profvince.com>
Thu, 26 Nov 2009 21:10:19 +0000 (22:10 +0100)
Magic.xs

index 5a46c641761e3b63afc1c369b3b91ade09b0502e..caff817b84c869d0d76fd6a63c9e0e9fe7c8d4f8 100644 (file)
--- a/Magic.xs
+++ b/Magic.xs
@@ -490,6 +490,22 @@ STATIC void vmg_ptable_clone(pTHX_ ptable_ent *ent, void *ud_) {
   ptable_store(ud->wizards, ent->key, w);
 }
 
+STATIC void vmg_thread_cleanup(pTHX_ void *);
+
+STATIC void vmg_thread_cleanup(pTHX_ void *ud) {
+ int *level = ud;
+
+ if (*level) {
+  --*level;
+  LEAVE;
+  SAVEDESTRUCTOR_X(vmg_thread_cleanup, level);
+  ENTER;
+ } else {
+  dMY_CXT;
+  PerlMemShared_free(level);
+  ptable_free(MY_CXT.wizards);
+ }
+}
 #endif /* VMG_THREADSAFE */
 
 /* --- Wizard objects ------------------------------------------------------ */
@@ -1294,7 +1310,6 @@ CLONE(...)
 PROTOTYPE: DISABLE
 PREINIT:
  ptable *t;
- int    *level;
  U32     had_b__op_stash = 0;
  opclass c;
 PPCODE:
@@ -1320,6 +1335,14 @@ PPCODE:
                               ? gv_stashpv(vmg_opclassnames[c], 1) : NULL;
   }
  }
+ {
+  int *level;
+  level = PerlMemShared_malloc(sizeof *level);
+  *level = 1;
+  LEAVE;
+  SAVEDESTRUCTOR_X(vmg_thread_cleanup, level);
+  ENTER;
+ }
  XSRETURN(0);
 
 #endif /* VMG_THREADSAFE */