summaryrefslogtreecommitdiffstats
path: root/setup.py
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2021-12-04 10:21:43 (GMT)
committerGitHub <noreply@github.com>2021-12-04 10:21:43 (GMT)
commit4045392e0e3446362841b3336497cb6eeccfcd23 (patch)
treead93651b416d5fb070044047f26a64bcc816226e /setup.py
parentcee07b162843694e8166ad8715162d4d5886b50f (diff)
downloadcpython-4045392e0e3446362841b3336497cb6eeccfcd23.zip
cpython-4045392e0e3446362841b3336497cb6eeccfcd23.tar.gz
cpython-4045392e0e3446362841b3336497cb6eeccfcd23.tar.bz2
bpo-45847: Port _ctypes partly to PY_STDLIB_MOD (GH-29747)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py59
1 files changed, 26 insertions, 33 deletions
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