Skip to content

Commit

Permalink
_wrappers: use PyDict_GetItemStringRef instead of PyDict_GetItemString
Browse files Browse the repository at this point in the history
Signed-off-by: Filipe Laíns <[email protected]>
  • Loading branch information
FFY00 committed Oct 8, 2024
1 parent 1a6b468 commit 21e18e6
Showing 1 changed file with 12 additions and 1 deletion.
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 */
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

0 comments on commit 21e18e6

Please sign in to comment.