For those who are interested, I have attached a patch here that will
handle pointers using perl XS macros instead of casting.
From e774610c2310c25816e36306f45caaa8e40780a3 Mon Sep 17 00:00:00 2001
From: Douglas Christopher Wilson <doug@somethingdoug.com>
Date: Thu, 22 Sep 2011 17:30:05 -0400
Subject: [PATCH] Use XS pointer macros for storing pointers in SVs
Fix the typemap so that pointer types are of type T_PTR which
generates XS code using the INT2PTR and PTR2IV macros which store
pointers in an IV. Since an IV is guaranted to be at least the
size of a pointer, no information is lost.
Previously the pointers were cast to unsigned long int which
resulted in a loss on 64-bit systems where long int was only
4 bytes.
Also removed the pointer cast test since pointers are not being
cast anymore and are handled by the macros designed for the job.
---
MANIFEST | 2 -
SSLeay.xs | 4 +-
t/local/00_ptr_cast.t | 43 ---------------------
t/local/ptr_cast_test.c | 43 ---------------------
typemap | 94 +++++++++++++++++++++++-----------------------
5 files changed, 49 insertions(+), 137 deletions(-)
delete mode 100644 t/local/00_ptr_cast.t
delete mode 100644 t/local/ptr_cast_test.c
diff --git a/MANIFEST b/MANIFEST
index 4512a5d..099063a 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -55,7 +55,6 @@ t/external/15_altnames.t
t/handle/external/10_destroy.t
t/handle/external/50_external.t
t/handle/local/05_use.t
-t/local/00_ptr_cast.t
t/local/01_pod.t
t/local/02_pod_coverage.t
t/local/03_use.t
@@ -71,6 +70,5 @@ t/local/31_rsa_generate_key.t
t/local/35_ephemeral.t
t/local/50_digest.t
t/local/kwalitee.t
-t/local/ptr_cast_test.c
TODO
typemap
diff --git a/SSLeay.xs b/SSLeay.xs
index f9d1caa..1e7cf26 100644
--- a/SSLeay.xs
+++ b/SSLeay.xs
@@ -182,7 +182,7 @@ ssleay_verify_callback_invoke (int ok, X509_STORE_CTX* x509_store) {
PUSHMARK(sp);
EXTEND( sp, 2 );
PUSHs( sv_2mortal(newSViv(ok)) );
- PUSHs( sv_2mortal(newSViv((unsigned long int)x509_store)) );
+ PUSHs( sv_2mortal(newSViv(PTR2IV(x509_store))) );
PUTBACK;
PR("About to call verify callback.\n");
@@ -2863,7 +2863,7 @@ SSL_CTX_set1_param(ctx, vpm)
int
SSL_set1_param(ctx, vpm)
- SSL_CTX * ctx
+ SSL * ctx
X509_VERIFY_PARAM *vpm
#endif
diff --git a/t/local/00_ptr_cast.t b/t/local/00_ptr_cast.t
deleted file mode 100644
index 6293de6..0000000
--- a/t/local/00_ptr_cast.t
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use File::Spec;
-use Test::More tests => 5;
-use Symbol qw(gensym);
-use IPC::Open3;
-use Config;
-
-my $input = File::Spec->catfile(qw( t local ptr_cast_test.c ));
-my $output = File::Spec->catfile(qw( t local ptr_cast_test ));
-
-unlink $output;
-
-my $out = gensym();
-my $err = gensym();
-
-my @extraargs;
-my $cmd;
-if($^O eq 'MSWin32' && $Config{cc} eq 'cl') {
- push(@extraargs, '/nologo ' . $Config{libs});
- $cmd = "$Config{cc} /Fe$output $input " . join(' ', @extraargs);
-}
-else {
- push(@extraargs, '-Zexe') if $^O eq 'os2';
- $cmd = "$Config{cc} $Config{ccflags} -o $output $input " . join(' ', @extraargs)
-}
-diag( "compiling test program with: $cmd" );
-my $pid = open3(undef, $out, $err, $cmd);
-waitpid $pid, 0;
-
-is( $?, 0, 'compiling ptr_cast_test.c' );
-
-is( do { local $/ = undef; <$err>}, '', 'STDERR empty after compiling' );
-
-$pid = open3(undef, $out, $err, "./$output");
-waitpid $pid, 0;
-
-is( $?, 0, './ptr_cast_test exited with 0' );
-
-like( do { local $/ = undef; <$out> }, qr/ptr_cast_test:\s+ok\s+/, 'casting pointer integer and back worked' );
-ok( !do { local $/ = undef; <$err> }, 'STDERR empty after running' );
diff --git a/t/local/ptr_cast_test.c b/t/local/ptr_cast_test.c
deleted file mode 100644
index 15084b7..0000000
--- a/t/local/ptr_cast_test.c
+++ /dev/null
@@ -1,43 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-
-/* test if a pointer can be cast to an unsigned long int and back
- (aspa@hip.fi)
-
- tested on: HP-UX B.10.20, AIX 4.3, IRIX 5.3, OSF1 v4.0B and SunOS 5.6
- with both gcc and native compilers, and linux/gcc (i686) +
- linux/gcc (alpha).
-
-*/
-
-#define FROMTYPE void *
-#define FROMTYPESTR "void *"
-#define TOTYPE unsigned long int
-#define TOTYPESTR "unsigned long int"
-
-int main(argc, argv)
- int argc; /* e.g. HP-UX cc doesn't support ISO C by default */
- char *argv[];
-{
- /* heap should be near the end of process's address space */
- FROMTYPE bufptr = (FROMTYPE) malloc(500);
- volatile TOTYPE i; /* prevent optimization */
-
- printf("# %s: '%s' len: %ul, '%s' len: %ul.\n", argv[0], FROMTYPESTR,
- (int)sizeof(TOTYPE), TOTYPESTR, (int)sizeof(char *));
-
- i = (TOTYPE)bufptr;
- if( ((FROMTYPE)i) != bufptr ) {
- printf("# %s: failed: (%p != %p).\n", argv[0], (FROMTYPE)i, bufptr);
- printf("# ERROR: a '%s' can't be cast to a '%s' and back \n",
- FROMTYPESTR, TOTYPESTR);
- printf("# ERROR: without loss of information on this architecture.\n");
- exit(1);
- } else {
- printf("# ptr_cast_test: ok (%p == %p).\n", (FROMTYPE)i, bufptr);
- exit(0);
- }
-
- exit(1);
-}
-
diff --git a/typemap b/typemap
index 47c4f75..b7852f5 100644
--- a/typemap
+++ b/typemap
@@ -1,53 +1,53 @@
TYPEMAP
-SSL_METHOD * T_IV
-SSL_CTX * T_IV
-SSL_SESSION * T_IV
-SSL * T_IV
-RSA * T_IV
-DH * T_IV
-X509 * T_IV
-X509_CRL * T_IV
-X509_LOOKUP * T_IV
-X509_NAME * T_IV
-X509_EXTENSION * T_IV
-BIO * T_IV
-BIO_METHOD * T_IV
-EVP_PKEY * T_IV
-const EVP_MD * T_IV
-CERT * T_IV
-LHASH * T_IV
-struct lhash_st_SSL_SESSION * T_IV
-struct cert_st * T_IV
-X509_STORE_CTX * T_IV
-ASN1_UTCTIME * T_IV
-ASN1_OCTET_STRING * T_IV
-EVP_PKEY * T_IV
+SSL_METHOD * T_PTR
+SSL_CTX * T_PTR
+SSL_SESSION * T_PTR
+SSL * T_PTR
+RSA * T_PTR
+DH * T_PTR
+X509 * T_PTR
+X509_CRL * T_PTR
+X509_LOOKUP * T_PTR
+X509_NAME * T_PTR
+X509_EXTENSION * T_PTR
+BIO * T_PTR
+BIO_METHOD * T_PTR
+EVP_PKEY * T_PTR
+const EVP_MD * T_PTR
+CERT * T_PTR
+LHASH * T_PTR
+struct lhash_st_SSL_SESSION * T_PTR
+struct cert_st * T_PTR
+X509_STORE_CTX * T_PTR
+ASN1_UTCTIME * T_PTR
+ASN1_OCTET_STRING * T_PTR
+EVP_PKEY * T_PTR
const char * T_PV
const unsigned char * T_PV
-CRYPTO_EX_new * T_IV
-CRYPTO_EX_dup * T_IV
-CRYPTO_EX_free * T_IV
-SSL_CIPHER * T_IV
-int * T_IV
-COMP_METHOD * T_IV
-X509_STORE * T_IV
-X509_NAME_STACK * T_IV
-X509_VERIFY_PARAM * T_IV
-X509_POLICY_LEVEL * T_IV
-X509_POLICY_TREE * T_IV
-X509_POLICY_NODE * T_IV
-STACK_OF(X509_POLICY_NODE) * T_IV
-STACK_OF(POLICYQUALINFO) * T_IV
-ASN1_OBJECT * T_IV
-STACK_OF(ASN1_OBJECT) * T_IV
-ENGINE * T_IV
-pem_password_cb * T_IV
-generate_key_cb * T_IV
-callback_ret_int * T_IV
-callback_no_ret * T_IV
-cb_ssl_int_int_ret_void * T_IV
-cb_ssl_int_int_ret_RSA * T_IV
-cb_ssl_int_int_ret_DH * T_IV
+CRYPTO_EX_new * T_PTR
+CRYPTO_EX_dup * T_PTR
+CRYPTO_EX_free * T_PTR
+SSL_CIPHER * T_PTR
+int * T_PTR
+COMP_METHOD * T_PTR
+X509_STORE * T_PTR
+X509_NAME_STACK * T_PTR
+X509_VERIFY_PARAM * T_PTR
+X509_POLICY_LEVEL * T_PTR
+X509_POLICY_TREE * T_PTR
+X509_POLICY_NODE * T_PTR
+STACK_OF(X509_POLICY_NODE) * T_PTR
+STACK_OF(POLICYQUALINFO) * T_PTR
+ASN1_OBJECT * T_PTR
+STACK_OF(ASN1_OBJECT) * T_PTR
+ENGINE * T_PTR
+pem_password_cb * T_PTR
+generate_key_cb * T_PTR
+callback_ret_int * T_PTR
+callback_no_ret * T_PTR
+cb_ssl_int_int_ret_void * T_PTR
+cb_ssl_int_int_ret_RSA * T_PTR
+cb_ssl_int_int_ret_DH * T_PTR
perl_filehandle_t T_PERL_IO_HANDLE
INPUT
--
1.7.6.msysgit.0