Patrick Williams | d849ec7 | 2016-08-17 14:59:38 -0500 | [diff] [blame] | 1 | From 8430e7202407fb1a0a104b0decdcc9da9e41a52b Mon Sep 17 00:00:00 2001 |
| 2 | From: Jackie Huang <jackie.huang@windriver.com> |
| 3 | Date: Mon, 4 Apr 2016 23:28:15 -0400 |
| 4 | Subject: [PATCH] Fix build with SWIG 3.0.5 |
| 5 | |
| 6 | See analysis and previous patches in |
| 7 | https://github.com/martinpaljak/M2Crypto/issues/60 and |
| 8 | https://github.com/swig/swig/issues/344, in particular this adds the |
| 9 | build machinery to patch |
| 10 | https://github.com/martinpaljak/M2Crypto/issues/60#issuecomment-75735489 |
| 11 | |
| 12 | Fixes #47 |
| 13 | |
| 14 | Author: Miloslav Trmac <mitr@redhat.com> |
| 15 | |
| 16 | Upstream-Status: Backport |
| 17 | |
| 18 | Signed-off-by: Jackie Huang <jackie.huang@windriver.com> |
| 19 | --- |
| 20 | M2Crypto/__init__.py | 4 ++-- |
| 21 | M2Crypto/m2.py | 2 +- |
| 22 | SWIG/_lib.i | 4 ++++ |
| 23 | SWIG/_pkcs7.i | 1 + |
| 24 | setup.py | 24 ++++++++++++++++++++++++ |
| 25 | 5 files changed, 32 insertions(+), 3 deletions(-) |
| 26 | |
| 27 | diff --git a/M2Crypto/__init__.py b/M2Crypto/__init__.py |
| 28 | index 647e057..280af94 100644 |
| 29 | --- a/M2Crypto/__init__.py |
| 30 | +++ b/M2Crypto/__init__.py |
| 31 | @@ -19,7 +19,7 @@ Copyright 2008-2011 Heikki Toivonen. All rights reserved. |
| 32 | version_info = (0, 22) |
| 33 | version = '.'.join([str(_v) for _v in version_info]) |
| 34 | |
| 35 | -import __m2crypto |
| 36 | +import _m2crypto |
| 37 | import m2 |
| 38 | import ASN1 |
| 39 | import AuthCookie |
| 40 | @@ -47,4 +47,4 @@ import m2xmlrpclib |
| 41 | import threading |
| 42 | import util |
| 43 | |
| 44 | -__m2crypto.lib_init() |
| 45 | +_m2crypto.lib_init() |
| 46 | diff --git a/M2Crypto/m2.py b/M2Crypto/m2.py |
| 47 | index e4bb695..822143f 100644 |
| 48 | --- a/M2Crypto/m2.py |
| 49 | +++ b/M2Crypto/m2.py |
| 50 | @@ -25,7 +25,7 @@ Portions created by Open Source Applications Foundation (OSAF) are |
| 51 | Copyright (C) 2004 OSAF. All Rights Reserved. |
| 52 | """ |
| 53 | |
| 54 | -from __m2crypto import * |
| 55 | +from _m2crypto import * |
| 56 | lib_init() |
| 57 | |
| 58 | |
| 59 | diff --git a/SWIG/_lib.i b/SWIG/_lib.i |
| 60 | index 0d40698..6cc1a44 100644 |
| 61 | --- a/SWIG/_lib.i |
| 62 | +++ b/SWIG/_lib.i |
| 63 | @@ -66,6 +66,7 @@ int ssl_verify_callback(int ok, X509_STORE_CTX *ctx) { |
| 64 | int cret; |
| 65 | int new_style_callback = 0, warning_raised_exception=0; |
| 66 | PyGILState_STATE gilstate; |
| 67 | + PyObject *self = NULL; /* bug in SWIG_NewPointerObj as of 3.0.5 */ |
| 68 | |
| 69 | ssl = (SSL *)X509_STORE_CTX_get_app_data(ctx); |
| 70 | |
| 71 | @@ -151,6 +152,7 @@ int ssl_verify_callback(int ok, X509_STORE_CTX *ctx) { |
| 72 | void ssl_info_callback(const SSL *s, int where, int ret) { |
| 73 | PyObject *argv, *retval, *_SSL; |
| 74 | PyGILState_STATE gilstate; |
| 75 | + PyObject *self = NULL; /* bug in SWIG_NewPointerObj as of 3.0.5 */ |
| 76 | |
| 77 | gilstate = PyGILState_Ensure(); |
| 78 | |
| 79 | @@ -170,6 +172,7 @@ DH *ssl_set_tmp_dh_callback(SSL *ssl, int is_export, int keylength) { |
| 80 | PyObject *argv, *ret, *_ssl; |
| 81 | DH *dh; |
| 82 | PyGILState_STATE gilstate; |
| 83 | + PyObject *self = NULL; /* bug in SWIG_NewPointerObj as of 3.0.5 */ |
| 84 | |
| 85 | gilstate = PyGILState_Ensure(); |
| 86 | |
| 87 | @@ -193,6 +196,7 @@ RSA *ssl_set_tmp_rsa_callback(SSL *ssl, int is_export, int keylength) { |
| 88 | PyObject *argv, *ret, *_ssl; |
| 89 | RSA *rsa; |
| 90 | PyGILState_STATE gilstate; |
| 91 | + PyObject *self = NULL; /* bug in SWIG_NewPointerObj as of 3.0.5 */ |
| 92 | |
| 93 | gilstate = PyGILState_Ensure(); |
| 94 | |
| 95 | diff --git a/SWIG/_pkcs7.i b/SWIG/_pkcs7.i |
| 96 | index 22d791a..20dfbaf 100644 |
| 97 | --- a/SWIG/_pkcs7.i |
| 98 | +++ b/SWIG/_pkcs7.i |
| 99 | @@ -157,6 +157,7 @@ PyObject *smime_read_pkcs7(BIO *bio) { |
| 100 | BIO *bcont = NULL; |
| 101 | PKCS7 *p7; |
| 102 | PyObject *tuple, *_p7, *_BIO; |
| 103 | + PyObject *self = NULL; /* bug in SWIG_NewPointerObj as of 3.0.5 */ |
| 104 | |
| 105 | if (BIO_method_type(bio) == BIO_TYPE_MEM) { |
| 106 | /* OpenSSL FAQ explains that this is needed for mem BIO to return EOF, |
| 107 | diff --git a/setup.py b/setup.py |
| 108 | index bac6f9f..f59dc18 100644 |
| 109 | --- a/setup.py |
| 110 | +++ b/setup.py |
| 111 | @@ -19,6 +19,7 @@ from setuptools.command import build_ext |
| 112 | |
| 113 | from distutils.core import Extension |
| 114 | from distutils.spawn import find_executable |
| 115 | +from distutils.file_util import copy_file |
| 116 | |
| 117 | |
| 118 | class _M2CryptoBuildExt(build_ext.build_ext): |
| 119 | @@ -77,6 +78,15 @@ class _M2CryptoBuildExt(build_ext.build_ext): |
| 120 | [opensslIncludeDir, os.path.join(opensslIncludeDir, "openssl")]] |
| 121 | self.swig_opts.append('-includeall') |
| 122 | self.swig_opts.append('-modern') |
| 123 | + self.swig_opts.append('-builtin') |
| 124 | + |
| 125 | + # These two lines are a workaround for |
| 126 | + # http://bugs.python.org/issue2624 , hard-coding that we are only |
| 127 | + # building a single extension with a known path; a proper patch to |
| 128 | + # distutils would be in the run phase, when extension name and path are |
| 129 | + # known. |
| 130 | + self.swig_opts.append('-outdir') |
| 131 | + self.swig_opts.append(os.path.join(self.build_lib, 'M2Crypto')) |
| 132 | |
| 133 | # Fedora does hat tricks. |
| 134 | if platform.linux_distribution()[0] in ['Fedora', 'CentOS']: |
| 135 | @@ -98,6 +108,20 @@ class _M2CryptoBuildExt(build_ext.build_ext): |
| 136 | |
| 137 | self.library_dirs += [os.path.join(self.openssl, opensslLibraryDir)] |
| 138 | |
| 139 | + def run(self): |
| 140 | + '''Overloaded build_ext implementation to allow inplace=1 to work, |
| 141 | + which is needed for (python setup.py test).''' |
| 142 | + # This is another workaround for http://bugs.python.org/issue2624 + the |
| 143 | + # corresponding lack of support in setuptools' test command. Note that |
| 144 | + # just using self.inplace in finalize_options() above does not work |
| 145 | + # because swig is not rerun if the __m2crypto.so extension exists. |
| 146 | + # Again, hard-coding our extension name and location. |
| 147 | + build_ext.build_ext.run(self) |
| 148 | + if self.inplace: |
| 149 | + copy_file(os.path.join(self.build_lib, 'M2Crypto', '_m2crypto.py'), |
| 150 | + os.path.join('M2Crypto', '_m2crypto.py'), |
| 151 | + verbose=self.verbose, dry_run=self.dry_run) |
| 152 | + |
| 153 | if sys.platform == 'darwin': |
| 154 | my_extra_compile_args = ["-Wno-deprecated-declarations"] |
| 155 | else: |
| 156 | -- |
| 157 | 1.9.1 |
| 158 | |