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

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 12 additions & 1 deletion src/wrapt/_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,7 @@ static PyObject *WraptObjectProxy_round(
WraptObjectProxyObject *self, PyObject *args, PyObject *kwds)
{
PyObject *ndigits = NULL;
int res;

PyObject *module = NULL;
PyObject *dict = NULL;
Expand All @@ -1346,13 +1347,23 @@ static PyObject *WraptObjectProxy_round(
return NULL;

round = PyObject_GetAttrString(module, "round");
dict = PyModule_GetDict(module);

#if PY_VERSION_HEX >= 0x30d0000 /* Python >=3.13 */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this version check, under free threading is it instead safe to use:

    // dict = PyModule_GetDict(module);
    // round = PyDict_GetItemString(dict, "round");

    round = PyObject_GetAttrString(builtins, "round");

That way same code across all versions.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW. There was a bug in the __round__ hook implementation anyway as it didn't accept ndigits argument. I have fixed that and changed to using PyObject_GetAttrString on assumption that is okay. Because have also made other changes for static vs const, then the only change required for PR may well just be adding:

     #ifdef Py_GIL_DISABLED
         PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED);
     #endif

Can you rebase your changes against head of develop branch and check again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK.

I will rebase.

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, ndigits, NULL);
Expand Down
Loading