From dfcb7949a0150f9b8c4ee3ae23c79bbe7427a299 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Sun, 30 Mar 2025 16:03:54 +0530 Subject: [PATCH] add critical section around tp_call --- Modules/_ctypes/_ctypes.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 803d41630dd59a..3ea94e8077f5d4 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -4406,7 +4406,7 @@ _build_result(PyObject *result, PyObject *callargs, } static PyObject * -PyCFuncPtr_call(PyObject *op, PyObject *inargs, PyObject *kwds) +PyCFuncPtr_call_lock_held(PyObject *op, PyObject *inargs, PyObject *kwds) { PyObject *restype; PyObject *converters; @@ -4544,6 +4544,16 @@ PyCFuncPtr_call(PyObject *op, PyObject *inargs, PyObject *kwds) outmask, inoutmask, numretvals); } +static PyObject * +PyCFuncPtr_call(PyObject *op, PyObject *inargs, PyObject *kwds) +{ + PyObject *result; + Py_BEGIN_CRITICAL_SECTION(op); + result = PyCFuncPtr_call_lock_held(op, inargs, kwds); + Py_END_CRITICAL_SECTION(); + return result; +} + static int PyCFuncPtr_traverse(PyObject *op, visitproc visit, void *arg) {