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 /scope.h | |
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 'scope.h')
-rw-r--r-- | scope.h | 6 |
1 files changed, 2 insertions, 4 deletions
@@ -235,10 +235,8 @@ scope has the given name. Name must be a literal string. #define SAVEPARSER(p) save_pushptr((p), SAVEt_PARSER) #ifdef USE_ITHREADS -# define SAVECOPSTASH(c) (SAVEPPTR(CopSTASHPV(c)), \ - SAVEI32(CopSTASH_len(c))) -# define SAVECOPSTASH_FREE(c) (SAVESHAREDPV(CopSTASHPV(c)), \ - SAVEI32(CopSTASH_len(c))) +# define SAVECOPSTASH(c) SAVEIV((c)->cop_stashoff) +# define SAVECOPSTASH_FREE(c) SAVEIV((c)->cop_stashoff) # define SAVECOPFILE(c) SAVEPPTR(CopFILE(c)) # define SAVECOPFILE_FREE(c) SAVESHAREDPV(CopFILE(c)) #else |