From 4045392e0e3446362841b3336497cb6eeccfcd23 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Sat, 4 Dec 2021 12:21:43 +0200 Subject: bpo-45847: Port _ctypes partly to PY_STDLIB_MOD (GH-29747) Co-authored-by: Erlend Egeberg Aasland --- Modules/Setup.stdlib.in | 4 + configure | 382 +++++++++++++++++++++++++++++++++++++++++++++++- configure.ac | 61 +++++++- pyconfig.h.in | 12 ++ setup.py | 59 ++++---- 5 files changed, 482 insertions(+), 36 deletions(-) diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in index 9dfe918..ff92db3 100644 --- a/Modules/Setup.stdlib.in +++ b/Modules/Setup.stdlib.in @@ -130,6 +130,10 @@ ############################################################################ # Modules with third party dependencies # + +# needs -lffi and -ldl +@MODULE__CTYPES_TRUE@_ctypes _ctypes/_ctypes.c _ctypes/callbacks.c _ctypes/callproc.c _ctypes/stgdict.c _ctypes/cfield.c + @MODULE__SQLITE3_TRUE@_sqlite3 _sqlite/connection.c _sqlite/cursor.c _sqlite/microprotocols.c _sqlite/module.c _sqlite/prepare_protocol.c _sqlite/row.c _sqlite/statement.c _sqlite/util.c # needs -lssl and -lcrypt diff --git a/configure b/configure index 5d47d03..8582224 100755 --- a/configure +++ b/configure @@ -664,6 +664,8 @@ MODULE__GDBM_FALSE MODULE__GDBM_TRUE MODULE__DECIMAL_FALSE MODULE__DECIMAL_TRUE +MODULE__CTYPES_FALSE +MODULE__CTYPES_TRUE MODULE__CRYPT_FALSE MODULE__CRYPT_TRUE MODULE__BLAKE2_FALSE @@ -828,6 +830,8 @@ LIBMPDEC_INTERNAL LIBMPDEC_LDFLAGS LIBMPDEC_CFLAGS LIBFFI_INCLUDEDIR +LIBFFI_LIBS +LIBFFI_CFLAGS LIBEXPAT_INTERNAL LIBEXPAT_LDFLAGS LIBEXPAT_CFLAGS @@ -1060,6 +1064,8 @@ CPP PROFILE_TASK LIBUUID_CFLAGS LIBUUID_LIBS +LIBFFI_CFLAGS +LIBFFI_LIBS LIBNSL_CFLAGS LIBNSL_LIBS LIBSQLITE3_CFLAGS @@ -1857,6 +1863,9 @@ Some influential environment variables: C compiler flags for LIBUUID, overriding pkg-config LIBUUID_LIBS linker flags for LIBUUID, overriding pkg-config + LIBFFI_CFLAGS + C compiler flags for LIBFFI, overriding pkg-config + LIBFFI_LIBS linker flags for LIBFFI, overriding pkg-config LIBNSL_CFLAGS C compiler flags for LIBNSL, overriding pkg-config LIBNSL_LIBS linker flags for LIBNSL, overriding pkg-config @@ -11375,6 +11384,335 @@ $as_echo "$as_me: WARNING: --with(out)-system-ffi is ignored on this platform" > with_system_ffi="yes" fi +have_libffi=missing +if test "x$with_system_ffi" = xyes; then : + + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LIBFFI" >&5 +$as_echo_n "checking for LIBFFI... " >&6; } + +if test -n "$LIBFFI_CFLAGS"; then + pkg_cv_LIBFFI_CFLAGS="$LIBFFI_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libffi\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libffi") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_LIBFFI_CFLAGS=`$PKG_CONFIG --cflags "libffi" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$LIBFFI_LIBS"; then + pkg_cv_LIBFFI_LIBS="$LIBFFI_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libffi\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libffi") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_LIBFFI_LIBS=`$PKG_CONFIG --libs "libffi" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + LIBFFI_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libffi" 2>&1` + else + LIBFFI_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libffi" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$LIBFFI_PKG_ERRORS" >&5 + + + ac_fn_c_check_header_mongrel "$LINENO" "ffi.h" "ac_cv_header_ffi_h" "$ac_includes_default" +if test "x$ac_cv_header_ffi_h" = xyes; then : + + save_CFLAGS=$CFLAGS +save_CPPFLAGS=$CPPFLAGS +save_LDFLAGS=$LDFLAGS +save_LIBS=$LIBS + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ffi_call in -lffi" >&5 +$as_echo_n "checking for ffi_call in -lffi... " >&6; } +if ${ac_cv_lib_ffi_ffi_call+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lffi $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char ffi_call (); +int +main () +{ +return ffi_call (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_ffi_ffi_call=yes +else + ac_cv_lib_ffi_ffi_call=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ffi_ffi_call" >&5 +$as_echo "$ac_cv_lib_ffi_ffi_call" >&6; } +if test "x$ac_cv_lib_ffi_ffi_call" = xyes; then : + have_libffi=yes +else + have_libffi=no +fi + + +CFLAGS=$save_CFLAGS +CPPFLAGS=$save_CPPFLAGS +LDFLAGS=$save_LDFLAGS +LIBS=$save_LIBS + + + +fi + + + +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + + ac_fn_c_check_header_mongrel "$LINENO" "ffi.h" "ac_cv_header_ffi_h" "$ac_includes_default" +if test "x$ac_cv_header_ffi_h" = xyes; then : + + save_CFLAGS=$CFLAGS +save_CPPFLAGS=$CPPFLAGS +save_LDFLAGS=$LDFLAGS +save_LIBS=$LIBS + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ffi_call in -lffi" >&5 +$as_echo_n "checking for ffi_call in -lffi... " >&6; } +if ${ac_cv_lib_ffi_ffi_call+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lffi $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char ffi_call (); +int +main () +{ +return ffi_call (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_ffi_ffi_call=yes +else + ac_cv_lib_ffi_ffi_call=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ffi_ffi_call" >&5 +$as_echo "$ac_cv_lib_ffi_ffi_call" >&6; } +if test "x$ac_cv_lib_ffi_ffi_call" = xyes; then : + have_libffi=yes +else + have_libffi=no +fi + + +CFLAGS=$save_CFLAGS +CPPFLAGS=$save_CPPFLAGS +LDFLAGS=$save_LDFLAGS +LIBS=$save_LIBS + + + +fi + + + +else + LIBFFI_CFLAGS=$pkg_cv_LIBFFI_CFLAGS + LIBFFI_LIBS=$pkg_cv_LIBFFI_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + have_libffi=yes +fi + +else + + have_libffi=yes + LIBFFI_CFLAGS="-I\$(srcdir)/Modules/_ctypes/darwin -DUSING_MALLOC_CLOSURE_DOT_C=1 -DMACOSX" + LIBFFI_LIBS= + +fi + +case $LIBS in #( + *-ldl*) : + LIBFFI_LIBS="$LIBFFI_LIBS -ldl" + ;; #( + *) : + ;; +esac + +if test "$with_system_ffi" = yes -a "$have_libffi" = yes; then + save_CFLAGS=$CFLAGS +save_CPPFLAGS=$CPPFLAGS +save_LDFLAGS=$LDFLAGS +save_LIBS=$LIBS + + + CFLAGS="$LIBFFI_CFLAGS $CFLAGS" + LIBS="$LIBFFI_LIBS $LIBS" + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ffi_prep_cif_var in ffi.h" >&5 +$as_echo_n "checking for ffi_prep_cif_var in ffi.h... " >&6; } +if ${ac_cv_ffi_prep_cif_var+:} false; then : + $as_echo_n "(cached) " >&6 +else + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "ffi_prep_cif_var" >/dev/null 2>&1; then : + ac_cv_ffi_prep_cif_var=yes +else + ac_cv_ffi_prep_cif_var=no +fi +rm -f conftest* + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_ffi_prep_cif_var" >&5 +$as_echo "$ac_cv_ffi_prep_cif_var" >&6; } + if test "x$ac_cv_ffi_prep_cif_var" = xyes; then : + + +$as_echo "#define HAVE_FFI_PREP_CIF_VAR 1" >>confdefs.h + + +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ffi_prep_closure_loc in ffi.h" >&5 +$as_echo_n "checking for ffi_prep_closure_loc in ffi.h... " >&6; } +if ${ac_cv_ffi_prep_closure_loc+:} false; then : + $as_echo_n "(cached) " >&6 +else + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "ffi_prep_closure_loc" >/dev/null 2>&1; then : + ac_cv_ffi_prep_closure_loc=yes +else + ac_cv_ffi_prep_closure_loc=no +fi +rm -f conftest* + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_ffi_prep_closure_loc" >&5 +$as_echo "$ac_cv_ffi_prep_closure_loc" >&6; } + if test "x$ac_cv_ffi_prep_closure_loc" = xyes; then : + + +$as_echo "#define HAVE_FFI_PREP_CLOSURE_LOC 1" >>confdefs.h + + +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ffi_closure_alloc in ffi.h" >&5 +$as_echo_n "checking for ffi_closure_alloc in ffi.h... " >&6; } +if ${ac_cv_ffi_closure_alloc+:} false; then : + $as_echo_n "(cached) " >&6 +else + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "ffi_closure_alloc" >/dev/null 2>&1; then : + ac_cv_ffi_closure_alloc=yes +else + ac_cv_ffi_closure_alloc=no +fi +rm -f conftest* + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_ffi_closure_alloc" >&5 +$as_echo "$ac_cv_ffi_closure_alloc" >&6; } + if test "x$ac_cv_ffi_closure_alloc" = xyes; then : + + +$as_echo "#define HAVE_FFI_CLOSURE_ALLOC 1" >>confdefs.h + + +fi + +CFLAGS=$save_CFLAGS +CPPFLAGS=$save_CPPFLAGS +LDFLAGS=$save_LDFLAGS +LIBS=$save_LIBS + + +fi + + if test "$with_system_ffi" = "yes" && test -n "$PKG_CONFIG"; then LIBFFI_INCLUDEDIR="`"$PKG_CONFIG" libffi --cflags-only-I 2>/dev/null | sed -e 's/^-I//;s/ *$//'`" else @@ -22726,6 +23064,42 @@ fi $as_echo "$py_cv_module__crypt" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdlib extension module _ctypes" >&5 +$as_echo_n "checking for stdlib extension module _ctypes... " >&6; } + case $py_stdlib_not_available in #( + *_ctypes*) : + py_cv_module__ctypes=n/a ;; #( + *) : + if true; then : + if test "$have_libffi" = yes; then : + py_cv_module__ctypes=yes +else + py_cv_module__ctypes=missing +fi +else + py_cv_module__ctypes=disabled +fi + ;; +esac + as_fn_append MODULE_BLOCK "MODULE__CTYPES=$py_cv_module__ctypes$as_nl" + if test "x$py_cv_module__ctypes" = xyes; then : + + as_fn_append MODULE_BLOCK "MODULE__CTYPES_CFLAGS=$LIBFFI_CFLAGS$as_nl" + as_fn_append MODULE_BLOCK "MODULE__CTYPES_LDFLAGS=$LIBFFI_LIBS$as_nl" + +fi + if test "$py_cv_module__ctypes" = yes; then + MODULE__CTYPES_TRUE= + MODULE__CTYPES_FALSE='#' +else + MODULE__CTYPES_TRUE='#' + MODULE__CTYPES_FALSE= +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $py_cv_module__ctypes" >&5 +$as_echo "$py_cv_module__ctypes" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdlib extension module _decimal" >&5 $as_echo_n "checking for stdlib extension module _decimal... " >&6; } case $py_stdlib_not_available in #( @@ -23336,7 +23710,7 @@ $as_echo_n "checking for stdlib extension module _ctypes_test... " >&6; } py_cv_module__ctypes_test=n/a ;; #( *) : if test "$TEST_MODULES" = yes; then : - if true; then : + if test "$have_libffi" = yes; then : py_cv_module__ctypes_test=yes else py_cv_module__ctypes_test=missing @@ -23350,7 +23724,7 @@ esac if test "x$py_cv_module__ctypes_test" = xyes; then : - as_fn_append MODULE_BLOCK "MODULE__CTYPES_TEST_LDFLAGS=-lm$as_nl" + as_fn_append MODULE_BLOCK "MODULE__CTYPES_TEST_LDFLAGS=$LIBM$as_nl" fi if test "$py_cv_module__ctypes_test" = yes; then @@ -23774,6 +24148,10 @@ if test -z "${MODULE__CRYPT_TRUE}" && test -z "${MODULE__CRYPT_FALSE}"; then as_fn_error $? "conditional \"MODULE__CRYPT\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi +if test -z "${MODULE__CTYPES_TRUE}" && test -z "${MODULE__CTYPES_FALSE}"; then + as_fn_error $? "conditional \"MODULE__CTYPES\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi if test -z "${MODULE__DECIMAL_TRUE}" && test -z "${MODULE__DECIMAL_FALSE}"; then as_fn_error $? "conditional \"MODULE__DECIMAL\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 diff --git a/configure.ac b/configure.ac index b35c92a..40dc6f4 100644 --- a/configure.ac +++ b/configure.ac @@ -3175,6 +3175,60 @@ else with_system_ffi="yes" fi +dnl detect libffi +have_libffi=missing +AS_VAR_IF([with_system_ffi], [yes], [ + PKG_CHECK_MODULES([LIBFFI], [libffi], [have_libffi=yes], [ + AC_CHECK_HEADER([ffi.h], [ + WITH_SAVE_ENV([ + AC_CHECK_LIB([ffi], [ffi_call], [have_libffi=yes], [have_libffi=no]) + ]) + ]) + ]) +], [ + dnl private ffi copy + have_libffi=yes + LIBFFI_CFLAGS="-I\$(srcdir)/Modules/_ctypes/darwin -DUSING_MALLOC_CLOSURE_DOT_C=1 -DMACOSX" + LIBFFI_LIBS= +]) + +dnl _ctypes needs -ldl for dlopen +AS_CASE([$LIBS], + [*-ldl*], [LIBFFI_LIBS="$LIBFFI_LIBS -ldl"] +) + +if test "$with_system_ffi" = yes -a "$have_libffi" = yes; then + WITH_SAVE_ENV([ + CFLAGS="$LIBFFI_CFLAGS $CFLAGS" + LIBS="$LIBFFI_LIBS $LIBS" + + AC_CACHE_CHECK([for ffi_prep_cif_var in ffi.h], [ac_cv_ffi_prep_cif_var], [ + AC_EGREP_HEADER([ffi_prep_cif_var], [ffi.h], [ac_cv_ffi_prep_cif_var=yes], [ac_cv_ffi_prep_cif_var=no]) + ]) + AS_VAR_IF([ac_cv_ffi_prep_cif_var], [yes], [ + AC_DEFINE([HAVE_FFI_PREP_CIF_VAR], [1], + [Define to 1 if you have the ffi_prep_cif_var function in header file.]) + ]) + + AC_CACHE_CHECK([for ffi_prep_closure_loc in ffi.h], [ac_cv_ffi_prep_closure_loc], [ + AC_EGREP_HEADER([ffi_prep_closure_loc], [ffi.h], [ac_cv_ffi_prep_closure_loc=yes], [ac_cv_ffi_prep_closure_loc=no]) + ]) + AS_VAR_IF([ac_cv_ffi_prep_closure_loc], [yes], [ + AC_DEFINE([HAVE_FFI_PREP_CLOSURE_LOC], [1], + [Define to 1 if you have the ffi_prep_closure_loc function in header file.]) + ]) + + AC_CACHE_CHECK([for ffi_closure_alloc in ffi.h], [ac_cv_ffi_closure_alloc], [ + AC_EGREP_HEADER([ffi_closure_alloc], [ffi.h], [ac_cv_ffi_closure_alloc=yes], [ac_cv_ffi_closure_alloc=no]) + ]) + AS_VAR_IF([ac_cv_ffi_closure_alloc], [yes], [ + AC_DEFINE([HAVE_FFI_CLOSURE_ALLOC], [1], + [Define to 1 if you have the ffi_closure_alloc function in header file.]) + ]) + ]) +fi + + if test "$with_system_ffi" = "yes" && test -n "$PKG_CONFIG"; then LIBFFI_INCLUDEDIR="`"$PKG_CONFIG" libffi --cflags-only-I 2>/dev/null | sed -e 's/^-I//;s/ *$//'`" else @@ -6423,6 +6477,9 @@ PY_STDLIB_MOD([_blake2], [test "$with_builtin_blake2" = yes]) PY_STDLIB_MOD([_crypt], [], [test "$ac_cv_crypt_crypt" = yes], [$LIBCRYPT_CFLAGS], [$LIBCRYPT_LIBS]) +PY_STDLIB_MOD([_ctypes], + [], [test "$have_libffi" = yes], + [$LIBFFI_CFLAGS], [$LIBFFI_LIBS]) PY_STDLIB_MOD([_decimal], [], [], [$LIBMPDEC_CFLAGS], [$LIBMPDEC_LDFLAGS]) PY_STDLIB_MOD([_gdbm], [test "$have_gdbm_dbmliborder" = yes], [test "$have_gdbm" = yes], @@ -6461,7 +6518,9 @@ PY_STDLIB_MOD([_testbuffer], [test "$TEST_MODULES" = yes]) PY_STDLIB_MOD([_testimportmultiple], [test "$TEST_MODULES" = yes]) PY_STDLIB_MOD([_testmultiphase], [test "$TEST_MODULES" = yes]) PY_STDLIB_MOD([_xxtestfuzz], [test "$TEST_MODULES" = yes]) -PY_STDLIB_MOD([_ctypes_test], [test "$TEST_MODULES" = yes], [], [], [-lm]) +PY_STDLIB_MOD([_ctypes_test], + [test "$TEST_MODULES" = yes], [test "$have_libffi" = yes], + [], [$LIBM]) dnl Limited API template modules. dnl The limited C API is not compatible with the Py_TRACE_REFS macro. diff --git a/pyconfig.h.in b/pyconfig.h.in index efad243..c6cc1fd 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -356,6 +356,18 @@ /* Define to 1 if you have the `fexecve' function. */ #undef HAVE_FEXECVE +/* Define to 1 if you have the ffi_closure_alloc function in header + file. */ +#undef HAVE_FFI_CLOSURE_ALLOC + +/* Define to 1 if you have the ffi_prep_cif_var function in header + file. */ +#undef HAVE_FFI_PREP_CIF_VAR + +/* Define to 1 if you have the ffi_prep_closure_loc function in header + file. */ +#undef HAVE_FFI_PREP_CLOSURE_LOC + /* Define to 1 if you have the `flock' function. */ #undef HAVE_FLOCK diff --git a/setup.py b/setup.py index 572f2ac..ca5d077 100644 --- a/setup.py +++ b/setup.py @@ -669,12 +669,6 @@ class PyBuildExt(build_ext): raise RuntimeError("Failed to build some stdlib modules") def build_extension(self, ext): - - if ext.name == '_ctypes': - if not self.configure_ctypes(ext): - self.failed.append(ext.name) - return - try: build_ext.build_extension(self, ext) except (CCompilerError, DistutilsError) as why: @@ -1738,10 +1732,26 @@ class PyBuildExt(build_ext): library_dirs=added_lib_dirs)) return True - def configure_ctypes(self, ext): - return True - def detect_ctypes(self): + ext = Extension( + '_ctypes', + [ + '_ctypes/_ctypes.c', + '_ctypes/callbacks.c', + '_ctypes/callproc.c', + '_ctypes/stgdict.c', + '_ctypes/cfield.c', + ] + ) + if MACOS: + self._build_ctypes_macos(ext) + else: + self.use_system_libffi = True + self.addext(ext) + + self.addext(Extension('_ctypes_test', ['_ctypes/_ctypes_test.c'])) + + def _build_ctypes_macos(self, ext): # Thomas Heller's _ctypes module if (not sysconfig.get_config_var("LIBFFI_INCLUDEDIR") and MACOS): @@ -1749,20 +1759,11 @@ class PyBuildExt(build_ext): else: self.use_system_libffi = '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS") - include_dirs = [] - extra_compile_args = [] - extra_link_args = [] - sources = ['_ctypes/_ctypes.c', - '_ctypes/callbacks.c', - '_ctypes/callproc.c', - '_ctypes/stgdict.c', - '_ctypes/cfield.c'] - if MACOS: - sources.append('_ctypes/malloc_closure.c') - extra_compile_args.append('-DUSING_MALLOC_CLOSURE_DOT_C=1') - extra_compile_args.append('-DMACOSX') - include_dirs.append('_ctypes/darwin') + ext.sources.append('_ctypes/malloc_closure.c') + ext.extra_compile_args.append('-DUSING_MALLOC_CLOSURE_DOT_C=1') + ext.extra_compile_args.append('-DMACOSX') + ext.include_dirs.append('_ctypes/darwin') elif HOST_PLATFORM == 'sunos5': # XXX This shouldn't be necessary; it appears that some @@ -1773,20 +1774,12 @@ class PyBuildExt(build_ext): # this option. If you want to compile ctypes with the Sun # compiler, please research a proper solution, instead of # finding some -z option for the Sun compiler. - extra_link_args.append('-mimpure-text') + ext.extra_link_args.append('-mimpure-text') elif HOST_PLATFORM.startswith('hp-ux'): - extra_link_args.append('-fPIC') - - ext = Extension('_ctypes', - include_dirs=include_dirs, - extra_compile_args=extra_compile_args, - extra_link_args=extra_link_args, - libraries=[], - sources=sources) + ext.extra_link_args.append('-fPIC') + self.add(ext) - # function my_sqrt() needs libm for sqrt() - self.addext(Extension('_ctypes_test', ['_ctypes/_ctypes_test.c'])) ffi_inc = sysconfig.get_config_var("LIBFFI_INCLUDEDIR") ffi_lib = None -- cgit v0.12