STATIC SV *lt_tag(pTHX_ SV *value) {
#define lt_tag(V) lt_tag(aTHX_ (V))
lt_hint_t *h;
- SV *code = NULL;
+ SV *code = NULL;
+#if LT_THREADSAFE
+ dMY_CXT;
+
+ if (!MY_CXT.tbl)
+ return newSViv(0);
+#endif /* LT_THREADSAFE */
if (SvROK(value)) {
value = SvRV(value);
#endif /* !LT_HINT_STRUCT */
#if LT_THREADSAFE
- {
- dMY_CXT;
- /* We only need for the key to be an unique tag for looking up the value later
- * Allocated memory provides convenient unique identifiers, so that's why we
- * use the hint as the key itself. */
- ptable_hints_store(MY_CXT.tbl, h, h);
- }
+ /* We only need for the key to be an unique tag for looking up the value later
+ * Allocated memory provides convenient unique identifiers, so that's why we
+ * use the hint as the key itself. */
+ ptable_hints_store(MY_CXT.tbl, h, h);
#endif /* LT_THREADSAFE */
return newSViv(PTR2IV(h));
lt_hint_t *h;
#if LT_THREADSAFE
dMY_CXT;
-#endif
+
+ if (!MY_CXT.tbl)
+ return NULL;
+#endif /* LT_THREADSAFE */
if (!(hint && SvIOK(hint)))
return NULL;
if (stash && (code = lt_hint())) {
dMY_CXT;
SV *orig_pkg = newSVpvn(HvNAME_get(stash), HvNAMELEN_get(stash));
- SV *orig_meth = MY_CXT.default_meth;
+ SV *orig_meth = MY_CXT.default_meth; /* Guarded by lt_hint() */
SV *type_pkg = NULL;
SV *type_meth = NULL;
int items;
lt_old_peep(aTHX_ o);
- ptable_seen_clear(seen);
- lt_peep_rec(o);
- ptable_seen_clear(seen);
+ if (seen) {
+ ptable_seen_clear(seen);
+ lt_peep_rec(o);
+ ptable_seen_clear(seen);
+ }
}
/* --- Interpreter setup/teardown ------------------------------------------ */
Only one mangler or prefix can be in use at the same time in a given scope.
+Typed lexicals declarations that appear in code C<eval>'d during the global destruction phase of a spawned thread or pseudo-fork (the processes used internally for the C<fork> emulation on Windows) are ignored.
+
The implementation was tweaked to work around several limitations of vanilla C<perl> pragmas : it's thread safe, and doesn't suffer from a C<perl 5.8.x-5.10.0> bug that causes all pragmas to propagate into C<require>d scopes.
With 5.8 perls, the pragma does not propagate into C<eval STRING>.
use VPIT::TestHelpers;
use Lexical::Types::TestThreads;
-use Test::More tests => 1;
+use Test::More tests => 2;
{
my $status = run_perl <<' RUN';
RUN
is $status, 0, 'loading the pragma in a thread and using it outside doesn\'t segfault';
}
+
+{
+ my $status = run_perl <<' RUN';
+ use threads;
+ BEGIN { require Lexical::Types; }
+ sub X::DESTROY {
+ eval 'use Lexical::Types; package Z; my Z $z = 1';
+ exit 1 if $@;
+ }
+ threads->create(sub {
+ my $x = bless { }, 'X';
+ $x->{self} = $x;
+ return;
+ })->join;
+ exit 0;
+ RUN
+ is $status, 0, 'Lexical::Types can be loaded in eval STRING during global destruction at the end of a thread';
+}