summaryrefslogtreecommitdiffstats
path: root/Modules/_pickle.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-07-11 20:04:12 (GMT)
committerGitHub <noreply@github.com>2023-07-11 20:04:12 (GMT)
commit4bf43710d1e1f19cc46b116b5d8524f6c75dabfa (patch)
treef005fe94ab083da1f9a21485f51373efa7cf8008 /Modules/_pickle.c
parentb444bfb0a325dea8c29f7b1828233b00fbf4a1cb (diff)
downloadcpython-4bf43710d1e1f19cc46b116b5d8524f6c75dabfa.zip
cpython-4bf43710d1e1f19cc46b116b5d8524f6c75dabfa.tar.gz
cpython-4bf43710d1e1f19cc46b116b5d8524f6c75dabfa.tar.bz2
gh-106307: C API: Add PyMapping_GetOptionalItem() function (GH-106308)
Also add PyMapping_GetOptionalItemString() function.
Diffstat (limited to 'Modules/_pickle.c')
-rw-r--r--Modules/_pickle.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index a68a0aa..5ecf7ca 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -4438,16 +4438,13 @@ save(PickleState *st, PicklerObject *self, PyObject *obj, int pers_save)
PyObject_GetItem and _PyObject_GetAttrId used below. */
Py_INCREF(reduce_func);
}
- } else {
- reduce_func = PyObject_GetItem(self->dispatch_table,
- (PyObject *)type);
- if (reduce_func == NULL) {
- if (PyErr_ExceptionMatches(PyExc_KeyError))
- PyErr_Clear();
- else
- goto error;
- }
}
+ else if (PyMapping_GetOptionalItem(self->dispatch_table, (PyObject *)type,
+ &reduce_func) < 0)
+ {
+ goto error;
+ }
+
if (reduce_func != NULL) {
reduce_value = _Pickle_FastCall(reduce_func, Py_NewRef(obj));
}