summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-11-27 17:41:47 (GMT)
committerGitHub <noreply@github.com>2023-11-27 17:41:47 (GMT)
commit0f009033202b339375944f613aa6d0597a2841de (patch)
treed9fdb0155b550dca4e1156f665dbb903329da1dc
parentb14e5df120ca8ce968a67df2e00e7a764dd703a0 (diff)
downloadcpython-0f009033202b339375944f613aa6d0597a2841de.zip
cpython-0f009033202b339375944f613aa6d0597a2841de.tar.gz
cpython-0f009033202b339375944f613aa6d0597a2841de.tar.bz2
gh-111789: Use PyDict_GetItemRef() in Modules/_struct.c (gh-112076)
-rw-r--r--Modules/_struct.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/Modules/_struct.c b/Modules/_struct.c
index 24a4cb3..bd16fa8 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -2257,14 +2257,13 @@ cache_struct_converter(PyObject *module, PyObject *fmt, PyStructObject **ptr)
return 1;
}
- s_object = PyDict_GetItemWithError(state->cache, fmt);
+ if (PyDict_GetItemRef(state->cache, fmt, &s_object) < 0) {
+ return 0;
+ }
if (s_object != NULL) {
- *ptr = (PyStructObject *)Py_NewRef(s_object);
+ *ptr = (PyStructObject *)s_object;
return Py_CLEANUP_SUPPORTED;
}
- else if (PyErr_Occurred()) {
- return 0;
- }
s_object = PyObject_CallOneArg(state->PyStructType, fmt);
if (s_object != NULL) {