]> git.vpit.fr Git - perl/modules/indirect.git/blobdiff - indirect.xs
Make sure MULTIPLICITY builds set PERL_IMPLICIT_CONTEXT
[perl/modules/indirect.git] / indirect.xs
index 57a0ea79dbf1289a8a756d6e70420c5161403176..d8e7d0deb9d21ebc25cbfa683a86c84e9db71af8 100644 (file)
 #endif
 
 #ifndef I_MULTIPLICITY
-# if defined(MULTIPLICITY) || defined(PERL_IMPLICIT_CONTEXT)
+# if defined(MULTIPLICITY)
 #  define I_MULTIPLICITY 1
 # else
 #  define I_MULTIPLICITY 0
 # endif
 #endif
+#if I_MULTIPLICITY
+# ifndef PERL_IMPLICIT_CONTEXT
+#  error MULTIPLICITY builds must set PERL_IMPLICIT_CONTEXT
+# endif
+#endif
 #if I_MULTIPLICITY && !defined(tTHX)
 # define tTHX PerlInterpreter*
 #endif
@@ -468,7 +473,7 @@ static SV *indirect_detag(pTHX_ const SV *hint) {
  return I_HINT_CODE(h);
 }
 
-static U32 indirect_hash = 0;
+static VOL U32 indirect_hash = 0;
 
 static SV *indirect_hint(pTHX) {
 #define indirect_hint() indirect_hint(aTHX)
@@ -933,9 +938,11 @@ done:
  return o;
 }
 
-static U32 indirect_initialized = 0;
+/* --- Global setup/teardown ------------------------------------------------ */
 
-static void indirect_teardown(pTHX_ void *root) {
+static VOL U32 indirect_initialized = 0;
+
+static void indirect_global_teardown(pTHX_ void *root) {
  if (!indirect_initialized)
   return;
 
@@ -944,16 +951,6 @@ static void indirect_teardown(pTHX_ void *root) {
   return;
 #endif
 
- {
-  dMY_CXT;
-  ptable_free(MY_CXT.map);
-  MY_CXT.map = NULL;
-#if I_THREADSAFE
-  ptable_hints_free(MY_CXT.tbl);
-  MY_CXT.tbl = NULL;
-#endif
- }
-
  indirect_ck_restore(OP_CONST,   &indirect_old_ck_const);
  indirect_ck_restore(OP_RV2SV,   &indirect_old_ck_rv2sv);
  indirect_ck_restore(OP_PADANY,  &indirect_old_ck_padany);
@@ -965,22 +962,22 @@ static void indirect_teardown(pTHX_ void *root) {
  indirect_ck_restore(OP_ENTERSUB,     &indirect_old_ck_entersub);
 
  indirect_initialized = 0;
+
+ return;
 }
 
-static void indirect_setup(pTHX) {
-#define indirect_setup() indirect_setup(aTHX)
+static void indirect_global_setup(pTHX) {
+#define indirect_global_setup() indirect_global_setup(aTHX)
+ HV *stash;
+
  if (indirect_initialized)
   return;
 
- {
-  MY_CXT_INIT;
-#if I_THREADSAFE
-  MY_CXT.tbl         = ptable_new();
-  MY_CXT.owner       = aTHX;
-#endif
-  MY_CXT.map         = ptable_new();
-  MY_CXT.global_code = NULL;
- }
+ PERL_HASH(indirect_hash, __PACKAGE__, __PACKAGE_LEN__);
+
+ stash = gv_stashpvn(__PACKAGE__, __PACKAGE_LEN__, 1);
+ newCONSTSUB(stash, "I_THREADSAFE", newSVuv(I_THREADSAFE));
+ newCONSTSUB(stash, "I_FORKSAFE",   newSVuv(I_FORKSAFE));
 
  indirect_ck_replace(OP_CONST,   indirect_ck_const,  &indirect_old_ck_const);
  indirect_ck_replace(OP_RV2SV,   indirect_ck_rv2sv,  &indirect_old_ck_rv2sv);
@@ -996,15 +993,48 @@ static void indirect_setup(pTHX) {
                                       &indirect_old_ck_entersub);
 
 #if I_MULTIPLICITY
- call_atexit(indirect_teardown, aTHX);
+ call_atexit(indirect_global_teardown, aTHX);
 #else
- call_atexit(indirect_teardown, NULL);
+ call_atexit(indirect_global_teardown, NULL);
 #endif
 
  indirect_initialized = 1;
+
+ return;
 }
 
-static U32 indirect_booted = 0;
+/* --- Interpreter setup/teardown ------------------------------------------ */
+
+static void indirect_local_teardown(pTHX_ void *param) {
+ dMY_CXT;
+
+ ptable_free(MY_CXT.map);
+ MY_CXT.map = NULL;
+
+#if I_THREADSAFE
+ ptable_hints_free(MY_CXT.tbl);
+ MY_CXT.tbl = NULL;
+#endif
+
+ return;
+}
+
+static void indirect_local_setup(pTHX) {
+#define indirect_local_setup() indirect_local_setup(aTHX)
+ MY_CXT_INIT;
+
+#if I_THREADSAFE
+ MY_CXT.tbl         = ptable_new();
+ MY_CXT.owner       = aTHX;
+#endif
+
+ MY_CXT.map         = ptable_new();
+ MY_CXT.global_code = NULL;
+
+ call_atexit(indirect_local_teardown, NULL);
+
+ return;
+}
 
 /* --- XS ------------------------------------------------------------------ */
 
@@ -1014,17 +1044,8 @@ PROTOTYPES: ENABLE
 
 BOOT:
 {
- if (!indirect_booted++) {
-  HV *stash;
-
-  PERL_HASH(indirect_hash, __PACKAGE__, __PACKAGE_LEN__);
-
-  stash = gv_stashpvn(__PACKAGE__, __PACKAGE_LEN__, 1);
-  newCONSTSUB(stash, "I_THREADSAFE", newSVuv(I_THREADSAFE));
-  newCONSTSUB(stash, "I_FORKSAFE",   newSVuv(I_FORKSAFE));
- }
-
- indirect_setup();
+ indirect_global_setup();
+ indirect_local_setup();
 }
 
 #if I_THREADSAFE