]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-112026: Restore removed _PyDict_GetItemStringWithError() (#112119)
authorVictor Stinner <vstinner@python.org>
Wed, 15 Nov 2023 17:10:06 +0000 (18:10 +0100)
committerGitHub <noreply@github.com>
Wed, 15 Nov 2023 17:10:06 +0000 (17:10 +0000)
Restore the removed _PyDict_GetItemStringWithError() function. It is
used by numpy.

Include/cpython/dictobject.h
Misc/NEWS.d/next/C API/2023-11-15-17-10-09.gh-issue-112026.ts9yyn.rst [new file with mode: 0644]
Objects/dictobject.c

index 91ddc081e2d0136a16dd6d4baee79b05350c3879..944965fb9e5351aef1ee96080cea79d968b0ef3e 100644 (file)
@@ -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 (file)
index 0000000..7d54f6b
--- /dev/null
@@ -0,0 +1,2 @@
+Restore the removed ``_PyDict_GetItemStringWithError()`` function. It is
+used by numpy. Patch by Victor Stinner.
index 556c74db6f6a23cbf9e274b906b54edc40529856..70f424e07ece9ac13882260c5ac38ec0c67d5605 100644 (file)
@@ -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.
  *