summaryrefslogtreecommitdiff
path: root/embedvar.h
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-06-04 14:04:03 -0700
committerFather Chrysostomos <sprout@cpan.org>2012-06-04 18:14:53 -0700
commitd4d03940c58a0177edb93c8854929856e9975bf9 (patch)
tree3852b1f0c210b55ba9172c1edbef3040a6fbae36 /embedvar.h
parentf3ac9fb2631eb3706dcdd2fe0274a953da37486f (diff)
downloadperl-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 'embedvar.h')
-rw-r--r--embedvar.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/embedvar.h b/embedvar.h
index c4a0fa9042..52452617ac 100644
--- a/embedvar.h
+++ b/embedvar.h
@@ -316,6 +316,9 @@
#define PL_stack_sp (vTHX->Istack_sp)
#define PL_start_env (vTHX->Istart_env)
#define PL_stashcache (vTHX->Istashcache)
+#define PL_stashpad (vTHX->Istashpad)
+#define PL_stashpadix (vTHX->Istashpadix)
+#define PL_stashpadmax (vTHX->Istashpadmax)
#define PL_statbuf (vTHX->Istatbuf)
#define PL_statcache (vTHX->Istatcache)
#define PL_statgv (vTHX->Istatgv)