Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Free-threading support #271

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/wrapt/_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -2265,7 +2275,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) {
Expand Down Expand Up @@ -3028,7 +3038,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)) {
Expand Down Expand Up @@ -3222,6 +3232,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;
}

Expand Down
Loading