Skip to content

Commit cf567c1

Browse files
author
Thomas Heller
committed
Changes to build the _ctypes extension module.
Based on a patch from Hye-Shik Chang.
1 parent d4c9320 commit cf567c1

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

Makefile.pre.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ PLATMACPATH=:plat-mac:plat-mac/lib-scriptpackages
677677
LIBSUBDIRS= lib-old lib-tk site-packages test test/output test/data \
678678
test/decimaltestdata \
679679
encodings email email/test email/test/data compiler hotshot \
680-
logging bsddb bsddb/test csv idlelib idlelib/Icons \
680+
logging bsddb bsddb/test csv ctypes idlelib idlelib/Icons \
681681
distutils distutils/command distutils/tests $(XMLLIBSUBDIRS) \
682682
curses $(MACHDEPS)
683683
libinstall: $(BUILDPYTHON) $(srcdir)/Lib/$(PLATDIR)

setup.py

+58
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,9 @@ class db_found(Exception): pass
888888
if (dl_inc is not None) and (platform not in ['atheos', 'darwin']):
889889
exts.append( Extension('dl', ['dlmodule.c']) )
890890

891+
# Thomas Heller's _ctypes module
892+
self.detect_ctypes()
893+
891894
# Platform-specific libraries
892895
if platform == 'linux2':
893896
# Linux-specific modules
@@ -1180,6 +1183,61 @@ def detect_tkinter(self, inc_dirs, lib_dirs):
11801183
# *** Uncomment these for TOGL extension only:
11811184
# -lGL -lGLU -lXext -lXmu \
11821185

1186+
def detect_ctypes(self):
1187+
(srcdir,) = sysconfig.get_config_vars('srcdir')
1188+
ffi_builddir = os.path.join(self.build_temp, 'libffi')
1189+
ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
1190+
'_ctypes', 'libffi'))
1191+
ffi_configfile = os.path.join(ffi_builddir, 'fficonfig.py')
1192+
1193+
if self.force or not os.path.exists(ffi_configfile):
1194+
from distutils.dir_util import mkpath
1195+
mkpath(ffi_builddir)
1196+
config_args = []
1197+
1198+
# Pass empty CFLAGS because we'll just append the resulting CFLAGS
1199+
# to Python's; -g or -O2 is to be avoided.
1200+
cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \
1201+
% (ffi_builddir, ffi_srcdir, " ".join(config_args))
1202+
1203+
res = os.system(cmd)
1204+
if res or not os.path.exists(ffi_configfile):
1205+
print "Failed to configure _ctypes module"
1206+
return
1207+
1208+
fficonfig = {}
1209+
execfile(ffi_configfile, globals(), fficonfig)
1210+
ffi_srcdir = os.path.join(fficonfig['ffi_srcdir'], 'src')
1211+
1212+
# Add .S (preprocessed assembly) to C compiler source extensions.
1213+
self.compiler.src_extensions.append('.S')
1214+
1215+
include_dirs = [os.path.join(ffi_builddir, 'include'),
1216+
ffi_builddir, ffi_srcdir]
1217+
extra_compile_args = fficonfig['ffi_cflags'].split()
1218+
sources = ['_ctypes/_ctypes.c',
1219+
'_ctypes/callbacks.c',
1220+
'_ctypes/callproc.c',
1221+
'_ctypes/stgdict.c',
1222+
'_ctypes/cfield.c',
1223+
'_ctypes/malloc_closure.c'] + fficonfig['ffi_sources']
1224+
depends = ['_ctypes/ctypes.h']
1225+
1226+
if sys.platform == 'darwin':
1227+
sources.append('_ctypes/darwin/dlfcn_simple.c')
1228+
include_dirs.append('_ctypes/darwin')
1229+
# XXX Is this still needed?
1230+
## extra_link_args.extend(['-read_only_relocs', 'warning'])
1231+
1232+
ext = Extension('_ctypes',
1233+
include_dirs=include_dirs,
1234+
extra_compile_args=extra_compile_args,
1235+
sources=sources,
1236+
depends=depends)
1237+
ext_test = Extension('_ctypes_test',
1238+
sources=['_ctypes/_ctypes_test.c'])
1239+
self.extensions.extend([ext, ext_test])
1240+
11831241
class PyBuildInstall(install):
11841242
# Suppress the warning about installation into the lib_dynload
11851243
# directory, which is not in sys.path when running Python during

0 commit comments

Comments
 (0)