Skip to content

Commit acd6f41

Browse files
gh-111789: Use PyDict_GetItemRef() in Python/compile.c (GH-112083)
Co-authored-by: Łukasz Langa <[email protected]>
1 parent e74cd0f commit acd6f41

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Python/compile.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -921,11 +921,10 @@ dict_add_o(PyObject *dict, PyObject *o)
921921
PyObject *v;
922922
Py_ssize_t arg;
923923

924-
v = PyDict_GetItemWithError(dict, o);
924+
if (PyDict_GetItemRef(dict, o, &v) < 0) {
925+
return ERROR;
926+
}
925927
if (!v) {
926-
if (PyErr_Occurred()) {
927-
return ERROR;
928-
}
929928
arg = PyDict_GET_SIZE(dict);
930929
v = PyLong_FromSsize_t(arg);
931930
if (!v) {
@@ -935,10 +934,10 @@ dict_add_o(PyObject *dict, PyObject *o)
935934
Py_DECREF(v);
936935
return ERROR;
937936
}
938-
Py_DECREF(v);
939937
}
940938
else
941939
arg = PyLong_AsLong(v);
940+
Py_DECREF(v);
942941
return arg;
943942
}
944943

0 commit comments

Comments
 (0)