From: Victor Stinner Date: Wed, 15 Nov 2023 17:10:06 +0000 (+0100) Subject: gh-112026: Restore removed _PyDict_GetItemStringWithError() (#112119) X-Git-Tag: v3.13.0a2~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd2f1485b089bd38d123b4d202a37e567f119482;p=thirdparty%2FPython%2Fcpython.git gh-112026: Restore removed _PyDict_GetItemStringWithError() (#112119) Restore the removed _PyDict_GetItemStringWithError() function. It is used by numpy. --- diff --git a/Include/cpython/dictobject.h b/Include/cpython/dictobject.h index 91ddc081e2d0..944965fb9e53 100644 --- a/Include/cpython/dictobject.h +++ b/Include/cpython/dictobject.h @@ -34,7 +34,7 @@ typedef struct { PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key, Py_hash_t hash); - +PyAPI_FUNC(PyObject *) _PyDict_GetItemStringWithError(PyObject *, const char *); PyAPI_FUNC(PyObject *) PyDict_SetDefault( PyObject *mp, PyObject *key, PyObject *defaultobj); diff --git a/Misc/NEWS.d/next/C API/2023-11-15-17-10-09.gh-issue-112026.ts9yyn.rst b/Misc/NEWS.d/next/C API/2023-11-15-17-10-09.gh-issue-112026.ts9yyn.rst new file mode 100644 index 000000000000..7d54f6b36268 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2023-11-15-17-10-09.gh-issue-112026.ts9yyn.rst @@ -0,0 +1,2 @@ +Restore the removed ``_PyDict_GetItemStringWithError()`` function. It is +used by numpy. Patch by Victor Stinner. diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 556c74db6f6a..70f424e07ece 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -1842,6 +1842,20 @@ _PyDict_GetItemIdWithError(PyObject *dp, _Py_Identifier *key) return _PyDict_GetItem_KnownHash(dp, kv, hash); // borrowed reference } +PyObject * +_PyDict_GetItemStringWithError(PyObject *v, const char *key) +{ + PyObject *kv, *rv; + kv = PyUnicode_FromString(key); + if (kv == NULL) { + return NULL; + } + rv = PyDict_GetItemWithError(v, kv); + Py_DECREF(kv); + return rv; +} + + /* Fast version of global value lookup (LOAD_GLOBAL). * Lookup in globals, then builtins. *