X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=indirect.xs;h=fd742ebf9cac5c72a1402df39a04e544b8d2a80c;hb=b5c134ab71c3f931cc2c9b55eb69b44ced87e46e;hp=57a0ea79dbf1289a8a756d6e70420c5161403176;hpb=461d68367d0b993e2dcbb87f1bf5b850c73c1232;p=perl%2Fmodules%2Findirect.git diff --git a/indirect.xs b/indirect.xs index 57a0ea7..fd742eb 100644 --- a/indirect.xs +++ b/indirect.xs @@ -468,7 +468,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 +933,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 +946,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 +957,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 +988,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; +} + +/* --- 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 U32 indirect_booted = 0; +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 +1039,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