bpo-45847: Revert Port _ctypes partly to PY_STDLIB_MOD (GH-29747) (GH-29969)

This commit is contained in:
Christian Heimes 2021-12-07 21:56:41 +02:00 committed by GitHub
parent 06c4ae8b13
commit 91b59a3fcd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 478 deletions

View file

@ -669,6 +669,12 @@ 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:
@ -1732,26 +1738,10 @@ 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):
@ -1759,11 +1749,20 @@ 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:
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')
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')
elif HOST_PLATFORM == 'sunos5':
# XXX This shouldn't be necessary; it appears that some
@ -1774,12 +1773,20 @@ 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.
ext.extra_link_args.append('-mimpure-text')
extra_link_args.append('-mimpure-text')
elif HOST_PLATFORM.startswith('hp-ux'):
ext.extra_link_args.append('-fPIC')
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)
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