# define SvREFCNT_inc_simple_NN SvREFCNT_inc
#endif
+#ifndef ENTER_with_name
+# define ENTER_with_name(N) ENTER
+#endif
+
+#ifndef LEAVE_with_name
+# define LEAVE_with_name(N) LEAVE
+#endif
+
/* ... Thread safety and multiplicity ...................................... */
#ifndef LT_MULTIPLICITY
typedef struct {
SV *code;
- UV requires;
+ IV cxreq;
} lt_hint_t;
#define LT_HINT_STRUCT 1
#if LT_HINT_STRUCT
- h2 = PerlMemShared_malloc(sizeof *h2);
- h2->code = lt_clone(h1->code, ud->owner);
+ h2 = PerlMemShared_malloc(sizeof *h2);
+ h2->code = lt_clone(h1->code, ud->owner);
SvREFCNT_inc(h2->code);
#if LT_WORKAROUND_REQUIRE_PROPAGATION
- h2->requires = h1->requires;
+ h2->cxreq = h1->cxreq;
#endif
#else /* LT_HINT_STRUCT */
/* ... Hint tags ........................................................... */
+#if LT_WORKAROUND_REQUIRE_PROPAGATION
+STATIC IV lt_require_tag(pTHX) {
+#define lt_require_tag() lt_require_tag(aTHX)
+ const PERL_SI *si;
+
+ for (si = PL_curstackinfo; si; si = si->si_prev) {
+ I32 cxix;
+
+ for (cxix = si->si_cxix; cxix >= 0; --cxix) {
+ const PERL_CONTEXT *cx = si->si_cxstack + cxix;
+
+ if (CxTYPE(cx) == CXt_EVAL && cx->blk_eval.old_op_type == OP_REQUIRE)
+ return PTR2IV(cx);
+ }
+ }
+
+ return PTR2IV(NULL);
+}
+#endif /* LT_WORKAROUND_REQUIRE_PROPAGATION */
+
STATIC SV *lt_tag(pTHX_ SV *value) {
#define lt_tag(V) lt_tag(aTHX_ (V))
lt_hint_t *h;
#if LT_HINT_STRUCT
h = PerlMemShared_malloc(sizeof *h);
- h->code = code;
-
-#if LT_WORKAROUND_REQUIRE_PROPAGATION
- {
- const PERL_SI *si;
- I32 requires = 0;
-
- for (si = PL_curstackinfo; si; si = si->si_prev) {
- I32 cxix;
-
- for (cxix = si->si_cxix; cxix >= 0; --cxix) {
- const PERL_CONTEXT *cx = si->si_cxstack + cxix;
-
- if (CxTYPE(cx) == CXt_EVAL && cx->blk_eval.old_op_type == OP_REQUIRE)
- ++requires;
- }
- }
-
- h->requires = requires;
- }
-#endif /* LT_WORKAROUND_REQUIRE_PROPAGATION */
-
+ h->code = code;
+# if LT_WORKAROUND_REQUIRE_PROPAGATION
+ h->cxreq = lt_require_tag();
+# endif /* LT_WORKAROUND_REQUIRE_PROPAGATION */
#else /* LT_HINT_STRUCT */
h = code;
#endif /* !LT_HINT_STRUCT */
#if LT_THREADSAFE
h = ptable_fetch(MY_CXT.tbl, h);
#endif /* LT_THREADSAFE */
-
#if LT_WORKAROUND_REQUIRE_PROPAGATION
- {
- const PERL_SI *si;
- I32 requires = 0;
-
- for (si = PL_curstackinfo; si; si = si->si_prev) {
- I32 cxix;
-
- for (cxix = si->si_cxix; cxix >= 0; --cxix) {
- const PERL_CONTEXT *cx = si->si_cxstack + cxix;
-
- if (CxTYPE(cx) == CXt_EVAL && cx->blk_eval.old_op_type == OP_REQUIRE
- && ++requires > h->requires)
- return NULL;
- }
- }
- }
+ if (lt_require_tag() != h->cxreq)
+ return NULL;
#endif /* LT_WORKAROUND_REQUIRE_PROPAGATION */
return LT_HINT_CODE(h);
STATIC U32 lt_initialized = 0;
+STATIC void lt_teardown(pTHX_ void *root) {
+ dMY_CXT;
+
+ if (!lt_initialized)
+ return;
+
+#if LT_MULTIPLICITY
+ if (aTHX != root)
+ return;
+#endif
+
+#if LT_THREADSAFE
+ ptable_hints_free(MY_CXT.tbl);
+#endif
+ SvREFCNT_dec(MY_CXT.default_meth);
+
+ PL_check[OP_PADANY] = MEMBER_TO_FPTR(lt_old_ck_padany);
+ lt_old_ck_padany = 0;
+ PL_check[OP_PADSV] = MEMBER_TO_FPTR(lt_old_ck_padsv);
+ lt_old_ck_padsv = 0;
+
+ lt_initialized = 0;
+}
+
+STATIC lt_setup(pTHX) {
+#define lt_setup() lt_setup(aTHX)
+ if (lt_initialized)
+ return;
+
+ MY_CXT_INIT;
+#if LT_THREADSAFE
+ MY_CXT.tbl = ptable_new();
+ MY_CXT.owner = aTHX;
+#endif
+ MY_CXT.pp_padsv_saved = 0;
+ MY_CXT.default_meth = newSVpvn("TYPEDSCALAR", 11);
+ SvREADONLY_on(MY_CXT.default_meth);
+
+ lt_old_ck_padany = PL_check[OP_PADANY];
+ PL_check[OP_PADANY] = MEMBER_TO_FPTR(lt_ck_padany);
+ lt_old_ck_padsv = PL_check[OP_PADSV];
+ PL_check[OP_PADSV] = MEMBER_TO_FPTR(lt_ck_padsv);
+
+#if LT_MULTIPLICITY
+ call_atexit(lt_teardown, aTHX);
+#else
+ call_atexit(lt_teardown, NULL);
+#endif
+
+ lt_initialized = 1;
+}
+
+STATIC U32 lt_booted = 0;
+
/* --- XS ------------------------------------------------------------------ */
MODULE = Lexical::Types PACKAGE = Lexical::Types
BOOT:
{
- if (!lt_initialized++) {
+ if (!lt_booted++) {
HV *stash;
- MY_CXT_INIT;
-#if LT_THREADSAFE
- MY_CXT.tbl = ptable_new();
- MY_CXT.owner = aTHX;
-#endif
- MY_CXT.pp_padsv_saved = 0;
- MY_CXT.default_meth = newSVpvn("TYPEDSCALAR", 11);
- SvREADONLY_on(MY_CXT.default_meth);
-
lt_op_map = ptable_new();
#ifdef USE_ITHREADS
MUTEX_INIT(<_op_map_mutex);
PERL_HASH(lt_hash, __PACKAGE__, __PACKAGE_LEN__);
- lt_old_ck_padany = PL_check[OP_PADANY];
- PL_check[OP_PADANY] = MEMBER_TO_FPTR(lt_ck_padany);
- lt_old_ck_padsv = PL_check[OP_PADSV];
- PL_check[OP_PADSV] = MEMBER_TO_FPTR(lt_ck_padsv);
-
stash = gv_stashpvn(__PACKAGE__, __PACKAGE_LEN__, 1);
newCONSTSUB(stash, "LT_THREADSAFE", newSVuv(LT_THREADSAFE));
}
+
+ lt_setup();
}
#if LT_THREADSAFE
{
level = PerlMemShared_malloc(sizeof *level);
*level = 1;
- LEAVE;
+ LEAVE_with_name("sub");
SAVEDESTRUCTOR_X(lt_thread_cleanup, level);
- ENTER;
+ ENTER_with_name("sub");
}
#endif