Skip to content

Commit d65711f

Browse files
serhiy-storchakaGlyphack
authored andcommitted
pythongh-111789: Use PyDict_GetItemRef() in Modules/_struct.c (pythongh-112076)
1 parent 2973bc9 commit d65711f

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Modules/_struct.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,14 +2257,13 @@ cache_struct_converter(PyObject *module, PyObject *fmt, PyStructObject **ptr)
22572257
return 1;
22582258
}
22592259

2260-
s_object = PyDict_GetItemWithError(state->cache, fmt);
2260+
if (PyDict_GetItemRef(state->cache, fmt, &s_object) < 0) {
2261+
return 0;
2262+
}
22612263
if (s_object != NULL) {
2262-
*ptr = (PyStructObject *)Py_NewRef(s_object);
2264+
*ptr = (PyStructObject *)s_object;
22632265
return Py_CLEANUP_SUPPORTED;
22642266
}
2265-
else if (PyErr_Occurred()) {
2266-
return 0;
2267-
}
22682267

22692268
s_object = PyObject_CallOneArg(state->PyStructType, fmt);
22702269
if (s_object != NULL) {

0 commit comments

Comments
 (0)