diff options
author | Alexandre Vassalotti <alexandre@peadrop.com> | 2013-12-01 00:06:39 (GMT) |
---|---|---|
committer | Alexandre Vassalotti <alexandre@peadrop.com> | 2013-12-01 00:06:39 (GMT) |
commit | 19b6fa6ebb887e498437b4ae87d6e70b92b4742b (patch) | |
tree | 06c58ae3259eb7bead5356406c4fc7fefa0e34d9 /Modules | |
parent | f8ceb04fcfb2fac63c832639442e69d8902a48b8 (diff) | |
download | cpython-19b6fa6ebb887e498437b4ae87d6e70b92b4742b.zip cpython-19b6fa6ebb887e498437b4ae87d6e70b92b4742b.tar.gz cpython-19b6fa6ebb887e498437b4ae87d6e70b92b4742b.tar.bz2 |
Issue #6477: Added support for pickling the types of built-in singletons.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_pickle.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/Modules/_pickle.c b/Modules/_pickle.c index d862ae8..ba192fb 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -2836,6 +2836,36 @@ save_notimplemented(PicklerObject *self, PyObject *obj) } static int +save_singleton_type(PicklerObject *self, PyObject *obj, PyObject *singleton) +{ + PyObject *reduce_value; + int status; + + reduce_value = Py_BuildValue("O(O)", &PyType_Type, singleton); + if (reduce_value == NULL) { + return -1; + } + status = save_reduce(self, reduce_value, obj); + Py_DECREF(reduce_value); + return status; +} + +static int +save_type(PicklerObject *self, PyObject *obj) +{ + if (obj == (PyObject *)&PyNone_Type) { + return save_singleton_type(self, obj, Py_None); + } + else if (obj == (PyObject *)&PyEllipsis_Type) { + return save_singleton_type(self, obj, Py_Ellipsis); + } + else if (obj == (PyObject *)&PyNotImplemented_Type) { + return save_singleton_type(self, obj, Py_NotImplemented); + } + return save_global(self, obj, NULL); +} + +static int save_pers(PicklerObject *self, PyObject *obj, PyObject *func) { PyObject *pid = NULL; @@ -3189,7 +3219,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save) goto done; } else if (type == &PyType_Type) { - status = save_global(self, obj, NULL); + status = save_type(self, obj); goto done; } else if (type == &PyFunction_Type) { |