summaryrefslogtreecommitdiffstats
path: root/Python/marshal.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-01-23 13:15:48 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-01-23 13:15:48 (GMT)
commit1aa78938b0d019b7c9cbb153c2f35709ee01a19a (patch)
treed6402b7773cb2a98e0ab6efccd997707007045d7 /Python/marshal.c
parent5ebe2c89fe47501db64e1a82ac6a3bcbd21f6e70 (diff)
downloadcpython-1aa78938b0d019b7c9cbb153c2f35709ee01a19a.zip
cpython-1aa78938b0d019b7c9cbb153c2f35709ee01a19a.tar.gz
cpython-1aa78938b0d019b7c9cbb153c2f35709ee01a19a.tar.bz2
Issue #26146: marshal.loads() now uses the empty frozenset singleton
Diffstat (limited to 'Python/marshal.c')
-rw-r--r--Python/marshal.c69
1 files changed, 40 insertions, 29 deletions
diff --git a/Python/marshal.c b/Python/marshal.c
index 589eb80..7a4b9d2 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -1266,41 +1266,52 @@ r_object(RFILE *p)
PyErr_SetString(PyExc_ValueError, "bad marshal data (set size out of range)");
break;
}
- v = (type == TYPE_SET) ? PySet_New(NULL) : PyFrozenSet_New(NULL);
- if (type == TYPE_SET) {
- R_REF(v);
- } else {
- /* must use delayed registration of frozensets because they must
- * be init with a refcount of 1
- */
- idx = r_ref_reserve(flag, p);
- if (idx < 0)
- Py_CLEAR(v); /* signal error */
- }
- if (v == NULL)
- break;
- for (i = 0; i < n; i++) {
- v2 = r_object(p);
- if ( v2 == NULL ) {
- if (!PyErr_Occurred())
- PyErr_SetString(PyExc_TypeError,
- "NULL object in marshal data for set");
- Py_DECREF(v);
- v = NULL;
+ if (n == 0 && type == TYPE_FROZENSET) {
+ /* call frozenset() to get the empty frozenset singleton */
+ v = PyObject_CallFunction((PyObject*)&PyFrozenSet_Type, NULL);
+ if (v == NULL)
break;
+ R_REF(v);
+ retval = v;
+ }
+ else {
+ v = (type == TYPE_SET) ? PySet_New(NULL) : PyFrozenSet_New(NULL);
+ if (type == TYPE_SET) {
+ R_REF(v);
+ } else {
+ /* must use delayed registration of frozensets because they must
+ * be init with a refcount of 1
+ */
+ idx = r_ref_reserve(flag, p);
+ if (idx < 0)
+ Py_CLEAR(v); /* signal error */
}
- if (PySet_Add(v, v2) == -1) {
- Py_DECREF(v);
- Py_DECREF(v2);
- v = NULL;
+ if (v == NULL)
break;
+
+ for (i = 0; i < n; i++) {
+ v2 = r_object(p);
+ if ( v2 == NULL ) {
+ if (!PyErr_Occurred())
+ PyErr_SetString(PyExc_TypeError,
+ "NULL object in marshal data for set");
+ Py_DECREF(v);
+ v = NULL;
+ break;
+ }
+ if (PySet_Add(v, v2) == -1) {
+ Py_DECREF(v);
+ Py_DECREF(v2);
+ v = NULL;
+ break;
+ }
+ Py_DECREF(v2);
}
- Py_DECREF(v2);
+ if (type != TYPE_SET)
+ v = r_ref_insert(v, idx, flag, p);
+ retval = v;
}
- if (type != TYPE_SET)
- v = r_ref_insert(v, idx, flag, p);
- retval = v;
break;
case TYPE_CODE: