summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2022-05-29 16:57:33 +0200
committerKarl Williamson <khw@cpan.org>2022-06-08 07:34:26 -0600
commite6567a72c70327ad01f6eaea5d09b56f4c9ef22c (patch)
treee9fbc2f2824b9d0c13c484de0636e0b290a28f82
parent0195a594a079310dd4da2952885abd35c8cb624b (diff)
downloadperl-e6567a72c70327ad01f6eaea5d09b56f4c9ef22c.tar.gz
opset_len in Opcode.xs is a constant, so should be a static const
We can also remove many dMY_CXT declarations, as they are no longer needed (and generate a now unused variable in threaded builds, hence compiler warnings). Previously it was part of the module's my_cxt_t, because it was a value calculated from the interpreter variable PL_maxo. But PL_maxo itself is *not* a variable - it was converted to a #define in Aug 2016 by commit 8d89205aa6324e7d: Remove PL_maxo We have an interpreter variable using memory, PL_maxo, which is defined to be the same as MAXO, a #defined constant. As far as I can tell, it is never used in lvalue context, in core or on CPAN, except for the initialisation in intrpvar.h. It can simply be removed and replaced with a macro defined as equiva- lent to MAXO. It was added in this commit: commit 84ea024ac9cdf20f21223e686dddea82d5eceb4f Author: Perl 5 Porters <perl5-porters.nicoh.com> Date: Tue Jan 2 23:21:55 1996 +0000 perl 5.002beta1h patch: perl.h 5.002beta1 attempted some memory optimizations, but unfortunately they can result in a memory leak problem. This can be avoided by #define STRANGE_MALLOC. I do that here until consensus is reached on a better strategy for handling the memory optimizations. Include maxo for the maximum number of operations (needed for the Safe extension). But apparently it is not needed for the Safe extension (tests pass without it). What the author of that commit didn't realise was that Opcode had been split out from Safe - the code in question is in this module not Safe.
-rw-r--r--ext/Opcode/Opcode.pm2
-rw-r--r--ext/Opcode/Opcode.xs30
2 files changed, 13 insertions, 19 deletions
diff --git a/ext/Opcode/Opcode.pm b/ext/Opcode/Opcode.pm
index 051fad7891..8170416a2a 100644
--- a/ext/Opcode/Opcode.pm
+++ b/ext/Opcode/Opcode.pm
@@ -6,7 +6,7 @@ use strict;
our($VERSION, @ISA, @EXPORT_OK);
-$VERSION = "1.57";
+$VERSION = "1.58";
use Carp;
use Exporter 'import';
diff --git a/ext/Opcode/Opcode.xs b/ext/Opcode/Opcode.xs
index 44a6d7c354..a0e706efde 100644
--- a/ext/Opcode/Opcode.xs
+++ b/ext/Opcode/Opcode.xs
@@ -12,7 +12,6 @@
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 */
#ifdef OPCODE_DEBUG
int x_opcode_debug; /* unused warn() emitting debugging code */
#endif
@@ -20,9 +19,11 @@ typedef struct {
START_MY_CXT
+/* length of opmasks in bytes */
+static const STRLEN opset_len = (PL_maxo + 7) / 8;
+
#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)
#ifdef OPCODE_DEBUG
# define opcode_debug (MY_CXT.x_opcode_debug)
#else
@@ -128,7 +129,6 @@ static SV *
new_opset(pTHX_ SV *old_opset)
{
SV *opset;
- dMY_CXT;
if (old_opset) {
verify_opset(aTHX_ old_opset,1);
@@ -149,11 +149,10 @@ static int
verify_opset(pTHX_ SV *opset, int fatal)
{
const char *err = NULL;
- dMY_CXT;
if (!SvOK(opset)) err = "undefined";
else if (!SvPOK(opset)) err = "wrong type";
- else if (SvCUR(opset) != (STRLEN)opset_len) err = "wrong size";
+ else if (SvCUR(opset) != opset_len) err = "wrong size";
if (err && fatal) {
croak("Invalid opset: %s", err);
}
@@ -164,8 +163,6 @@ verify_opset(pTHX_ SV *opset, int fatal)
static void
set_opset_bits(pTHX_ char *bitmap, SV *bitspec, int on, const char *opname)
{
- dMY_CXT;
-
if (SvIOK(bitspec)) {
const int myopcode = SvIV(bitspec);
const int offset = myopcode >> 3;
@@ -180,7 +177,7 @@ set_opset_bits(pTHX_ char *bitmap, SV *bitspec, int on, const char *opname)
else
bitmap[offset] &= ~(1 << bit);
}
- else if (SvPOK(bitspec) && SvCUR(bitspec) == (STRLEN)opset_len) {
+ else if (SvPOK(bitspec) && SvCUR(bitspec) == opset_len) {
STRLEN len;
const char * const specbits = SvPV(bitspec, len);
@@ -200,11 +197,10 @@ set_opset_bits(pTHX_ char *bitmap, SV *bitspec, int on, const char *opname)
static void
opmask_add(pTHX_ SV *opset) /* THE ONLY FUNCTION TO EDIT PL_op_mask ITSELF */
{
- int i,j;
+ int j;
char *bitmask;
STRLEN len;
int myopcode = 0;
- dMY_CXT;
verify_opset(aTHX_ opset,1); /* croaks on bad opset */
@@ -214,7 +210,7 @@ opmask_add(pTHX_ SV *opset) /* THE ONLY FUNCTION TO EDIT PL_op_mask ITSELF */
/* OPCODES ALREADY MASKED ARE NEVER UNMASKED. See opmask_addlocal() */
bitmask = SvPV(opset, len);
- for (i=0; i < opset_len; i++) {
+ for (STRLEN i=0; i < opset_len; i++) {
const U16 bits = bitmask[i];
if (!bits) { /* optimise for sparse masks */
myopcode += 8;
@@ -258,7 +254,6 @@ BOOT:
{
MY_CXT_INIT;
STATIC_ASSERT_STMT(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);
@@ -353,7 +348,6 @@ invert_opset(opset)
CODE:
{
char *bitmap;
- dMY_CXT;
STRLEN len = opset_len;
opset = sv_2mortal(new_opset(aTHX_ opset)); /* verify and clone opset */
@@ -374,10 +368,10 @@ opset_to_ops(opset, desc = 0)
PPCODE:
{
STRLEN len;
- int i, j, myopcode;
+ STRLEN i;
+ int j, myopcode;
const char * const 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++) {
@@ -468,7 +462,6 @@ 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. */
@@ -483,8 +476,9 @@ PPCODE:
XPUSHs(newSVpvn_flags(op_desc[myopcode], strlen(op_desc[myopcode]),
SVs_TEMP));
}
- else if (SvPOK(bitspec) && SvCUR(bitspec) == (STRLEN)opset_len) {
- int b, j;
+ else if (SvPOK(bitspec) && SvCUR(bitspec) == opset_len) {
+ STRLEN b;
+ int j;
const char * const bitmap = SvPV_nolen_const(bitspec);
int myopcode = 0;
for (b=0; b < opset_len; b++) {