From 61deb5f4fec16a2763204655e9719308b645a95e Mon Sep 17 00:00:00 2001 From: Matt Davis <6775756+nitzmahone@users.noreply.github.com> Date: Mon, 19 Aug 2024 23:33:23 -0700 Subject: [PATCH] add yet another flag to recompile() to avoid calling ffiplatform (#81) Co-authored-by: Armin Rigo (cherry picked from commit 00cb9fc425d79b09510bbbdf4297cf65afc17dce) --- src/cffi/api.py | 6 ++++-- src/cffi/recompiler.py | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cffi/api.py b/src/cffi/api.py index edeb7928..5a474f3d 100644 --- a/src/cffi/api.py +++ b/src/cffi/api.py @@ -693,7 +693,8 @@ def emit_c_code(self, filename): raise TypeError("emit_c_code() is only for C extension modules, " "not for dlopen()-style pure Python modules") recompile(self, module_name, source, - c_file=filename, call_c_compiler=False, **kwds) + c_file=filename, call_c_compiler=False, + uses_ffiplatform=False, **kwds) def emit_python_code(self, filename): from .recompiler import recompile @@ -705,7 +706,8 @@ def emit_python_code(self, filename): raise TypeError("emit_python_code() is only for dlopen()-style " "pure Python modules, not for C extension modules") recompile(self, module_name, source, - c_file=filename, call_c_compiler=False, **kwds) + c_file=filename, call_c_compiler=False, + uses_ffiplatform=False, **kwds) def compile(self, tmpdir='.', verbose=0, target=None, debug=None): """The 'target' argument gives the final file name of the diff --git a/src/cffi/recompiler.py b/src/cffi/recompiler.py index 3c427754..57781a3c 100644 --- a/src/cffi/recompiler.py +++ b/src/cffi/recompiler.py @@ -1529,7 +1529,8 @@ 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, debug=None, **kwds): + compiler_verbose=1, target=None, debug=None, + uses_ffiplatform=True, **kwds): if not isinstance(module_name, str): module_name = module_name.encode('ascii') if ffi._windows_unicode: @@ -1556,7 +1557,10 @@ def recompile(ffi, module_name, preamble, tmpdir='.', call_c_compiler=True, else: target = '*' # - ext = ffiplatform.get_extension(ext_c_file, module_name, **kwds) + if uses_ffiplatform: + ext = ffiplatform.get_extension(ext_c_file, module_name, **kwds) + else: + ext = None updated = make_c_source(ffi, module_name, preamble, c_file, verbose=compiler_verbose) if call_c_compiler: