Perl code patch contributed by "Kurt J. Pires" <kjpires@iat.com>
His own words are:
The patch adds no new functionality (other than a simple test package)
to the libraries, but it allows them to be compiled with Perl5.6.0.
It has only been tested under "Red Hat Linux release 7.0 (Guinness)"
with the unpatched verion of OpenSSL 0.9.6 released last September.
diff --git a/perl/OpenSSL.xs b/perl/OpenSSL.xs
index 2267168..6ef66cc 100644
--- a/perl/OpenSSL.xs
+++ b/perl/OpenSSL.xs
@@ -72,11 +72,38 @@
boot_digest();
boot_err();
boot_ssl();
- boot_OpenSSL__BN();
- boot_OpenSSL__BIO();
- boot_OpenSSL__Cipher();
- boot_OpenSSL__MD();
- boot_OpenSSL__ERR();
- boot_OpenSSL__SSL();
- boot_OpenSSL__X509();
+
+ /* */
+ /* The next macro is the completely correct way to call a C */
+ /* function that uses perl calling conventions but is not */
+ /* registered with perl. */
+ /* */
+ /* The second macro seems to work for this context. (We just */
+ /* need a mark for the called function since we don't have */
+ /* any local variables and what-not.) */
+ /* */
+ /* Unfortunately, we need to do this because these boot_* */
+ /* functions are auto-generated by xsubpp and are normally */
+ /* called from DyncLoader, but we're pulling them in here. */
+ /* */
+#define FULL_callBootFunc(func) { \
+ dSP; \
+ ENTER; \
+ SAVETMPS; \
+ PUSHMARK(SP); \
+ func(); \
+ FREETMPS; \
+ LEAVE; \
+ }
+#define callBootFunc(func) { \
+ PUSHMARK(SP); \
+ func(); \
+ }
+ callBootFunc(boot_OpenSSL__BN);
+ callBootFunc(boot_OpenSSL__BIO);
+ callBootFunc(boot_OpenSSL__Cipher);
+ callBootFunc(boot_OpenSSL__MD);
+ callBootFunc(boot_OpenSSL__ERR);
+ callBootFunc(boot_OpenSSL__SSL);
+ callBootFunc(boot_OpenSSL__X509);
diff --git a/perl/openssl_bio.xs b/perl/openssl_bio.xs
index 06d61af..5628300 100644
--- a/perl/openssl_bio.xs
+++ b/perl/openssl_bio.xs
@@ -32,7 +32,7 @@
if ((state == BIO_CB_READ) || (state == BIO_CB_WRITE))
XPUSHs(sv_2mortal(newSVpv(parg,larg)));
else
- XPUSHs(&sv_undef);
+ XPUSHs(&PL_sv_undef);
/* ptr one */
XPUSHs(sv_2mortal(newSViv(larg)));
XPUSHs(sv_2mortal(newSViv(ret)));
@@ -129,9 +129,9 @@
PPCODE:
pr_name("p5_BIO_new");
if ((items == 1) && SvPOK(ST(0)))
- type = SvPV(ST(0),na);
+ type = SvPV_nolen(ST(0));
else if ((items == 2) && SvPOK(ST(1)))
- type = SvPV(ST(1),na);
+ type = SvPV_nolen(ST(1));
else
croak("Usage: OpenSSL::BIO::new(type)");
EXTEND(sp,1);
@@ -314,7 +314,7 @@
PUSHs(sv_newmortal());
sv_setpvn(ST(0), "", 0);
SvGROW(ST(0), 1024);
- p=SvPV(ST(0), na);
+ p=SvPV_nolen(ST(0));
i = BIO_gets(bio, p, 1024);
if (i < 0)
i = 0;
@@ -370,7 +370,7 @@
PREINIT:
char *ptr;
CODE:
- ptr = SvPV(in,na);
+ ptr = SvPV_nolen(in);
RETVAL = BIO_puts(bio, ptr);
OUTPUT:
RETVAL
diff --git a/perl/openssl_bn.xs b/perl/openssl_bn.xs
index f79bf87..6817cfb 100644
--- a/perl/openssl_bn.xs
+++ b/perl/openssl_bn.xs
@@ -142,7 +142,7 @@
i=BN_num_bytes(a)+2;
sv_setpvn(ST(0),"",1);
SvGROW(ST(0),i+1);
- SvCUR_set(ST(0),BN_bn2bin(a,SvPV(ST(0),na)));
+ SvCUR_set(ST(0),BN_bn2bin(a,SvPV_nolen(ST(0))));
void
p5_BN_mpi2bn(a)
@@ -168,7 +168,7 @@
i=BN_bn2mpi(a,NULL);
sv_setpvn(ST(0),"",1);
SvGROW(ST(0),i+1);
- SvCUR_set(ST(0),BN_bn2mpi(a,SvPV(ST(0),na)));
+ SvCUR_set(ST(0),BN_bn2mpi(a,SvPV_nolen(ST(0))));
void
p5_BN_hex2bn(a)
@@ -208,9 +208,9 @@
RETVAL=newSVpv("",0);
i=strlen(ptr);
SvGROW(RETVAL,i+1);
- memcpy(SvPV(RETVAL,na),ptr,i+1);
+ memcpy(SvPV_nolen(RETVAL),ptr,i+1);
SvCUR_set(RETVAL,i);
- Free(ptr);
+ OPENSSL_free(ptr);
OUTPUT:
RETVAL
@@ -226,9 +226,9 @@
RETVAL=newSVpv("",0);
i=strlen(ptr);
SvGROW(RETVAL,i+1);
- memcpy(SvPV(RETVAL,na),ptr,i+1);
+ memcpy(SvPV_nolen(RETVAL),ptr,i+1);
SvCUR_set(RETVAL,i);
- Free(ptr);
+ OPENSSL_free(ptr);
OUTPUT:
RETVAL
diff --git a/perl/openssl_cipher.xs b/perl/openssl_cipher.xs
index e9ff2a8..580620f 100644
--- a/perl/openssl_cipher.xs
+++ b/perl/openssl_cipher.xs
@@ -20,9 +20,9 @@
char *name;
PPCODE:
if ((items == 1) && SvPOK(ST(0)))
- name=SvPV(ST(0),na);
+ name=SvPV_nolen(ST(0));
else if ((items == 2) && SvPOK(ST(1)))
- name=SvPV(ST(1),na);
+ name=SvPV_nolen(ST(1));
else
croak("Usage: OpenSSL::Cipher::new(type)");
PUSHs(sv_newmortal());
@@ -112,7 +112,7 @@
CODE:
RETVAL=newSVpv("",0);
SvGROW(RETVAL,in.dsize+EVP_CIPHER_CTX_block_size(ctx)+1);
- EVP_Cipher(ctx,SvPV(RETVAL,na),in.dptr,in.dsize);
+ EVP_Cipher(ctx,SvPV_nolen(RETVAL),in.dptr,in.dsize);
SvCUR_set(RETVAL,in.dsize);
OUTPUT:
RETVAL
@@ -126,7 +126,7 @@
CODE:
RETVAL=newSVpv("",0);
SvGROW(RETVAL,in.dsize+EVP_CIPHER_CTX_block_size(ctx)+1);
- EVP_CipherUpdate(ctx,SvPV(RETVAL,na),&i,in.dptr,in.dsize);
+ EVP_CipherUpdate(ctx,SvPV_nolen(RETVAL),&i,in.dptr,in.dsize);
SvCUR_set(RETVAL,i);
OUTPUT:
RETVAL
@@ -139,7 +139,7 @@
CODE:
RETVAL=newSVpv("",0);
SvGROW(RETVAL,EVP_CIPHER_CTX_block_size(ctx)+1);
- if (!EVP_CipherFinal(ctx,SvPV(RETVAL,na),&i))
+ if (!EVP_CipherFinal(ctx,SvPV_nolen(RETVAL),&i))
sv_setpv(RETVAL,"BAD DECODE");
else
SvCUR_set(RETVAL,i);
diff --git a/perl/openssl_digest.xs b/perl/openssl_digest.xs
index 6cd3018..4f2f893 100644
--- a/perl/openssl_digest.xs
+++ b/perl/openssl_digest.xs
@@ -27,9 +27,9 @@
char *name;
PPCODE:
if ((items == 1) && SvPOK(ST(0)))
- name=SvPV(ST(0),na);
+ name=SvPV_nolen(ST(0));
else if ((items == 2) && SvPOK(ST(1)))
- name=SvPV(ST(1),na);
+ name=SvPV_nolen(ST(1));
else
croak("Usage: OpenSSL::MD::new(type)");
PUSHs(sv_newmortal());
@@ -45,8 +45,9 @@
p5_EVP_MD_name(ctx)
EVP_MD_CTX *ctx
CODE:
- RETVAL.dptr=OBJ_nid2ln(EVP_MD_type(EVP_MD_CTX_type(ctx)));
+ RETVAL.dptr=OBJ_nid2ln(EVP_MD_CTX_type(ctx));
RETVAL.dsize=strlen(RETVAL.dptr);
+
OUTPUT:
RETVAL
diff --git a/perl/openssl_ssl.xs b/perl/openssl_ssl.xs
index c7d1b17..146c1ac 100644
--- a/perl/openssl_ssl.xs
+++ b/perl/openssl_ssl.xs
@@ -72,9 +72,9 @@
PPCODE:
pr_name("p5_SSL_CTX_new");
if ((items == 1) && SvPOK(ST(0)))
- method=SvPV(ST(0),na);
+ method=SvPV_nolen(ST(0));
else if ((items == 2) && SvPOK(ST(1)))
- method=SvPV(ST(1),na);
+ method=SvPV_nolen(ST(1));
else
croak("Usage: OpenSSL::SSL::CTX::new(type)");
@@ -124,7 +124,7 @@
croak("OpenSSL::SSL::CTX::use_PrivateKey_file(ssl_ctx,file[,type])");
if (items == 3)
{
- ptr=SvPV(ST(2),na);
+ ptr=SvPV_nolen(ST(2));
if (strcmp(ptr,"der") == 0)
i=SSL_FILETYPE_ASN1;
else
@@ -148,7 +148,7 @@
{
if (!SvPOK(ST(i)))
croak("Usage: OpenSSL::SSL_CTX::set_options(ssl_ctx[,option,value]+)");
- ptr=SvPV(ST(i),na);
+ ptr=SvPV_nolen(ST(i));
if (strcmp(ptr,"-info_callback") == 0)
{
SSL_CTX_set_info_callback(ctx,
@@ -325,7 +325,7 @@
{
if (!SvPOK(ST(i)))
croak("Usage: OpenSSL::SSL::set_options(ssl[,option,value]+)");
- ptr=SvPV(ST(i),na);
+ ptr=SvPV_nolen(ST(i));
if (strcmp(ptr,"-info_callback") == 0)
{
SSL_set_info_callback(ssl,
@@ -477,7 +477,7 @@
ret=sv_mortalcopy(ret);
}
else
- ret= &sv_undef;
+ ret= &PL_sv_undef;
EXTEND(sp,1);
PUSHs(ret);