From 1a68e4b0da11043f0bfc3c4bf1f9287a383b7e4b Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 14 Nov 2023 21:11:05 +0200 Subject: [PATCH] gh-111789: Use PyDict_GetItemRef() in Python/compile.c --- Python/compile.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Python/compile.c b/Python/compile.c index 8b1eef79a79eae..1ee8f50a4c7ad4 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -944,11 +944,10 @@ dict_add_o(PyObject *dict, PyObject *o) PyObject *v; Py_ssize_t arg; - v = PyDict_GetItemWithError(dict, o); + if (PyDict_GetItemRef(dict, o, &v) < 0) { + return ERROR; + } if (!v) { - if (PyErr_Occurred()) { - return ERROR; - } arg = PyDict_GET_SIZE(dict); v = PyLong_FromSsize_t(arg); if (!v) { @@ -958,10 +957,10 @@ dict_add_o(PyObject *dict, PyObject *o) Py_DECREF(v); return ERROR; } - Py_DECREF(v); } else arg = PyLong_AsLong(v); + Py_DECREF(v); return arg; }