From ec574faccd6c208a92af597eab756c6897672d2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Fri, 20 Sep 2024 06:02:57 +0100 Subject: [PATCH 1/3] _wrappers: enable free-threading/no-gil support when available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns --- src/wrapt/_wrappers.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/wrapt/_wrappers.c b/src/wrapt/_wrappers.c index e0e1b5bc..3ceb3bcc 100644 --- a/src/wrapt/_wrappers.c +++ b/src/wrapt/_wrappers.c @@ -3222,6 +3222,10 @@ moduleinit(void) PyModule_AddObject(module, "BoundFunctionWrapper", (PyObject *)&WraptBoundFunctionWrapper_Type); + #ifdef Py_GIL_DISABLED + PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED); + #endif + return module; } From 01a2c0bb5a8cee50b30362e03c5a2e064b9f412f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Fri, 20 Sep 2024 06:08:01 +0100 Subject: [PATCH 2/3] _wrappers: make kwlist const instead of static MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns --- src/wrapt/_wrappers.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wrapt/_wrappers.c b/src/wrapt/_wrappers.c index 3ceb3bcc..167f3c7c 100644 --- a/src/wrapt/_wrappers.c +++ b/src/wrapt/_wrappers.c @@ -127,7 +127,7 @@ static int WraptObjectProxy_init(WraptObjectProxyObject *self, { PyObject *wrapped = NULL; - static char *kwlist[] = { "wrapped", NULL }; + char *const kwlist[] = { "wrapped", NULL }; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:ObjectProxy", kwlist, &wrapped)) { @@ -2265,7 +2265,7 @@ static int WraptFunctionWrapperBase_init(WraptFunctionWrapperObject *self, static PyObject *function_str = NULL; - static char *kwlist[] = { "wrapped", "instance", "wrapper", + char *const kwlist[] = { "wrapped", "instance", "wrapper", "enabled", "binding", "parent", NULL }; if (!function_str) { @@ -3028,7 +3028,7 @@ static int WraptFunctionWrapper_init(WraptFunctionWrapperObject *self, int result = 0; - static char *kwlist[] = { "wrapped", "wrapper", "enabled", NULL }; + char *const kwlist[] = { "wrapped", "wrapper", "enabled", NULL }; if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|O:FunctionWrapper", kwlist, &wrapped, &wrapper, &enabled)) { From 4b6db84026a392e23dfbb0faee8099400cb47361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Fri, 20 Sep 2024 06:40:34 +0100 Subject: [PATCH 3/3] _wrappers: use PyDict_GetItemStringRef instead of PyDict_GetItemString MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns --- src/wrapt/_wrappers.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/wrapt/_wrappers.c b/src/wrapt/_wrappers.c index 167f3c7c..326862c2 100644 --- a/src/wrapt/_wrappers.c +++ b/src/wrapt/_wrappers.c @@ -1301,6 +1301,8 @@ static PyObject *WraptObjectProxy_reversed( static PyObject *WraptObjectProxy_round( WraptObjectProxyObject *self, PyObject *args) { + int res; + PyObject *module = NULL; PyObject *dict = NULL; PyObject *round = NULL; @@ -1318,14 +1320,22 @@ static PyObject *WraptObjectProxy_round( return NULL; dict = PyModule_GetDict(module); - round = PyDict_GetItemString(dict, "round"); + #if PY_VERSION_HEX >= 0x30d0000 /* Python >=3.13 */ + res = PyDict_GetItemStringRef(dict, "round", &round); + if (res != 1) { + Py_DECREF(module); + return NULL; + } + #else + round = PyDict_GetItemString(dict, "round"); if (!round) { Py_DECREF(module); return NULL; } - Py_INCREF(round); + #endif + Py_DECREF(module); result = PyObject_CallFunctionObjArgs(round, self->wrapped, NULL);