Skip to content

Commit e42b708

Browse files
author
martin.v.loewis
committed
Patch #1464444: Add --with-system-ffi.
git-svn-id: http://svn.python.org/projects/python/trunk@45278 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 8ee7b76 commit e42b708

File tree

4 files changed

+98
-38
lines changed

4 files changed

+98
-38
lines changed

README

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,9 @@ Modules/getpath.o.
10681068

10691069
--with-tsc: Profile using the Pentium timestamping counter (TSC).
10701070

1071+
--with-system-ffi: Build the _ctypes extension module using an ffi
1072+
library installed on the system.
1073+
10711074

10721075
Building for multiple architectures (using the VPATH feature)
10731076
-------------------------------------------------------------

configure

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/sh
2-
# From configure.in Revision: 43748 .
2+
# From configure.in Revision: 45264 .
33
# Guess values for system-dependent variables and create Makefiles.
44
# Generated by GNU Autoconf 2.59 for python 2.5.
55
#
@@ -863,6 +863,7 @@ Optional Packages:
863863
--with-suffix=.exe set executable suffix
864864
--with-pydebug build with Py_DEBUG defined
865865
--with-libs='lib1 ...' link against additional libs
866+
--with-system-ffi build _ctypes module using an installed ffi library
866867
--with-signal-module disable/enable signal module
867868
--with-dec-threads use DEC Alpha/OSF1 thread-safe libraries
868869
--with(out)-threads[=DIRECTORY]
@@ -11780,6 +11781,22 @@ else
1178011781
echo "${ECHO_T}no" >&6
1178111782
fi;
1178211783

11784+
# Check for use of the system libffi library
11785+
echo "$as_me:$LINENO: checking for --with-system-ffi" >&5
11786+
echo $ECHO_N "checking for --with-system-ffi... $ECHO_C" >&6
11787+
11788+
# Check whether --with-system_ffi or --without-system_ffi was given.
11789+
if test "${with_system_ffi+set}" = set; then
11790+
withval="$with_system_ffi"
11791+
11792+
fi;
11793+
11794+
if test -z "$with_system_ffi"
11795+
then with_system_ffi="no"
11796+
fi
11797+
echo "$as_me:$LINENO: result: $with_system_ffi" >&5
11798+
echo "${ECHO_T}$with_system_ffi" >&6
11799+
1178311800
# Determine if signalmodule should be used.
1178411801

1178511802

configure.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,16 @@ LIBS="$withval $LIBS"
16041604
],
16051605
[AC_MSG_RESULT(no)])
16061606

1607+
# Check for use of the system libffi library
1608+
AC_MSG_CHECKING(for --with-system-ffi)
1609+
AC_ARG_WITH(system_ffi,
1610+
AC_HELP_STRING(--with-system-ffi, build _ctypes module using an installed ffi library))
1611+
1612+
if test -z "$with_system_ffi"
1613+
then with_system_ffi="no"
1614+
fi
1615+
AC_MSG_RESULT($with_system_ffi)
1616+
16071617
# Determine if signalmodule should be used.
16081618
AC_SUBST(USE_SIGNAL_MODULE)
16091619
AC_SUBST(SIGNAL_OBJS)

setup.py

Lines changed: 67 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ class db_found(Exception): pass
973973
exts.append( Extension('dl', ['dlmodule.c']) )
974974

975975
# Thomas Heller's _ctypes module
976-
self.detect_ctypes()
976+
self.detect_ctypes(inc_dirs, lib_dirs)
977977

978978
# Platform-specific libraries
979979
if platform == 'linux2':
@@ -1269,44 +1269,46 @@ def detect_tkinter(self, inc_dirs, lib_dirs):
12691269
# -lGL -lGLU -lXext -lXmu \
12701270

