summaryrefslogtreecommitdiff
path: root/Modules/_pickle.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-11-22 03:37:50 +0100
committerGitHub <noreply@github.com>2018-11-22 03:37:50 +0100
commitb37672daf61740fe1ff9d805f6d74bc5ef04012b (patch)
tree530bb0a89a5de62c1eed68f8b2e616dc24cdc497 /Modules/_pickle.c
parent2ff8fb7639a86757c00a7cbbe7da418fffec3870 (diff)
downloadcpython-git-b37672daf61740fe1ff9d805f6d74bc5ef04012b.tar.gz
bpo-35059: Cleanup usage of Python macros (GH-10648)
Don't pass complex expressions but regular variables to Python macros. * _datetimemodule.c: split single large "if" into two "if" in date_new(), time_new() and datetime_new(). * _pickle.c, load_extension(): flatten complex "if" expression into more regular C code. * _ssl.c: addbool() now uses a temporary bool_obj to only evaluate the value once. * weakrefobject.c: replace "Py_INCREF(result = proxy);" with "result = proxy; Py_INCREF(result);"
Diffstat (limited to 'Modules/_pickle.c')
-rw-r--r--Modules/_pickle.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 2166d296ab..3a77005533 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -5858,14 +5858,20 @@ load_extension(UnpicklerObject *self, int nbytes)
/* Since the extension registry is manipulable via Python code,
* confirm that pair is really a 2-tuple of strings.
*/
- if (!PyTuple_Check(pair) || PyTuple_Size(pair) != 2 ||
- !PyUnicode_Check(module_name = PyTuple_GET_ITEM(pair, 0)) ||
- !PyUnicode_Check(class_name = PyTuple_GET_ITEM(pair, 1))) {
- Py_DECREF(py_code);
- PyErr_Format(PyExc_ValueError, "_inverted_registry[%ld] "
- "isn't a 2-tuple of strings", code);
- return -1;
+ if (!PyTuple_Check(pair) || PyTuple_Size(pair) != 2) {
+ goto error;
+ }
+
+ module_name = PyTuple_GET_ITEM(pair, 0);
+ if (!PyUnicode_Check(module_name)) {
+ goto error;
+ }
+
+ class_name = PyTuple_GET_ITEM(pair, 1);
+ if (!PyUnicode_Check(class_name)) {
+ goto error;
}
+
/* Load the object. */
obj = find_class(self, module_name, class_name);
if (obj == NULL) {
@@ -5881,6 +5887,12 @@ load_extension(UnpicklerObject *self, int nbytes)
}
PDATA_PUSH(self->stack, obj, -1);
return 0;
+
+error:
+ Py_DECREF(py_code);
+ PyErr_Format(PyExc_ValueError, "_inverted_registry[%ld] "
+ "isn't a 2-tuple of strings", code);
+ return -1;
}
static int