diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-06-04 14:04:03 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-06-04 18:14:53 -0700 |
commit | d4d03940c58a0177edb93c8854929856e9975bf9 (patch) | |
tree | 3852b1f0c210b55ba9172c1edbef3040a6fbae36 /makedef.pl | |
parent | f3ac9fb2631eb3706dcdd2fe0274a953da37486f (diff) | |
download | perl-d4d03940c58a0177edb93c8854929856e9975bf9.tar.gz |
[perl #78742] Store CopSTASH in a pad under threads
Before this commit, a pointer to the cop’s stash was stored in
cop->cop_stash under non-threaded perls, and the name and name length
were stored in cop->cop_stashpv and cop->cop_stashlen under ithreads.
Consequently, eval "__PACKAGE__" would end up returning the
wrong package name under threads if the current package had been
assigned over.
This commit changes the way cops store their stash under threads. Now
it is an offset (cop->cop_stashoff) into the new PL_stashpad array
(just a mallocked block), which holds pointers to all stashes that
have code compiled in them.
I didn’t use the lexical pads, because CopSTASH(cop) won’t work unless
PL_curpad is holding the right pad. And things start to get very
hairy in pp_caller, since the correct pad isn’t anywhere easily
accessible on the context stack (oldcomppad actually referring to the
current comppad). The approach I’ve followed uses far less code, too.
In addition to fixing the bug, this also saves memory. Instead of
allocating a separate PV for every single statement (to hold the stash
name), now all lines of code in a package can share the same stashpad
slot. So, on a 32-bit OS X, that’s 16 bytes less memory per COP for
short package names. Since stashoff is the same size as stashpv,
there is no difference there. Each package now needs just 4 bytes in
the stashpad for storing a pointer.
For speed’s sake PL_stashpadix stores the index of the last-used
stashpad offset. So only when switching packages is there a linear
search through the stashpad.
Diffstat (limited to 'makedef.pl')
-rw-r--r-- | makedef.pl | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/makedef.pl b/makedef.pl index a52241ff8c..f309efb5f1 100644 --- a/makedef.pl +++ b/makedef.pl @@ -355,6 +355,9 @@ unless ($define{'USE_ITHREADS'}) { PL_hints_mutex PL_my_ctx_mutex PL_perlio_mutex + PL_stashpad + PL_stashpadix + PL_stashpadmax Perl_clone_params_del Perl_clone_params_new Perl_parser_dup |