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, 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) {