Skip to content

Commit

Permalink
fix for yet another way in which old libffi's are not compatible with…
Browse files Browse the repository at this point in the history
… new libffi's
  • Loading branch information
arigo committed Nov 24, 2020
1 parent 17b8ef4 commit 6ad9369
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions c/_cffi_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
#ifdef __NetBSD__

# define CFFI_CHECK_FFI_CLOSURE_ALLOC 1
# define CFFI_CHECK_FFI_CLOSURE_ALLOC_MAYBE 1
# define CFFI_CHECK_FFI_PREP_CLOSURE_LOC 1
# define CFFI_CHECK_FFI_PREP_CLOSURE_LOC_MAYBE 1
# define CFFI_CHECK_FFI_PREP_CIF_VAR 0
Expand All @@ -98,6 +99,7 @@
#elif defined(__APPLE__) && defined(FFI_AVAILABLE_APPLE)

# define CFFI_CHECK_FFI_CLOSURE_ALLOC __builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)
# define CFFI_CHECK_FFI_CLOSURE_ALLOC_MAYBE 1
# define CFFI_CHECK_FFI_PREP_CLOSURE_LOC __builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)
# define CFFI_CHECK_FFI_PREP_CLOSURE_LOC_MAYBE 1
# define CFFI_CHECK_FFI_PREP_CIF_VAR __builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)
Expand All @@ -106,6 +108,7 @@
#else

# define CFFI_CHECK_FFI_CLOSURE_ALLOC 0
# define CFFI_CHECK_FFI_CLOSURE_ALLOC_MAYBE 0
# define CFFI_CHECK_FFI_PREP_CLOSURE_LOC 0
# define CFFI_CHECK_FFI_PREP_CLOSURE_LOC_MAYBE 0
# define CFFI_CHECK_FFI_PREP_CIF_VAR 0
Expand Down Expand Up @@ -1915,11 +1918,12 @@ static void cdataowninggc_dealloc(CDataObject *cd)
ffi_closure *closure = ((CDataObject_closure *)cd)->closure;
PyObject *args = (PyObject *)(closure->user_data);
Py_XDECREF(args);
#if CFFI_CHECK_FFI_CLOSURE_ALLOC_MAYBE
if (CFFI_CHECK_FFI_CLOSURE_ALLOC) {
ffi_closure_free(closure);
} else {
} else
#endif
cffi_closure_free(closure);
}
}
else {
Py_FatalError("cdata CDataOwningGC_Type with unexpected type flags");
Expand Down Expand Up @@ -6283,9 +6287,12 @@ static PyObject *b_callback(PyObject *self, PyObject *args)
if (infotuple == NULL)
return NULL;

#if CFFI_CHECK_FFI_CLOSURE_ALLOC_MAYBE
if (CFFI_CHECK_FFI_CLOSURE_ALLOC) {
closure = ffi_closure_alloc(sizeof(ffi_closure), &closure_exec);
} else {
} else
#endif
{
closure = cffi_closure_alloc();
closure_exec = closure;
}
Expand Down Expand Up @@ -6373,12 +6380,13 @@ static PyObject *b_callback(PyObject *self, PyObject *args)
error:
closure->user_data = NULL;
if (cd == NULL) {
#if CFFI_CHECK_FFI_CLOSURE_ALLOC_MAYBE
if (CFFI_CHECK_FFI_CLOSURE_ALLOC) {
ffi_closure_free(closure);
}
else {
else
#endif
cffi_closure_free(closure);
}
}
else
Py_DECREF(cd);
Expand Down

0 comments on commit 6ad9369

Please sign in to comment.