summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2016-09-03 19:21:55 +0200
committerArmin Rigo <arigo@tunes.org>2016-09-03 19:21:55 +0200
commitab96121085aa3b5e81be029e60dad084fb67e088 (patch)
tree022aafb91dff0c26ea59a0787618fad806d137f0
parentb3c5f159d9e39a3ed268516a4342686744d192e4 (diff)
downloadcffi-ab96121085aa3b5e81be029e60dad084fb67e088.tar.gz
- 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
-rw-r--r--cffi/api.py4
-rw-r--r--cffi/ffiplatform.py9
-rw-r--r--cffi/recompiler.py5
-rw-r--r--doc/source/cdef.rst9
-rw-r--r--doc/source/whatsnew.rst20
5 files changed, 33 insertions, 14 deletions
diff --git a/cffi/api.py b/cffi/api.py
index 267076f..6d1eb48 100644
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -646,7 +646,7 @@ class FFI(object):
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 @@ class FFI(object):
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
index d2daa8e..15e591b 100644
--- a/cffi/ffiplatform.py
+++ b/cffi/ffiplatform.py
@@ -21,12 +21,12 @@ def get_extension(srcfilename, modname, sources=(), **kwds):
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 @@ def compile(tmpdir, ext, compiler_verbose=0):
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 @@ def _build(tmpdir, ext, compiler_verbose=0):
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
index 0bd0045..7b0797d 100644
--- a/cffi/recompiler.py
+++ b/cffi/recompiler.py
@@ -1431,7 +1431,7 @@ def _patch_for_target(patchlist, target):
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 @@ def recompile(ffi, module_name, preamble, tmpdir='.', call_c_compiler=True,
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
index 005ce31..077835e 100644
--- a/doc/source/cdef.rst
+++ b/doc/source/cdef.rst
@@ -533,7 +533,7 @@ package will still produce a file called e.g.
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 @@ usual distutils output, including the command lines that call the
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
index 7fa353d..6f81a41 100644
--- a/doc/source/whatsnew.rst
+++ b/doc/source/whatsnew.rst
@@ -3,8 +3,8 @@ What's New
======================
-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 @@ v1.8
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 @@ v1.8
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
====