From 3a5b3cab927dbf83012e9e6173c81375e36fda41 Mon Sep 17 00:00:00 2001 From: Armin Rigo Date: Tue, 28 Dec 2021 14:33:19 +0100 Subject: Test and fix for the case where ffi.embedding_api() is called but does not list any `extern "Python"` function --- cffi/_embedding.h | 3 ++- cffi/recompiler.py | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'cffi') diff --git a/cffi/_embedding.h b/cffi/_embedding.h index e863d85..4a42cbb 100644 --- a/cffi/_embedding.h +++ b/cffi/_embedding.h @@ -22,7 +22,8 @@ extern "C" { * _cffi_call_python_org, which on CPython is actually part of the _cffi_exports[] array, is the function pointer copied from - _cffi_backend. + _cffi_backend. If _cffi_start_python() fails, then this is set + to NULL; otherwise, it should never be NULL. After initialization is complete, both are equal. However, the first one remains equal to &_cffi_start_and_call_python until the diff --git a/cffi/recompiler.py b/cffi/recompiler.py index 86b37d7..16a7078 100644 --- a/cffi/recompiler.py +++ b/cffi/recompiler.py @@ -406,9 +406,8 @@ class Recompiler: else: prnt(' NULL, /* no includes */') prnt(' %d, /* num_types */' % (len(self.cffi_types),)) - flags = 0 - if self._num_externpy: - flags |= 1 # set to mean that we use extern "Python" + # set 'flags' to 1 in embedding mode, 0 otherwise + flags = int(self.ffi._embedding is not None) prnt(' %d, /* flags */' % flags) prnt('};') prnt() -- cgit v1.2.1