[pypy-commit] cffi default: - add ffi.compile(debug=flag)
arigo
pypy.commits at gmail.com
Sat Sep 3 13:22:05 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r2753:ecd17895c8df
Date: 2016-09-03 19:21 +0200
http://bitbucket.org/cffi/cffi/changeset/ecd17895c8df/
Log: - add ffi.compile(debug=flag)
- this small addition, and a few others not in pypy 5.4, will make
the next cffi release v1.8.1
diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -646,7 +646,7 @@
recompile(self, module_name, source,
c_file=filename, call_c_compiler=False, **kwds)
- def compile(self, tmpdir='.', verbose=0, target=None):
+ def compile(self, tmpdir='.', verbose=0, target=None, debug=None):
"""The 'target' argument gives the final file name of the
compiled DLL. Use '*' to force distutils' choice, suitable for
regular CPython C API modules. Use a file name ending in '.*'
@@ -663,7 +663,7 @@
module_name, source, source_extension, kwds = self._assigned_source
return recompile(self, module_name, source, tmpdir=tmpdir,
target=target, source_extension=source_extension,
- compiler_verbose=verbose, **kwds)
+ compiler_verbose=verbose, debug=debug, **kwds)
def init_once(self, func, tag):
# Read _init_once_cache[tag], which is either (False, lock) if
diff --git a/cffi/ffiplatform.py b/cffi/ffiplatform.py
--- a/cffi/ffiplatform.py
+++ b/cffi/ffiplatform.py
@@ -21,12 +21,12 @@
allsources.append(os.path.normpath(src))
return Extension(name=modname, sources=allsources, **kwds)
-def compile(tmpdir, ext, compiler_verbose=0):
+def compile(tmpdir, ext, compiler_verbose=0, debug=None):
"""Compile a C extension module using distutils."""
saved_environ = os.environ.copy()
try:
- outputfilename = _build(tmpdir, ext, compiler_verbose)
+ outputfilename = _build(tmpdir, ext, compiler_verbose, debug)
outputfilename = os.path.abspath(outputfilename)
finally:
# workaround for a distutils bugs where some env vars can
@@ -36,7 +36,7 @@
os.environ[key] = value
return outputfilename
-def _build(tmpdir, ext, compiler_verbose=0):
+def _build(tmpdir, ext, compiler_verbose=0, debug=None):
# XXX compact but horrible :-(
from distutils.core import Distribution
import distutils.errors, distutils.log
@@ -44,6 +44,9 @@
dist = Distribution({'ext_modules': [ext]})
dist.parse_config_files()
options = dist.get_option_dict('build_ext')
+ if debug is None:
+ debug = sys.flags.debug
+ options['debug'] = ('ffiplatform', debug)
options['force'] = ('ffiplatform', True)
options['build_lib'] = ('ffiplatform', tmpdir)
options['build_temp'] = ('ffiplatform', tmpdir)
diff --git a/cffi/recompiler.py b/cffi/recompiler.py
--- a/cffi/recompiler.py
+++ b/cffi/recompiler.py
@@ -1431,7 +1431,7 @@
def recompile(ffi, module_name, preamble, tmpdir='.', call_c_compiler=True,
c_file=None, source_extension='.c', extradir=None,
- compiler_verbose=1, target=None, **kwds):
+ compiler_verbose=1, target=None, debug=None, **kwds):
if not isinstance(module_name, str):
module_name = module_name.encode('ascii')
if ffi._windows_unicode:
@@ -1467,7 +1467,8 @@
if target != '*':
_patch_for_target(patchlist, target)
os.chdir(tmpdir)
- outputfilename = ffiplatform.compile('.', ext, compiler_verbose)
+ outputfilename = ffiplatform.compile('.', ext,
+ compiler_verbose, debug)
finally:
os.chdir(cwd)
_unpatch_meths(patchlist)
diff --git a/doc/source/cdef.rst b/doc/source/cdef.rst
--- a/doc/source/cdef.rst
+++ b/doc/source/cdef.rst
@@ -533,7 +533,7 @@
that compiling with a debug version of Python will not actually define
``Py_LIMITED_API``, as doing so makes ``Python.h`` unhappy.
-**ffibuilder.compile(tmpdir='.', verbose=False):**
+**ffibuilder.compile(tmpdir='.', verbose=False, debug=None):**
explicitly generate the .py or .c file,
and (if .c) compile it. The output file is (or are) put in the
directory given by ``tmpdir``. In the examples given here, we use
@@ -548,6 +548,13 @@
compiler. (This parameter might be changed to True by default in a
future release.)
+*New in version 1.8.1:* ``debug`` argument. If set to a bool, it
+controls whether the C code is compiled in debug mode or not. The
+default None means to use the host Python's ``sys.flags.debug``.
+Starting with version 1.8.1, if you are running a debug-mode Python, the
+C code is thus compiled in debug mode by default (note that it is anyway
+necessary to do so on Windows).
+
**ffibuilder.emit_python_code(filename):** generate the given .py file (same
as ``ffibuilder.compile()`` for ABI mode, with an explicitly-named file to
write). If you choose, you can include this .py file pre-packaged in
diff --git a/doc/source/whatsnew.rst b/doc/source/whatsnew.rst
--- a/doc/source/whatsnew.rst
+++ b/doc/source/whatsnew.rst
@@ -3,8 +3,8 @@
======================
-v1.8
-====
+v1.8.1
+======
* CPython 3.x: experimental: the generated C extension modules now use
the "limited API", which means that, as a compiled .so/.dll, it should
@@ -13,6 +13,18 @@
name, you can rename it manually to ``NAME.abi3.so``, or use the very
recent setuptools 26.
+* Removed the ctypes backend. If ``_cffi_backend`` was not compiled,
+ you could ask (using an undocumented interface) for ``backend_ctypes``
+ instead. That was never fully functional and long deprecated.
+
+* Added ``ffi.compile(debug=...)``, similar to ``python setup.py build
+ --debug`` but defaulting to True if we are running a debugging
+ version of Python itself.
+
+
+v1.8
+====
+
* Removed the restriction that ``ffi.from_buffer()`` cannot be used on
byte strings. Now you can get a ``char *`` out of a byte string,
which is valid as long as the string object is kept alive. (But
@@ -23,10 +35,6 @@
argument (in older versions, a copy would be made). This used to be
a CPython-only optimization.
-* Removed the ctypes backend. If ``_cffi_backend`` was not compiled,
- you could ask (using an undocumented interface) for ``backend_ctypes``
- instead. That was never fully functional and long deprecated.
-
v1.7
====
More information about the pypy-commit
mailing list