diff options
author | Guido van Rossum <guido@python.org> | 2003-02-18 22:05:12 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2003-02-18 22:05:12 (GMT) |
commit | c53f009f94a5758530e6f35d8e7ed64c8efcb74b (patch) | |
tree | e39099602182ef895a382a640dc49872619d64b7 /Objects | |
parent | 2b0643a95db568ef9293cc51708d72b121c5d734 (diff) | |
download | cpython-c53f009f94a5758530e6f35d8e7ed64c8efcb74b.zip cpython-c53f009f94a5758530e6f35d8e7ed64c8efcb74b.tar.gz cpython-c53f009f94a5758530e6f35d8e7ed64c8efcb74b.tar.bz2 |
Introducing __reduce_ex__, which is called with a protocol number argument
if it exists in preference over __reduce__. Now Tim can go implement this
in cPickle.c.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index e238056..a1e5b88 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2441,11 +2441,15 @@ static PyGetSetDef object_getsets[] = { }; static PyObject * -object_reduce(PyObject *self, PyObject *args) +object_reduce_ex(PyObject *self, PyObject *args) { - /* Call copy_reg._reduce(self) */ + /* Call copy_reg._reduce_ex(self, proto) */ static PyObject *copy_reg_str; PyObject *copy_reg, *res; + int proto = 0; + + if (!PyArg_ParseTuple(args, "|i:__reduce_ex__", &proto)) + return NULL; if (!copy_reg_str) { copy_reg_str = PyString_InternFromString("copy_reg"); @@ -2455,13 +2459,15 @@ object_reduce(PyObject *self, PyObject *args) copy_reg = PyImport_Import(copy_reg_str); if (!copy_reg) return NULL; - res = PyEval_CallMethod(copy_reg, "_reduce", "(O)", self); + res = PyEval_CallMethod(copy_reg, "_reduce_ex", "(Oi)", self, proto); Py_DECREF(copy_reg); return res; } static PyMethodDef object_methods[] = { - {"__reduce__", object_reduce, METH_NOARGS, + {"__reduce_ex__", object_reduce_ex, METH_VARARGS, + PyDoc_STR("helper for pickle")}, + {"__reduce__", object_reduce_ex, METH_VARARGS, PyDoc_STR("helper for pickle")}, {0} }; |