summaryrefslogtreecommitdiff
path: root/ext/Opcode
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2001-10-25 18:07:58 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2001-10-25 18:07:58 +0000
commit89ca4ac7af707d34da190bf469b8073ada175d9b (patch)
treee9338f678f71d31acd664a643de302ea3bd3289f /ext/Opcode
parent4e1a6d261e266112da00fd82e73dbe2a0631027c (diff)
downloadperl-89ca4ac7af707d34da190bf469b8073ada175d9b.tar.gz
Integrate changes #12652 and #12653 from maintperl;
more tweaks to change#12626 * move the boilerplate code over to perl.h and make DynaLoader use it * make re, Opcode, File::Glob and B threadsafe * re.xs needed s/deinstall/uninstall/ (guess nobody uses C<no re;> anywhere) include XS_VERSION in MY_CXT_KEY (tweak for change#12652) File::Glob required a bit more work in bleadperl because of ExtUtils::Constant (see the Makefile.PL change) p4raw-link: @12652 on //depot/maint-5.6/perl: 3bc8871b91a24662eada2114d9a016153718b1c4 p4raw-link: @12626 on //depot/maint-5.6/perl: 512dcce54ea4db665708f91609bdd0a6126d1acd p4raw-id: //depot/perl@12654 p4raw-integrated: from //depot/maint-5.6/perl@12650 'edit in' ext/B/B.xs ext/DynaLoader/dlutils.c (@12652..) 'merge in' perl.h (@12597..) ext/File/Glob/Glob.xs ext/Opcode/Opcode.xs ext/re/re.xs (@12652..)
Diffstat (limited to 'ext/Opcode')
-rw-r--r--ext/Opcode/Opcode.xs47
1 files changed, 43 insertions, 4 deletions
diff --git a/ext/Opcode/Opcode.xs b/ext/Opcode/Opcode.xs
index 22f022ba32..c00a5e528b 100644
--- a/ext/Opcode/Opcode.xs
+++ b/ext/Opcode/Opcode.xs
@@ -7,10 +7,21 @@
#define OP_MASK_BUF_SIZE (MAXO + 100)
/* XXX op_named_bits and opset_all are never freed */
-static HV *op_named_bits; /* cache shared for whole process */
-static SV *opset_all; /* mask with all bits set */
-static IV opset_len; /* length of opmasks in bytes */
-static int opcode_debug = 0;
+#define MY_CXT_KEY "Opcode::_guts"##XS_VERSION
+
+typedef struct {
+ HV * x_op_named_bits; /* cache shared for whole process */
+ SV * x_opset_all; /* mask with all bits set */
+ IV x_opset_len; /* length of opmasks in bytes */
+ int x_opcode_debug;
+} my_cxt_t;
+
+START_MY_CXT
+
+#define op_named_bits (MY_CXT.x_op_named_bits)
+#define opset_all (MY_CXT.x_opset_all)
+#define opset_len (MY_CXT.x_opset_len)
+#define opcode_debug (MY_CXT.x_opcode_debug)
static SV *new_opset (pTHX_ SV *old_opset);
static int verify_opset (pTHX_ SV *opset, int fatal);
@@ -34,6 +45,7 @@ op_names_init(pTHX)
STRLEN len;
char **op_names;
char *bitmap;
+ dMY_CXT;
op_named_bits = newHV();
op_names = get_op_names();
@@ -66,6 +78,8 @@ static void
put_op_bitspec(pTHX_ char *optag, STRLEN len, SV *mask)
{
SV **svp;
+ dMY_CXT;
+
verify_opset(aTHX_ mask,1);
if (!len)
len = strlen(optag);
@@ -87,6 +101,8 @@ static SV *
get_op_bitspec(pTHX_ char *opname, STRLEN len, int fatal)
{
SV **svp;
+ dMY_CXT;
+
if (!len)
len = strlen(opname);
svp = hv_fetch(op_named_bits, opname, len, 0);
@@ -110,6 +126,8 @@ static SV *
new_opset(pTHX_ SV *old_opset)
{
SV *opset;
+ dMY_CXT;
+
if (old_opset) {
verify_opset(aTHX_ old_opset,1);
opset = newSVsv(old_opset);
@@ -129,6 +147,8 @@ static int
verify_opset(pTHX_ SV *opset, int fatal)
{
char *err = Nullch;
+ dMY_CXT;
+
if (!SvOK(opset)) err = "undefined";
else if (!SvPOK(opset)) err = "wrong type";
else if (SvCUR(opset) != opset_len) err = "wrong size";
@@ -142,6 +162,8 @@ verify_opset(pTHX_ SV *opset, int fatal)
static void
set_opset_bits(pTHX_ char *bitmap, SV *bitspec, int on, char *opname)
{
+ dMY_CXT;
+
if (SvIOK(bitspec)) {
int myopcode = SvIV(bitspec);
int offset = myopcode >> 3;
@@ -180,6 +202,7 @@ opmask_add(pTHX_ SV *opset) /* THE ONLY FUNCTION TO EDIT PL_op_mask ITSELF */
char *bitmask;
STRLEN len;
int myopcode = 0;
+ dMY_CXT;
verify_opset(aTHX_ opset,1); /* croaks on bad opset */
@@ -204,6 +227,8 @@ static void
opmask_addlocal(pTHX_ SV *opset, char *op_mask_buf) /* Localise PL_op_mask then opmask_add() */
{
char *orig_op_mask = PL_op_mask;
+ dMY_CXT;
+
SAVEVPTR(PL_op_mask);
/* XXX casting to an ordinary function ptr from a member function ptr
* is disallowed by Borland
@@ -225,11 +250,14 @@ MODULE = Opcode PACKAGE = Opcode
PROTOTYPES: ENABLE
BOOT:
+{
+ MY_CXT_INIT;
assert(PL_maxo < OP_MASK_BUF_SIZE);
opset_len = (PL_maxo + 7) / 8;
if (opcode_debug >= 1)
warn("opset_len %ld\n", (long)opset_len);
op_names_init(aTHX);
+}
void
_safe_pkg_prep(Package)
@@ -308,7 +336,9 @@ invert_opset(opset)
CODE:
{
char *bitmap;
+ dMY_CXT;
STRLEN len = opset_len;
+
opset = sv_2mortal(new_opset(aTHX_ opset)); /* verify and clone opset */
bitmap = SvPVX(opset);
while(len-- > 0)
@@ -330,6 +360,8 @@ PPCODE:
int i, j, myopcode;
char *bitmap = SvPV(opset, len);
char **names = (desc) ? get_op_descs() : get_op_names();
+ dMY_CXT;
+
verify_opset(aTHX_ opset,1);
for (myopcode=0, i=0; i < opset_len; i++) {
U16 bits = bitmap[i];
@@ -348,6 +380,8 @@ CODE:
SV *bitspec, *opset;
char *bitmap;
STRLEN len, on;
+ dMY_CXT;
+
opset = sv_2mortal(new_opset(aTHX_ Nullsv));
bitmap = SvPVX(opset);
for (i = 0; i < items; i++) {
@@ -382,6 +416,7 @@ CODE:
SV *bitspec, *mask;
char *bitmap, *opname;
STRLEN len;
+ dMY_CXT;
if (!SvROK(safe) || !SvOBJECT(SvRV(safe)) || SvTYPE(SvRV(safe))!=SVt_PVHV)
croak("Not a Safe object");
@@ -416,6 +451,8 @@ PPCODE:
STRLEN len;
SV **args;
char **op_desc = get_op_descs();
+ dMY_CXT;
+
/* copy args to a scratch area since we may push output values onto */
/* the stack faster than we read values off it if masks are used. */
args = (SV**)SvPVX(sv_2mortal(newSVpvn((char*)&ST(0), items*sizeof(SV*))));
@@ -453,6 +490,7 @@ define_optag(optagsv, mask)
CODE:
STRLEN len;
char *optag = SvPV(optagsv, len);
+
put_op_bitspec(aTHX_ optag, len, mask); /* croaks */
ST(0) = &PL_sv_yes;
@@ -465,6 +503,7 @@ CODE:
void
full_opset()
CODE:
+ dMY_CXT;
ST(0) = sv_2mortal(new_opset(aTHX_ opset_all));
void