python-cffi/814c55e.patch
2023-06-14 09:08:44 +02:00

46 lines
1.7 KiB
Diff

From 814c55ebf46da49cdb0733756b9568486c682d03 Mon Sep 17 00:00:00 2001
From: Armin Rigo <arigo@tunes.org>
Date: Thu, 8 Jun 2023 19:18:37 +0200
Subject: [PATCH] fix for multiple embedded modules loaded in parallel from
multiple threads
---
cffi/_embedding.h | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/cffi/_embedding.h b/cffi/_embedding.h
index 265630ea..c5eaf889 100644
--- a/cffi/_embedding.h
+++ b/cffi/_embedding.h
@@ -321,10 +321,11 @@ static int _cffi_carefully_make_gil(void)
int old_value, locked_value = -42;
assert(!(PyCapsule_Type.tp_flags & Py_TPFLAGS_HAVE_VERSION_TAG));
# else
- static PyBufferProcs empty_buffer_procs;
+ static struct ebp_s { PyBufferProcs buf; int mark; } empty_buffer_procs;
+ empty_buffer_procs.mark = -42;
PyBufferProcs *volatile *lock = (PyBufferProcs *volatile *)
&PyCapsule_Type.tp_as_buffer;
- PyBufferProcs *old_value, *locked_value = &empty_buffer_procs;
+ PyBufferProcs *old_value, *locked_value = &empty_buffer_procs.buf;
# endif
while (1) { /* spin loop */
@@ -334,7 +335,13 @@ static int _cffi_carefully_make_gil(void)
break;
}
else {
+# if PY_VERSION_HEX < 0x030C0000
assert(old_value == locked_value);
+# else
+ /* The pointer should point to a possibly different
+ empty_buffer_procs from another C extension module */
+ assert(((struct ebp_s *)old_value)->mark == -42);
+# endif
/* should ideally do a spin loop instruction here, but
hard to do it portably and doesn't really matter I
think: PyEval_InitThreads() should be very fast, and
--
GitLab