From: gfx Date: Wed, 21 Apr 2010 04:26:26 +0000 (+0900) Subject: Workaround a bug with threads. cleaning stash with threads can cause panic or SEGV. X-Git-Tag: 0.55~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=20a12328ad6513c41ba0856f5d8d95aba672165b;p=gitmo%2FMouse.git Workaround a bug with threads. cleaning stash with threads can cause panic or SEGV. --- diff --git a/lib/Mouse/Meta/Module.pm b/lib/Mouse/Meta/Module.pm index b1b7ab6..4e0cfa8 100755 --- a/lib/Mouse/Meta/Module.pm +++ b/lib/Mouse/Meta/Module.pm @@ -283,6 +283,13 @@ sub DESTROY{ return if !$serial_id; # mortal anonymous class + # XXX: cleaning stash with threads causes panic/SEGV. + if(exists $INC{'threads.pm'}) { + # (caller)[2] indicates the caller's line number, + # which is zero when the current thread is joining. + return if( (caller)[2] == 0); + } + # @ISA is a magical variable, so we clear it manually. @{$self->{superclasses}} = () if exists $self->{superclasses}; @@ -293,7 +300,6 @@ sub DESTROY{ delete $METAS{$name}; $name =~ s/ $serial_id \z//xms; - no strict 'refs'; delete ${$name}{ $serial_id . '::' }; diff --git a/t/001_mouse/060-threads.t b/t/001_mouse/060-threads.t index 06748db..e82f7c5 100644 --- a/t/001_mouse/060-threads.t +++ b/t/001_mouse/060-threads.t @@ -3,9 +3,13 @@ use strict; use warnings; use constant HAS_THREADS => eval{ require threads }; -use Test::More HAS_THREADS ? (tests => 6) : (skip_all => "This is a test for threads ($@)"); +use if !HAS_THREADS, 'Test::More', (skip_all => "This is a test for threads ($@)"); +use Test::More; { + package MyTraits; + use Mouse::Role; + package MyClass; use Mouse; @@ -19,6 +23,9 @@ use Test::More HAS_THREADS ? (tests => 6) : (skip_all => "This is a test for thr has value => ( is => 'rw', + isa => 'Int', + + traits => [qw(MyTraits)], ); } @@ -42,5 +49,10 @@ threads->create(sub{ })->join(); is $o->foo->value, 42; + +$o = MyClass->new(foo => Foo->new(value => 43)); +is $o->foo->value, 43; + ok !$o->meta->is_immutable; +done_testing;