From 327129404bea6b1fe63747ce96b8fafb42aabcd6 Mon Sep 17 00:00:00 2001 From: Roumen Petrov Date: Sat, 2 Mar 2013 13:12:49 +0200 Subject: [PATCH 11/24] MINGW: setup _ctypes module with system libffi --- Modules/_ctypes/callproc.c | 21 +++++++++++++++++++++ setup.py | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index ead1c6f..e9bfd6e 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -727,6 +727,21 @@ ffi_type *_ctypes_get_ffi_type(PyObject *obj) } +#undef USE_PYFFI_DELTA +#ifdef MS_WIN32 +#ifdef X86_ANY +/* NOTE: + * - Standard library does not calculate stack pointer difference + * unlike python specific for MSVC source. + * - As X86_ANY is defined in standard libffi only we will use as flag + * to distinguish between standard and customized sources. + */ +#else +/* use customized python libffi source */ +# define USE_PYFFI_DELTA +#endif +#endif + /* * libffi uses: * @@ -755,7 +770,9 @@ static int _call_function_pointer(int flags, ffi_cif cif; int cc; #ifdef MS_WIN32 +#ifdef USE_PYFFI_DELTA int delta; +#endif /* USE_PYFFI_DELTA */ #ifndef DONT_USE_SEH DWORD dwExceptionCode = 0; EXCEPTION_RECORD record; @@ -806,7 +823,9 @@ static int _call_function_pointer(int flags, #ifndef DONT_USE_SEH __try { #endif +#ifdef USE_PYFFI_DELTA delta = +#endif /* USE_PYFFI_DELTA */ #endif ffi_call(&cif, (void *)pProc, resmem, avalues); #ifdef MS_WIN32 @@ -840,6 +859,7 @@ static int _call_function_pointer(int flags, return -1; } #endif +#ifdef USE_PYFFI_DELTA #ifdef MS_WIN64 if (delta != 0) { PyErr_Format(PyExc_RuntimeError, @@ -869,6 +889,7 @@ static int _call_function_pointer(int flags, return -1; } #endif +#endif /* USE_PYFFI_DELTA */ #endif if ((flags & FUNCFLAG_PYTHONAPI) && PyErr_Occurred()) return -1; diff --git a/setup.py b/setup.py index c95c5f6..d723f18 100644 --- a/setup.py +++ b/setup.py @@ -1881,6 +1881,8 @@ class PyBuildExt(build_ext): depends=depends) ext_test = Extension('_ctypes_test', sources=['_ctypes/_ctypes_test.c']) + if host_platform.startswith(('mingw', 'win')): + ext_test.libraries.extend(['oleaut32']) self.extensions.extend([ext, ext_test]) if not '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS"): @@ -1914,6 +1916,8 @@ class PyBuildExt(build_ext): if ffi_inc and ffi_lib: ext.include_dirs.extend(ffi_inc) ext.libraries.append(ffi_lib) + if host_platform.startswith(('mingw', 'win')): + ext.libraries.extend(['ole32', 'oleaut32', 'uuid']) self.use_system_libffi = True def _decimal_ext(self): -- 1.7.12.1