From f64974405418c82261983295ce744e123e9f6dbc 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] _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 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/wrapt/_wrappers.c b/src/wrapt/_wrappers.c index dc9120b..3434ea8 100644 --- a/src/wrapt/_wrappers.c +++ b/src/wrapt/_wrappers.c @@ -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; @@ -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);