Subject: | [PATCH] add PERL_NO_GET_CONTEXT for efficiency+consting |
See commit message body.
Subject: | 0001-add-PERL_NO_GET_CONTEXT-for-efficiency-consting.patch |
From a55ec20068f5fcf33cfad255a87c53cb489c59bc Mon Sep 17 00:00:00 2001
From: bulk88 <bulk88@hotmail.com>
Date: Fri, 2 Jan 2015 18:06:40 -0500
Subject: [PATCH] add PERL_NO_GET_CONTEXT for efficiency+consting
const the tables so they are stored in RO memory in the shared library so
the tables can be shared between perl processes by the OS
---
SHA.xs | 21 +++++++++++----------
src/sha.c | 14 +++++++-------
src/sha64bit.c | 10 +++++-----
typemap | 2 +-
4 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/SHA.xs b/SHA.xs
index 30fdb85..f212b57 100644
--- a/SHA.xs
+++ b/SHA.xs
@@ -1,3 +1,4 @@
+#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
@@ -28,7 +29,7 @@
#include "src/sha.c"
-static int ix2alg[] =
+static const int ix2alg[] =
{1,1,1,224,224,224,256,256,256,384,384,384,512,512,512,
512224,512224,512224,512256,512256,512256};
@@ -39,7 +40,7 @@ static int ix2alg[] =
#define MAX_WRITE_SIZE 16384
#define IO_BUFFER_SIZE 4096
-static SHA *getSHA(SV *self)
+static SHA *getSHA(pTHX_ SV *self)
{
if (!sv_isobject(self) || !sv_derived_from(self, "Digest::SHA"))
return(NULL);
@@ -90,7 +91,7 @@ PREINIT:
SHA *state;
SHA *clone;
CODE:
- if ((state = getSHA(self)) == NULL)
+ if ((state = getSHA(aTHX_ self)) == NULL)
XSRETURN_UNDEF;
Newx(clone, 1, SHA);
RETVAL = newSV(0);
@@ -231,7 +232,7 @@ ALIAS:
PREINIT:
SHA *state;
CODE:
- if ((state = getSHA(self)) == NULL)
+ if ((state = getSHA(aTHX_ self)) == NULL)
XSRETURN_UNDEF;
RETVAL = ix ? state->alg : (int) (state->digestlen << 3);
OUTPUT:
@@ -246,7 +247,7 @@ PREINIT:
STRLEN len;
SHA *state;
PPCODE:
- if ((state = getSHA(self)) == NULL)
+ if ((state = getSHA(aTHX_ self)) == NULL)
XSRETURN_UNDEF;
for (i = 1; i < items; i++) {
data = (UCHR *) (SvPVbyte(ST(i), len));
@@ -271,7 +272,7 @@ PREINIT:
SHA *state;
char *result;
CODE:
- if ((state = getSHA(self)) == NULL)
+ if ((state = getSHA(aTHX_ self)) == NULL)
XSRETURN_UNDEF;
shafinish(state);
len = 0;
@@ -296,7 +297,7 @@ PREINIT:
UCHR buf[256];
UCHR *ptr = buf;
CODE:
- if ((state = getSHA(self)) == NULL)
+ if ((state = getSHA(aTHX_ self)) == NULL)
XSRETURN_UNDEF;
Copy(digcpy(state), ptr, state->alg <= SHA256 ? 32 : 64, UCHR);
ptr += state->alg <= SHA256 ? 32 : 64;
@@ -321,7 +322,7 @@ PREINIT:
SHA *state;
UCHR *data;
PPCODE:
- if ((state = getSHA(self)) == NULL)
+ if ((state = getSHA(aTHX_ self)) == NULL)
XSRETURN_UNDEF;
data = (UCHR *) SvPV(packed_state, len);
if (len != (state->alg <= SHA256 ? 116U : 212U))
@@ -348,7 +349,7 @@ PREINIT:
int n;
UCHR in[IO_BUFFER_SIZE];
PPCODE:
- if (!f || (state = getSHA(self)) == NULL)
+ if (!f || (state = getSHA(aTHX_ self)) == NULL)
XSRETURN_UNDEF;
while ((n = PerlIO_read(f, in, sizeof(in))) > 0)
shawrite(in, (ULNG) n << 3, state);
@@ -366,7 +367,7 @@ PREINIT:
UCHR in[IO_BUFFER_SIZE+1];
SHA *state;
PPCODE:
- if (!f || (state = getSHA(self)) == NULL)
+ if (!f || (state = getSHA(aTHX_ self)) == NULL)
XSRETURN_UNDEF;
while ((n = PerlIO_read(f, in+1, IO_BUFFER_SIZE)) > 0) {
for (dst = in, src = in + 1; n; n--) {
diff --git a/src/sha.c b/src/sha.c
index 3756969..b53e1b8 100644
--- a/src/sha.c
+++ b/src/sha.c
@@ -45,7 +45,7 @@
#define K3 C32(0x8f1bbcdc)
#define K4 C32(0xca62c1d6)
-static W32 K256[64] = /* SHA-224/256 constants */
+static const W32 K256[64] = /* SHA-224/256 constants */
{
C32(0x428a2f98), C32(0x71374491), C32(0xb5c0fbcf), C32(0xe9b5dba5),
C32(0x3956c25b), C32(0x59f111f1), C32(0x923f82a4), C32(0xab1c5ed5),
@@ -65,19 +65,19 @@ static W32 K256[64] = /* SHA-224/256 constants */
C32(0x90befffa), C32(0xa4506ceb), C32(0xbef9a3f7), C32(0xc67178f2)
};
-static W32 H01[8] = /* SHA-1 initial hash value */
+static const W32 H01[8] = /* SHA-1 initial hash value */
{
C32(0x67452301), C32(0xefcdab89), C32(0x98badcfe), C32(0x10325476),
C32(0xc3d2e1f0), C32(0x00000000), C32(0x00000000), C32(0x00000000)
};
-static W32 H0224[8] = /* SHA-224 initial hash value */
+static const W32 H0224[8] = /* SHA-224 initial hash value */
{
C32(0xc1059ed8), C32(0x367cd507), C32(0x3070dd17), C32(0xf70e5939),
C32(0xffc00b31), C32(0x68581511), C32(0x64f98fa7), C32(0xbefa4fa4)
};
-static W32 H0256[8] = /* SHA-256 initial hash value */
+static const W32 H0256[8] = /* SHA-256 initial hash value */
{
C32(0x6a09e667), C32(0xbb67ae85), C32(0x3c6ef372), C32(0xa54ff53a),
C32(0x510e527f), C32(0x9b05688c), C32(0x1f83d9ab), C32(0x5be0cd19)
@@ -154,7 +154,7 @@ static void sha256(SHA *s, UCHR *block) /* SHA-224/256 transform */
{
W32 a, b, c, d, e, f, g, h, T1;
W32 W[16];
- W32 *kp = K256;
+ const W32 *kp = K256;
W32 *wp = W;
W32 *H = s->H32;
@@ -439,7 +439,7 @@ static void shafinish(SHA *s)
#define shadigest(state) digcpy(state)
/* xmap: translation map for hexadecimal encoding */
-static char xmap[] =
+static const char xmap[] =
"0123456789abcdef";
/* shahex: returns pointer to current digest (hexadecimal) */
@@ -462,7 +462,7 @@ static char *shahex(SHA *s)
}
/* bmap: translation map for Base 64 encoding */
-static char bmap[] =
+static const char bmap[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/* encbase64: encodes input (0 to 3 bytes) into Base 64 */
diff --git a/src/sha64bit.c b/src/sha64bit.c
index add57e0..e0d77a9 100644
--- a/src/sha64bit.c
+++ b/src/sha64bit.c
@@ -33,7 +33,7 @@
#define sigmaQ0(x) (ROTRQ(x, 1) ^ ROTRQ(x, 8) ^ SR64(x, 7))
#define sigmaQ1(x) (ROTRQ(x, 19) ^ ROTRQ(x, 61) ^ SR64(x, 6))
-static W64 K512[80] = /* SHA-384/512 constants */
+static const W64 K512[80] = /* SHA-384/512 constants */
{
C64(0x428a2f98d728ae22), C64(0x7137449123ef65cd), C64(0xb5c0fbcfec4d3b2f),
C64(0xe9b5dba58189dbbc), C64(0x3956c25bf348b538), C64(0x59f111f1b605d019),
@@ -64,28 +64,28 @@ C64(0x431d67c49c100d4c), C64(0x4cc5d4becb3e42b6), C64(0x597f299cfc657e2a),
C64(0x5fcb6fab3ad6faec), C64(0x6c44198c4a475817)
};
-static W64 H0384[8] = /* SHA-384 initial hash value */
+static const W64 H0384[8] = /* SHA-384 initial hash value */
{
C64(0xcbbb9d5dc1059ed8), C64(0x629a292a367cd507), C64(0x9159015a3070dd17),
C64(0x152fecd8f70e5939), C64(0x67332667ffc00b31), C64(0x8eb44a8768581511),
C64(0xdb0c2e0d64f98fa7), C64(0x47b5481dbefa4fa4)
};
-static W64 H0512[8] = /* SHA-512 initial hash value */
+static const W64 H0512[8] = /* SHA-512 initial hash value */
{
C64(0x6a09e667f3bcc908), C64(0xbb67ae8584caa73b), C64(0x3c6ef372fe94f82b),
C64(0xa54ff53a5f1d36f1), C64(0x510e527fade682d1), C64(0x9b05688c2b3e6c1f),
C64(0x1f83d9abfb41bd6b), C64(0x5be0cd19137e2179)
};
-static W64 H0512224[8] = /* SHA-512/224 initial hash value */
+static const W64 H0512224[8] = /* SHA-512/224 initial hash value */
{
C64(0x8c3d37c819544da2), C64(0x73e1996689dcd4d6), C64(0x1dfab7ae32ff9c82),
C64(0x679dd514582f9fcf), C64(0x0f6d2b697bd44da8), C64(0x77e36f7304c48942),
C64(0x3f9d85a86a1d36c8), C64(0x1112e6ad91d692a1)
};
-static W64 H0512256[8] = /* SHA-512/256 initial hash value */
+static const W64 H0512256[8] = /* SHA-512/256 initial hash value */
{
C64(0x22312194fc2bf72c), C64(0x9f555fa3c84c64c2), C64(0x2393b86b6f53b151),
C64(0x963877195940eabd), C64(0x96283ee2a88effe3), C64(0xbe5e1e2553863992),
diff --git a/typemap b/typemap
index b881a1d..8a47499 100644
--- a/typemap
+++ b/typemap
@@ -4,4 +4,4 @@ PerlIO * T_IN
INPUT
T_SHA
- $var = getSHA($arg)
+ $var = getSHA(aTHX_ $arg)
--
1.7.9.msysgit.0