]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111789: Use PyDict_GetItemRef() in Python/bltinmodule.c (gh-112081)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 27 Nov 2023 17:52:54 +0000 (19:52 +0200)
committerGitHub <noreply@github.com>
Mon, 27 Nov 2023 17:52:54 +0000 (18:52 +0100)
Python/bltinmodule.c

index ff07c498263cd320f7ff00a67c96f59997066186..7a9625134761f9d38433d3b73a2f9a48988632ba 100644 (file)
@@ -5,7 +5,6 @@
 #include "pycore_call.h"          // _PyObject_CallNoArgs()
 #include "pycore_ceval.h"         // _PyEval_Vector()
 #include "pycore_compile.h"       // _PyAST_Compile()
-#include "pycore_dict.h"          // _PyDict_GetItemWithError()
 #include "pycore_long.h"          // _PyLong_CompactValue
 #include "pycore_modsupport.h"    // _PyArg_NoKwnames()
 #include "pycore_object.h"        // _Py_AddToAllObjects()
@@ -141,18 +140,16 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs,
             goto error;
         }
 
-        meta = _PyDict_GetItemWithError(mkw, &_Py_ID(metaclass));
+        if (PyDict_GetItemRef(mkw, &_Py_ID(metaclass), &meta) < 0) {
+            goto error;
+        }
         if (meta != NULL) {
-            Py_INCREF(meta);
             if (PyDict_DelItem(mkw, &_Py_ID(metaclass)) < 0) {
                 goto error;
             }
             /* metaclass is explicitly given, check if it's indeed a class */
             isclass = PyType_Check(meta);
         }
-        else if (PyErr_Occurred()) {
-            goto error;
-        }
     }
     if (meta == NULL) {
         /* if there are no bases, use type: */