develooper Front page | perl.perl5.porters | Postings from March 2012

[perl #112104] die($object) in thread reblesses $object into main and breaks stringification

Thread Next
From:
Father Chrysostomos via RT
Date:
March 29, 2012 16:06
Subject:
[perl #112104] die($object) in thread reblesses $object into main and breaks stringification
Message ID:
rt-3.6.HEAD-4610-1333062359-862.112104-15-0@perl.org
On Thu Mar 29 02:52:26 2012, lasse.makholm@gmail.com wrote:
> This is a bug report for perl from lasse.makholm@gmail.com,
> generated with the help of perlbug 1.39 running under perl 5.15.9.
> 
> 
> -----------------------------------------------------------------
> 
> When passing an object to die() in a thread, the object gets
> reblessed into main before the thread termination warning is
> printed. This breaks exception stringification:
> 
> $ perl -e 'use threads; $t = threads->create(sub { die bless {}, "Foo"
> }); $t->join'
> Thread 1 terminated abnormally: main=HASH(0x1576a48) at -e line 1.
> $
> 
> The exception is cloned correctly into the main thread though:
> 
> $ perl -e 'use threads; $t = threads->create(sub { die bless {}, "Foo"
> }); $t->join; die $t->error'
> Thread 1 terminated abnormally: main=HASH(0x10b7d00) at -e line 1.
> Foo=HASH(0xfb7f90)
> $
> 
> I haven't been able to find any mentioning of this issue anywhere
> but snooping around the source seems to indicate that this
> behaviour has been around since perl-5.8.0-9301-g955c272.
> 
> The culprit is in threads.xs:
> 
>             /* If ERRSV is an object, remember the classname and then
>              * rebless into 'main' so it will survive 'cloning'
>              */
>             if (sv_isobject(thread->err)) {
>                 thread->err_class = HvNAME(SvSTASH(SvRV(thread-
> >err)));
>                 sv_bless(thread->err, gv_stashpv("main", 0));
>             }
> 
> ...but that was added for a reason it seems. I'm not sure what
> the appropriate fix should be.

This appears to be a 5.8.9 regression:

$ perl5.8.8 -e 'use threads; $t = threads->create(sub { die bless {}, "Foo"
}); $t->join'
thread failed to start: Foo=HASH(0x87242c) at -e line 2.
$ perl5.8.9 -e 'use threads; $t = threads->create(sub { die bless {}, "Foo"
}); $t->join'
Thread 1 terminated abnormally: main=HASH(0x87fdac) at -e line 2.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=112104

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About