mirror of
https://github.com/python/cpython.git
synced 2025-07-29 14:15:07 +00:00
Patch #1464444: Add --with-system-ffi.
This commit is contained in:
parent
2845750c5b
commit
9176fc1466
4 changed files with 91 additions and 31 deletions
3
README
3
README
|
@ -1068,6 +1068,9 @@ Modules/getpath.o.
|
||||||
|
|
||||||
--with-tsc: Profile using the Pentium timestamping counter (TSC).
|
--with-tsc: Profile using the Pentium timestamping counter (TSC).
|
||||||
|
|
||||||
|
--with-system-ffi: Build the _ctypes extension module using an ffi
|
||||||
|
library installed on the system.
|
||||||
|
|
||||||
|
|
||||||
Building for multiple architectures (using the VPATH feature)
|
Building for multiple architectures (using the VPATH feature)
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
|
|
19
configure
vendored
19
configure
vendored
|
@ -1,5 +1,5 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# From configure.in Revision: 43748 .
|
# From configure.in Revision: 45264 .
|
||||||
# Guess values for system-dependent variables and create Makefiles.
|
# Guess values for system-dependent variables and create Makefiles.
|
||||||
# Generated by GNU Autoconf 2.59 for python 2.5.
|
# Generated by GNU Autoconf 2.59 for python 2.5.
|
||||||
#
|
#
|
||||||
|
@ -863,6 +863,7 @@ Optional Packages:
|
||||||
--with-suffix=.exe set executable suffix
|
--with-suffix=.exe set executable suffix
|
||||||
--with-pydebug build with Py_DEBUG defined
|
--with-pydebug build with Py_DEBUG defined
|
||||||
--with-libs='lib1 ...' link against additional libs
|
--with-libs='lib1 ...' link against additional libs
|
||||||
|
--with-system-ffi build _ctypes module using an installed ffi library
|
||||||
--with-signal-module disable/enable signal module
|
--with-signal-module disable/enable signal module
|
||||||
--with-dec-threads use DEC Alpha/OSF1 thread-safe libraries
|
--with-dec-threads use DEC Alpha/OSF1 thread-safe libraries
|
||||||
--with(out)-threads[=DIRECTORY]
|
--with(out)-threads[=DIRECTORY]
|
||||||
|
@ -11780,6 +11781,22 @@ else
|
||||||
echo "${ECHO_T}no" >&6
|
echo "${ECHO_T}no" >&6
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
|
# Check for use of the system libffi library
|
||||||
|
echo "$as_me:$LINENO: checking for --with-system-ffi" >&5
|
||||||
|
echo $ECHO_N "checking for --with-system-ffi... $ECHO_C" >&6
|
||||||
|
|
||||||
|
# Check whether --with-system_ffi or --without-system_ffi was given.
|
||||||
|
if test "${with_system_ffi+set}" = set; then
|
||||||
|
withval="$with_system_ffi"
|
||||||
|
|
||||||
|
fi;
|
||||||
|
|
||||||
|
if test -z "$with_system_ffi"
|
||||||
|
then with_system_ffi="no"
|
||||||
|
fi
|
||||||
|
echo "$as_me:$LINENO: result: $with_system_ffi" >&5
|
||||||
|
echo "${ECHO_T}$with_system_ffi" >&6
|
||||||
|
|
||||||
# Determine if signalmodule should be used.
|
# Determine if signalmodule should be used.
|
||||||
|
|
||||||
|
|
||||||
|
|
10
configure.in
10
configure.in
|
@ -1604,6 +1604,16 @@ LIBS="$withval $LIBS"
|
||||||
],
|
],
|
||||||
[AC_MSG_RESULT(no)])
|
[AC_MSG_RESULT(no)])
|
||||||
|
|
||||||
|
# Check for use of the system libffi library
|
||||||
|
AC_MSG_CHECKING(for --with-system-ffi)
|
||||||
|
AC_ARG_WITH(system_ffi,
|
||||||
|
AC_HELP_STRING(--with-system-ffi, build _ctypes module using an installed ffi library))
|
||||||
|
|
||||||
|
if test -z "$with_system_ffi"
|
||||||
|
then with_system_ffi="no"
|
||||||
|
fi
|
||||||
|
AC_MSG_RESULT($with_system_ffi)
|
||||||
|
|
||||||
# Determine if signalmodule should be used.
|
# Determine if signalmodule should be used.
|
||||||
AC_SUBST(USE_SIGNAL_MODULE)
|
AC_SUBST(USE_SIGNAL_MODULE)
|
||||||
AC_SUBST(SIGNAL_OBJS)
|
AC_SUBST(SIGNAL_OBJS)
|
||||||
|
|
90
setup.py
90
setup.py
|
@ -973,7 +973,7 @@ class PyBuildExt(build_ext):
|
||||||
exts.append( Extension('dl', ['dlmodule.c']) )
|
exts.append( Extension('dl', ['dlmodule.c']) )
|
||||||
|
|
||||||
# Thomas Heller's _ctypes module
|
# Thomas Heller's _ctypes module
|
||||||
self.detect_ctypes()
|
self.detect_ctypes(inc_dirs, lib_dirs)
|
||||||
|
|
||||||
# Platform-specific libraries
|
# Platform-specific libraries
|
||||||
if platform == 'linux2':
|
if platform == 'linux2':
|
||||||
|
@ -1269,44 +1269,46 @@ class PyBuildExt(build_ext):
|
||||||
# -lGL -lGLU -lXext -lXmu \
|
# -lGL -lGLU -lXext -lXmu \
|
||||||
|
|
||||||
def configure_ctypes(self, ext):
|
def configure_ctypes(self, ext):
|
||||||
(srcdir,) = sysconfig.get_config_vars('srcdir')
|
if not self.use_system_libffi:
|
||||||
ffi_builddir = os.path.join(self.build_temp, 'libffi')
|
(srcdir,) = sysconfig.get_config_vars('srcdir')
|
||||||
ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
|
ffi_builddir = os.path.join(self.build_temp, 'libffi')
|
||||||
'_ctypes', 'libffi'))
|
ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules',
|
||||||
ffi_configfile = os.path.join(ffi_builddir, 'fficonfig.py')
|
'_ctypes', 'libffi'))
|
||||||
|
ffi_configfile = os.path.join(ffi_builddir, 'fficonfig.py')
|
||||||
|
|
||||||
if self.force or not os.path.exists(ffi_configfile):
|
if self.force or not os.path.exists(ffi_configfile):
|
||||||
from distutils.dir_util import mkpath
|
from distutils.dir_util import mkpath
|
||||||
mkpath(ffi_builddir)
|
mkpath(ffi_builddir)
|
||||||
config_args = []
|
config_args = []
|
||||||
|
|
||||||
# Pass empty CFLAGS because we'll just append the resulting CFLAGS
|
# Pass empty CFLAGS because we'll just append the resulting
|
||||||
# to Python's; -g or -O2 is to be avoided.
|
# CFLAGS to Python's; -g or -O2 is to be avoided.
|
||||||
cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \
|
cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \
|
||||||
% (ffi_builddir, ffi_srcdir, " ".join(config_args))
|
% (ffi_builddir, ffi_srcdir, " ".join(config_args))
|
||||||
|
|
||||||
res = os.system(cmd)
|
res = os.system(cmd)
|
||||||
if res or not os.path.exists(ffi_configfile):
|
if res or not os.path.exists(ffi_configfile):
|
||||||
print "Failed to configure _ctypes module"
|
print "Failed to configure _ctypes module"
|
||||||
return False
|
return False
|
||||||
|
|
||||||
fficonfig = {}
|
fficonfig = {}
|
||||||
execfile(ffi_configfile, globals(), fficonfig)
|
execfile(ffi_configfile, globals(), fficonfig)
|
||||||
ffi_srcdir = os.path.join(fficonfig['ffi_srcdir'], 'src')
|
ffi_srcdir = os.path.join(fficonfig['ffi_srcdir'], 'src')
|
||||||
|
|
||||||
# Add .S (preprocessed assembly) to C compiler source extensions.
|
# Add .S (preprocessed assembly) to C compiler source extensions.
|
||||||
self.compiler.src_extensions.append('.S')
|
self.compiler.src_extensions.append('.S')
|
||||||
|
|
||||||
include_dirs = [os.path.join(ffi_builddir, 'include'),
|
include_dirs = [os.path.join(ffi_builddir, 'include'),
|
||||||
ffi_builddir, ffi_srcdir]
|
ffi_builddir, ffi_srcdir]
|
||||||
extra_compile_args = fficonfig['ffi_cflags'].split()
|
extra_compile_args = fficonfig['ffi_cflags'].split()
|
||||||
|
|
||||||
ext.sources.extend(fficonfig['ffi_sources'])
|
ext.sources.extend(fficonfig['ffi_sources'])
|
||||||
ext.include_dirs.extend(include_dirs)
|
ext.include_dirs.extend(include_dirs)
|
||||||
ext.extra_compile_args.extend(extra_compile_args)
|
ext.extra_compile_args.extend(extra_compile_args)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def detect_ctypes(self):
|
def detect_ctypes(self, inc_dirs, lib_dirs):
|
||||||
|
self.use_system_libffi = False
|
||||||
include_dirs = []
|
include_dirs = []
|
||||||
extra_compile_args = []
|
extra_compile_args = []
|
||||||
sources = ['_ctypes/_ctypes.c',
|
sources = ['_ctypes/_ctypes.c',
|
||||||
|
@ -1326,12 +1328,40 @@ class PyBuildExt(build_ext):
|
||||||
ext = Extension('_ctypes',
|
ext = Extension('_ctypes',
|
||||||
include_dirs=include_dirs,
|
include_dirs=include_dirs,
|
||||||
extra_compile_args=extra_compile_args,
|
extra_compile_args=extra_compile_args,
|
||||||
|
libraries=[],
|
||||||
sources=sources,
|
sources=sources,
|
||||||
depends=depends)
|
depends=depends)
|
||||||
ext_test = Extension('_ctypes_test',
|
ext_test = Extension('_ctypes_test',
|
||||||
sources=['_ctypes/_ctypes_test.c'])
|
sources=['_ctypes/_ctypes_test.c'])
|
||||||
self.extensions.extend([ext, ext_test])
|
self.extensions.extend([ext, ext_test])
|
||||||
|
|
||||||
|
if not '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS"):
|
||||||
|
return
|
||||||
|
|
||||||
|
ffi_inc = find_file('ffi.h', [], inc_dirs)
|
||||||
|
if ffi_inc is not None:
|
||||||
|
ffi_h = ffi_inc[0] + '/ffi.h'
|
||||||
|
fp = open(ffi_h)
|
||||||
|
while 1:
|
||||||
|
line = fp.readline()
|
||||||
|
if not line:
|
||||||
|
ffi_inc = None
|
||||||
|
break
|
||||||
|
if line.startswith('#define LIBFFI_H'):
|
||||||
|
break
|
||||||
|
ffi_lib = None
|
||||||
|
if ffi_inc is not None:
|
||||||
|
for lib_name in ('ffi_convenience', 'ffi_pic', 'ffi'):
|
||||||
|
if (self.compiler.find_library_file(lib_dirs, lib_name)):
|
||||||
|
ffi_lib = lib_name
|
||||||
|
break
|
||||||
|
|
||||||
|
if ffi_inc and ffi_lib:
|
||||||
|
ext.include_dirs.extend(ffi_inc)
|
||||||
|
ext.libraries.append(ffi_lib)
|
||||||
|
self.use_system_libffi = True
|
||||||
|
|
||||||
|
|
||||||
class PyBuildInstall(install):
|
class PyBuildInstall(install):
|
||||||
# Suppress the warning about installation into the lib_dynload
|
# Suppress the warning about installation into the lib_dynload
|
||||||
# directory, which is not in sys.path when running Python during
|
# directory, which is not in sys.path when running Python during
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue