summaryrefslogtreecommitdiffstats
path: root/Modules/_pickle.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_pickle.c')
-rw-r--r--Modules/_pickle.c32
1 files changed, 11 insertions, 21 deletions
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index dc0ef0a..3efc05e 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -3650,34 +3650,24 @@ save_global(PickleState *st, PicklerObject *self, PyObject *obj,
if (extension_key == NULL) {
goto error;
}
- code_obj = PyDict_GetItemWithError(st->extension_registry,
- extension_key);
+ if (PyDict_GetItemRef(st->extension_registry, extension_key, &code_obj) < 0) {
+ Py_DECREF(extension_key);
+ goto error;
+ }
Py_DECREF(extension_key);
- /* The object is not registered in the extension registry.
- This is the most likely code path. */
if (code_obj == NULL) {
- if (PyErr_Occurred()) {
- goto error;
- }
+ /* The object is not registered in the extension registry.
+ This is the most likely code path. */
goto gen_global;
}
- /* XXX: pickle.py doesn't check neither the type, nor the range
- of the value returned by the extension_registry. It should for
- consistency. */
-
- /* Verify code_obj has the right type and value. */
- if (!PyLong_Check(code_obj)) {
- PyErr_Format(st->PicklingError,
- "Can't pickle %R: extension code %R isn't an integer",
- obj, code_obj);
- goto error;
- }
- code = PyLong_AS_LONG(code_obj);
+ code = PyLong_AsLong(code_obj);
+ Py_DECREF(code_obj);
if (code <= 0 || code > 0x7fffffffL) {
+ /* Should never happen in normal circumstances, since the type and
+ the value of the code are checked in copyreg.add_extension(). */
if (!PyErr_Occurred())
- PyErr_Format(st->PicklingError, "Can't pickle %R: extension "
- "code %ld is out of range", obj, code);
+ PyErr_Format(PyExc_RuntimeError, "extension code %ld is out of range", code);
goto error;
}