12711271
def configure_ctypes(self, ext):
1272-
(srcdir,) = sysconfig.get_config_vars('srcdir')
1273-
ffi_builddir = os.path.join(self.build_temp, 'libffi')
1274-
ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
1275-
'_ctypes', 'libffi'))
1276-
ffi_configfile = os.path.join(ffi_builddir, 'fficonfig.py')
1277-
1278-
if self.force or not os.path.exists(ffi_configfile):
1279-
from distutils.dir_util import mkpath
1280-
mkpath(ffi_builddir)
1281-
config_args = []
1282-
1283-
# Pass empty CFLAGS because we'll just append the resulting CFLAGS
1284-
# to Python's; -g or -O2 is to be avoided.
1285-
cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \
1286-
% (ffi_builddir, ffi_srcdir, " ".join(config_args))
1287-
1288-
res = os.system(cmd)
1289-
if res or not os.path.exists(ffi_configfile):
1290-
print "Failed to configure _ctypes module"
1291-
return False
1292-
1293-
fficonfig = {}
1294-
execfile(ffi_configfile, globals(), fficonfig)
1295-
ffi_srcdir = os.path.join(fficonfig['ffi_srcdir'], 'src')
1296-
1297-
# Add .S (preprocessed assembly) to C compiler source extensions.
1298-
self.compiler.src_extensions.append('.S')
1299-
1300-
include_dirs = [os.path.join(ffi_builddir, 'include'),
1301-
ffi_builddir, ffi_srcdir]
1302-
extra_compile_args = fficonfig['ffi_cflags'].split()
1303-
1304-
ext.sources.extend(fficonfig['ffi_sources'])
1305-
ext.include_dirs.extend(include_dirs)
1306-
ext.extra_compile_args.extend(extra_compile_args)
1272+
if not self.use_system_libffi:
1273+
(srcdir,) = sysconfig.get_config_vars('srcdir')
1274+
ffi_builddir = os.path.join(self.build_temp, 'libffi')
1275+
ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
1276+
'_ctypes', 'libffi'))
1277+
ffi_configfile = os.path.join(ffi_builddir, 'fficonfig.py')
1278+
1279+
if self.force or not os.path.exists(ffi_configfile):
1280+
from distutils.dir_util import mkpath
1281+
mkpath(ffi_builddir)
1282+
config_args = []
1283+
1284+
# Pass empty CFLAGS because we'll just append the resulting
1285+
# CFLAGS to Python's; -g or -O2 is to be avoided.
1286+
cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \
1287+
% (ffi_builddir, ffi_srcdir, " ".join(config_args))
1288+
1289+
res = os.system(cmd)
1290+
if res or not os.path.exists(ffi_configfile):
1291+
print "Failed to configure _ctypes module"
1292+
return False
1293+
1294+
fficonfig = {}
1295+
execfile(ffi_configfile, globals(), fficonfig)
1296+
ffi_srcdir = os.path.join(fficonfig['ffi_srcdir'], 'src')
1297+
1298+
# Add .S (preprocessed assembly) to C compiler source extensions.
1299+
self.compiler.src_extensions.append('.S')
1300+
1301+
include_dirs = [os.path.join(ffi_builddir, 'include'),
1302+
ffi_builddir, ffi_srcdir]
1303+
extra_compile_args = fficonfig['ffi_cflags'].split()
1304+
1305+
ext.sources.extend(fficonfig['ffi_sources'])
1306+
ext.include_dirs.extend(include_dirs)
1307+
ext.extra_compile_args.extend(extra_compile_args)
13071308
return True
13081309

1309-
def detect_ctypes(self):
1310+
def detect_ctypes(self, inc_dirs, lib_dirs):
1311+
self.use_system_libffi = False
13101312
include_dirs = []
13111313
extra_compile_args = []
13121314
sources = ['_ctypes/_ctypes.c',
@@ -1326,12 +1328,40 @@ def detect_ctypes(self):
13261328
ext = Extension('_ctypes',
13271329
include_dirs=include_dirs,
13281330
extra_compile_args=extra_compile_args,
1331+
libraries=[],
13291332
sources=sources,
13301333
depends=depends)
13311334
ext_test = Extension('_ctypes_test',
13321335
sources=['_ctypes/_ctypes_test.c'])
13331336
self.extensions.extend([ext, ext_test])
13341337

1338+
if not '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS"):
1339+
return
1340+
1341+
ffi_inc = find_file('ffi.h', [], inc_dirs)
1342+
if ffi_inc is not None:
1343+
ffi_h = ffi_inc[0] + '/ffi.h'
1344+
fp = open(ffi_h)
1345+
while 1:
1346+
line = fp.readline()
1347+
if not line:
1348+
ffi_inc = None
1349+
break
1350+
if line.startswith('#define LIBFFI_H'):
1351+
break
1352+
ffi_lib = None
1353+
if ffi_inc is not None:
1354+
for lib_name in ('ffi_convenience', 'ffi_pic', 'ffi'):
1355+
if (self.compiler.find_library_file(lib_dirs, lib_name)):
1356+
ffi_lib = lib_name
1357+
break
1358+
1359+
if ffi_inc and ffi_lib:
1360+
ext.include_dirs.extend(ffi_inc)
1361+
ext.libraries.append(ffi_lib)
1362+
self.use_system_libffi = True
1363+
1364+
13351365
class PyBuildInstall(install):
13361366
# Suppress the warning about installation into the lib_dynload
13371367
# directory, which is not in sys.path when running Python during

0 commit comments

Comments
 (0)