]> git.vpit.fr Git - perl/modules/Lexical-Types.git/commitdiff
Do nothing after that the thread local storage has been freed
authorVincent Pit <vince@profvince.com>
Sat, 4 Oct 2014 22:54:33 +0000 (00:54 +0200)
committerVincent Pit <vince@profvince.com>
Sat, 4 Oct 2014 22:54:33 +0000 (00:54 +0200)
This de facto disables the pragma for code eval'd during global
destruction of a thread or a pseudo-fork.

Types.xs
lib/Lexical/Types.pm
t/81-threads-teardown.t

index 752e3f43d27aab4f5b1de8a8c59d1e70ab91f220..d37cdc7eabb0e5a311b0e9e6701e81e0dee0fdb6 100644 (file)
--- a/Types.xs
+++ b/Types.xs
@@ -348,7 +348,13 @@ get_enclosing_cv:
 STATIC SV *lt_tag(pTHX_ SV *value) {
 #define lt_tag(V) lt_tag(aTHX_ (V))
  lt_hint_t *h;
 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);
 
  if (SvROK(value)) {
   value = SvRV(value);
@@ -369,13 +375,10 @@ STATIC SV *lt_tag(pTHX_ SV *value) {
 #endif /* !LT_HINT_STRUCT */
 
 #if LT_THREADSAFE
 #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));
 #endif /* LT_THREADSAFE */
 
  return newSViv(PTR2IV(h));
@@ -386,7 +389,10 @@ STATIC SV *lt_detag(pTHX_ const SV *hint) {
  lt_hint_t *h;
 #if LT_THREADSAFE
  dMY_CXT;
  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 (!(hint && SvIOK(hint)))
   return NULL;
@@ -710,7 +716,7 @@ STATIC OP *lt_ck_padany(pTHX_ OP *o) {
  if (stash && (code = lt_hint())) {
   dMY_CXT;
   SV *orig_pkg  = newSVpvn(HvNAME_get(stash), HvNAMELEN_get(stash));
  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;
   SV *type_pkg  = NULL;
   SV *type_meth = NULL;
   int items;
@@ -914,9 +920,11 @@ STATIC void lt_peep(pTHX_ OP *o) {
 
  lt_old_peep(aTHX_ o);
 
 
  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 ------------------------------------------ */
 }
 
 /* --- Interpreter setup/teardown ------------------------------------------ */
index 88b00afdf6073d65b746e67d7a9af0a0fc5b8f05..518e20522e776bc48e8c73def5b1c8685d49c0ad 100644 (file)
@@ -269,6 +269,8 @@ The restrictions on the type (being either a defined package name or a constant)
 
 Only one mangler or prefix can be in use at the same time in a given scope.
 
 
 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>.
 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>.
index c60e14f1aa1695f0d3c4b01b8b7dacd8c3913e45..7a5c2270268a3df0b335a154fc532d4b3a872bb9 100644 (file)
@@ -7,7 +7,7 @@ use lib 't/lib';
 use VPIT::TestHelpers;
 use Lexical::Types::TestThreads;
 
 use VPIT::TestHelpers;
 use Lexical::Types::TestThreads;
 
-use Test::More tests => 1;
+use Test::More tests => 2;
 
 {
  my $status = run_perl <<' RUN';
 
 {
  my $status = run_perl <<' RUN';
@@ -32,3 +32,21 @@ use Test::More tests => 1;
  RUN
  is $status, 0, 'loading the pragma in a thread and using it outside doesn\'t segfault';
 }
  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';
+}