aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/cffi/py3/c
diff options
context:
space:
mode:
authorrobot-contrib <robot-contrib@yandex-team.com>2023-10-17 17:39:32 +0300
committerrobot-contrib <robot-contrib@yandex-team.com>2023-10-17 18:15:16 +0300
commit6cd8ed34b1facfd950faaec4af85bda31ff85c42 (patch)
tree6667175f788ff1017595871fbc3476cbfe4a1ae8 /contrib/python/cffi/py3/c
parent6e016e79bcbbddee79fefa3a24236d49bda952d9 (diff)
downloadydb-6cd8ed34b1facfd950faaec4af85bda31ff85c42.tar.gz
Update contrib/python/cffi/py3 to 1.16.0
Diffstat (limited to 'contrib/python/cffi/py3/c')
-rw-r--r--contrib/python/cffi/py3/c/_cffi_backend.c15
-rw-r--r--contrib/python/cffi/py3/c/misc_thread_common.h19
2 files changed, 30 insertions, 4 deletions
diff --git a/contrib/python/cffi/py3/c/_cffi_backend.c b/contrib/python/cffi/py3/c/_cffi_backend.c
index f1036d5b4c2..487ab700782 100644
--- a/contrib/python/cffi/py3/c/_cffi_backend.c
+++ b/contrib/python/cffi/py3/c/_cffi_backend.c
@@ -2,7 +2,7 @@
#include <Python.h>
#include "structmember.h"
-#define CFFI_VERSION "1.15.1"
+#define CFFI_VERSION "1.16.0"
#ifdef MS_WIN32
#include <windows.h>
@@ -60,6 +60,13 @@
# endif
#endif
+/* Convert from closure pointer to function pointer. */
+#if defined(__hppa__) && !defined(__LP64__)
+#define CFFI_CLOSURE_TO_FNPTR(type, f) ((type)((unsigned int)(f) | 2))
+#else
+#define CFFI_CLOSURE_TO_FNPTR(type, f) ((type)(f))
+#endif
+
/* Define the following macro ONLY if you trust libffi's version of
* ffi_closure_alloc() more than the code in malloc_closure.h.
@@ -3190,7 +3197,7 @@ cdata_call(CDataObject *cd, PyObject *args, PyObject *kwds)
Py_BEGIN_ALLOW_THREADS
restore_errno();
- ffi_call(&cif_descr->cif, (void (*)(void))(cd->c_data),
+ ffi_call(&cif_descr->cif, CFFI_CLOSURE_TO_FNPTR(void (*)(void), cd->c_data),
resultdata, buffer_array);
save_errno();
Py_END_ALLOW_THREADS
@@ -4507,7 +4514,7 @@ static void *b_do_dlopen(PyObject *args, const char **p_printable_filename,
if (*p_printable_filename == NULL)
return NULL;
- sz1 = PyUnicode_GetSize(filename_unicode) + 1;
+ sz1 = PyText_GetSize(filename_unicode) + 1;
sz1 *= 2; /* should not be needed, but you never know */
w1 = alloca(sizeof(wchar_t) * sz1);
sz1 = PyUnicode_AsWideChar((PyUnicodeObject *)filename_unicode,
@@ -6393,7 +6400,7 @@ static PyObject *b_callback(PyObject *self, PyObject *args)
goto error;
Py_INCREF(ct);
cd->head.c_type = ct;
- cd->head.c_data = (char *)closure_exec;
+ cd->head.c_data = CFFI_CLOSURE_TO_FNPTR(char *, closure_exec);
cd->head.c_weakreflist = NULL;
closure->user_data = NULL;
cd->closure = closure;
diff --git a/contrib/python/cffi/py3/c/misc_thread_common.h b/contrib/python/cffi/py3/c/misc_thread_common.h
index 66e283545b7..ead9c83ce98 100644
--- a/contrib/python/cffi/py3/c/misc_thread_common.h
+++ b/contrib/python/cffi/py3/c/misc_thread_common.h
@@ -102,6 +102,7 @@ thread_canary_dealloc(ThreadCanaryObj *ob)
'local_thread_canary' accesses need to be protected with
the TLS_ZOM_LOCK.
*/
+ //fprintf(stderr, "entering dealloc(%p)\n", ob);
TLS_ZOM_LOCK();
if (ob->zombie_next != NULL) {
//fprintf(stderr, "thread_canary_dealloc(%p): ZOMBIE\n", ob);
@@ -136,6 +137,7 @@ thread_canary_make_zombie(ThreadCanaryObj *ob)
ob->zombie_prev = last;
last->zombie_next = ob;
cffi_zombie_head.zombie_prev = ob;
+ //fprintf(stderr, "thread_canary_make_zombie(%p) DONE\n", ob);
}
static void
@@ -164,6 +166,15 @@ thread_canary_free_zombies(void)
break;
PyThreadState_Clear(tstate); /* calls thread_canary_dealloc on 'ob',
but now ob->zombie_next == NULL. */
+#if PY_VERSION_HEX >= 0x030C0000
+ /* this might be a bug introduced in 3.12, or just me abusing the
+ API around there. The issue is that PyThreadState_Delete()
+ called on a random old tstate will clear the *current* thread
+ notion of what PyGILState_GetThisThreadState() should be, at
+ least if the internal 'bound_gilstate' flag is set in the old
+ tstate. Workaround: clear that flag. */
+ tstate->_status.bound_gilstate = 0;
+#endif
PyThreadState_Delete(tstate);
//fprintf(stderr, "thread_canary_free_zombie: cleared and deleted tstate=%p\n", tstate);
}
@@ -213,9 +224,11 @@ thread_canary_register(PyThreadState *tstate)
tstate->gilstate_counter++;
/* ^^^ this means 'tstate' will never be automatically freed by
PyGILState_Release() */
+ //fprintf(stderr, "CANARY: ready, tstate=%p, tls=%p, canary=%p\n", tstate, tls, canary);
return;
ignore_error:
+ //fprintf(stderr, "CANARY: IGNORED ERROR\n");
PyErr_Clear();
}
@@ -334,6 +347,7 @@ static PyGILState_STATE gil_ensure(void)
*/
PyGILState_STATE result;
PyThreadState *ts = PyGILState_GetThisThreadState();
+ //fprintf(stderr, "%p: gil_ensure(), tstate=%p, tls=%p\n", get_cffi_tls(), ts, get_cffi_tls());
if (ts != NULL) {
ts->gilstate_counter++;
@@ -341,9 +355,11 @@ static PyGILState_STATE gil_ensure(void)
/* common case: 'ts' is our non-current thread state and
we have to make it current and acquire the GIL */
PyEval_RestoreThread(ts);
+ //fprintf(stderr, "%p: gil_ensure(), tstate=%p MADE CURRENT\n", get_cffi_tls(), ts);
return PyGILState_UNLOCKED;
}
else {
+ //fprintf(stderr, "%p: gil_ensure(), tstate=%p ALREADY CURRENT\n", get_cffi_tls(), ts);
return PyGILState_LOCKED;
}
}
@@ -353,6 +369,7 @@ static PyGILState_STATE gil_ensure(void)
assert(result == PyGILState_UNLOCKED);
ts = PyGILState_GetThisThreadState();
+ //fprintf(stderr, "%p: gil_ensure(), made a new tstate=%p\n", get_cffi_tls(), ts);
assert(ts != NULL);
assert(ts == get_current_ts());
assert(ts->gilstate_counter >= 1);
@@ -361,11 +378,13 @@ static PyGILState_STATE gil_ensure(void)
thread really shuts down */
thread_canary_register(ts);
+ assert(ts == PyGILState_GetThisThreadState());
return result;
}
}
static void gil_release(PyGILState_STATE oldstate)
{
+ //fprintf(stderr, "%p: gil_release(%d), tls=%p\n", get_cffi_tls(), (int)oldstate, get_cffi_tls());
PyGILState_Release(oldstate);
}