
Tim.Bunce at pobox
Nov 10, 2009, 8:16 AM
Post #30 of 30
(39 views)
Permalink
|
|
Re: [perl #60374] Safe.pm sort {} bug with -Dusethreads
[In reply to]
|
|
On Tue, Nov 10, 2009 at 02:56:36PM +0000, Nicholas Clark wrote: > > > > http://rt.perl.org/rt3/Public/Bug/Display.html?id=60374#txn-491794 says > > "pp_sort uses CopSTASH(PL_curcop) to get the package stash (symbol > > table) in order to locate the $a and $b variables in it." > > > > While pp_sort does call CopSTASH(PL_curcop) directly, all it does with > > it is store the value in PL_sortstash which, as far as I can tell, isn't > > used or documented anywhere at all. (It could possibly be deleted.) > > > > The code to lookup the $a and $b uses: > > PL_firstgv = gv_fetchpvs("a", GV_ADD|GV_NOTQUAL, SVt_PV); > > PL_secondgv = gv_fetchpvs("b", GV_ADD|GV_NOTQUAL, SVt_PV); > > and it's Perl_gv_fetchpvn_flags that ends up calling CopSTASH(PL_curcop). > > > > If there was a way to get the stash pointer (not name) that was in > > effect at the time the code was compiled we could use that to lookup $a > > and $b. > > The logical way to do this would be to indirect via an entry in the > subroutine's pad, as the reference would be correctly translated by the > ithreads clone code. This probably isn't *trivial* to implement, as a > subroutine can contain code compiled in more than one package, but I think* > it would be viable at compile time to loop up/store if not there yet, the > stash pointer, under the stash's name. > > > There are stash pointers, er, stashed in lots of places. > > One approach might be CvSTASH(find_runcv(...)) > > I think that that doesn't cope with > > package foo; > sub bar { > # here package is foo > package baz; > # here package is baz > } I couldn't get it to work even without that (but trying to follow the inside-safe vs outside-safe and compile-time vs run-time intricacies made my rusty old head spin, so I could have done something silly). Alex's approach, of arranging to execute the closure 'inside' the compartment, seems like a good idea from a 'safety' point of view anyway. The fact it works around the bug is a bonus. On the other hand, the fact it costs two extra sub calls is unfortunate. I tried to look for a way to the PL_defstash switch into pp_entersub but couldn't see a viable approach. > * I think. I don't know this stuff well. Me neither. It's been many years since I helped develop Opcode and Safe. (I recall refering to Safe as a "failed experiment" more than once.) Tim.
|