diff options
author | Guido van Rossum <guido@python.org> | 2003-01-29 17:58:45 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2003-01-29 17:58:45 (GMT) |
commit | 5d9113d8be81596bc93f2b1a37f57e5110d39a77 (patch) | |
tree | f7bdf7fc9aa5afbf967e9e110baea0e4cdd9ffec /Objects | |
parent | d3590f937f4493445beeb253e5048771d1663ab7 (diff) | |
download | cpython-5d9113d8be81596bc93f2b1a37f57e5110d39a77.zip cpython-5d9113d8be81596bc93f2b1a37f57e5110d39a77.tar.gz cpython-5d9113d8be81596bc93f2b1a37f57e5110d39a77.tar.bz2 |
Implement appropriate __getnewargs__ for all immutable subclassable builtin
types. The special handling for these can now be removed from save_newobj().
Add some testing for this.
Also add support for setting the 'fast' flag on the Python Pickler class,
which suppresses use of the memo.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/complexobject.c | 7 | ||||
-rw-r--r-- | Objects/floatobject.c | 13 | ||||
-rw-r--r-- | Objects/intobject.c | 13 | ||||
-rw-r--r-- | Objects/longobject.c | 13 | ||||
-rw-r--r-- | Objects/stringobject.c | 7 | ||||
-rw-r--r-- | Objects/tupleobject.c | 14 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 9 |
7 files changed, 72 insertions, 4 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c index 56638d5..201da4d 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -639,8 +639,15 @@ complex_conjugate(PyObject *self) return PyComplex_FromCComplex(c); } +static PyObject * +complex_getnewargs(PyComplexObject *v) +{ + return Py_BuildValue("(D)", v->cval); +} + static PyMethodDef complex_methods[] = { {"conjugate", (PyCFunction)complex_conjugate, METH_NOARGS}, + {"__getnewargs__", (PyCFunction)complex_getnewargs, METH_NOARGS}, {NULL, NULL} /* sentinel */ }; diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 09406e4..6e65756 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -726,6 +726,17 @@ float_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return new; } +static PyObject * +float_getnewargs(PyFloatObject *v) +{ + return Py_BuildValue("(d)", v->ob_fval); +} + +static PyMethodDef float_methods[] = { + {"__getnewargs__", (PyCFunction)float_getnewargs, METH_NOARGS}, + {NULL, NULL} /* sentinel */ +}; + PyDoc_STRVAR(float_doc, "float(x) -> floating point number\n\ \n\ @@ -803,7 +814,7 @@ PyTypeObject PyFloat_Type = { 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ - 0, /* tp_methods */ + float_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ diff --git a/Objects/intobject.c b/Objects/intobject.c index 805f3b7..915ef21 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -850,6 +850,17 @@ int_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return new; } +static PyObject * +int_getnewargs(PyIntObject *v) +{ + return Py_BuildValue("(l)", v->ob_ival); +} + +static PyMethodDef int_methods[] = { + {"__getnewargs__", (PyCFunction)int_getnewargs, METH_NOARGS}, + {NULL, NULL} /* sentinel */ +}; + PyDoc_STRVAR(int_doc, "int(x[, base]) -> integer\n\ \n\ @@ -931,7 +942,7 @@ PyTypeObject PyInt_Type = { 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ - 0, /* tp_methods */ + int_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ diff --git a/Objects/longobject.c b/Objects/longobject.c index 1180ec2..7a04f1e 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -2646,6 +2646,17 @@ long_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return (PyObject *)new; } +static PyObject * +long_getnewargs(PyLongObject *v) +{ + return Py_BuildValue("(N)", _PyLong_Copy(v)); +} + +static PyMethodDef long_methods[] = { + {"__getnewargs__", (PyCFunction)long_getnewargs, METH_NOARGS}, + {NULL, NULL} /* sentinel */ +}; + PyDoc_STRVAR(long_doc, "long(x[, base]) -> integer\n\ \n\ @@ -2726,7 +2737,7 @@ PyTypeObject PyLong_Type = { 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ - 0, /* tp_methods */ + long_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ diff --git a/Objects/stringobject.c b/Objects/stringobject.c index f18edb0..9598ffb 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -3045,6 +3045,12 @@ string_splitlines(PyStringObject *self, PyObject *args) #undef SPLIT_APPEND +static PyObject * +string_getnewargs(PyStringObject *v) +{ + return Py_BuildValue("(s#)", v->ob_sval, v->ob_size); +} + static PyMethodDef string_methods[] = { @@ -3091,6 +3097,7 @@ string_methods[] = { expandtabs__doc__}, {"splitlines", (PyCFunction)string_splitlines, METH_VARARGS, splitlines__doc__}, + {"__getnewargs__", (PyCFunction)string_getnewargs, METH_NOARGS}, {NULL, NULL} /* sentinel */ }; diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 3a8f072..d6d0aaa 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -587,6 +587,18 @@ tuplesubscript(PyTupleObject* self, PyObject* item) } } +static PyObject * +tuple_getnewargs(PyTupleObject *v) +{ + return Py_BuildValue("(N)", tupleslice(v, 0, v->ob_size)); + +} + +static PyMethodDef tuple_methods[] = { + {"__getnewargs__", (PyCFunction)tuple_getnewargs, METH_NOARGS}, + {NULL, NULL} /* sentinel */ +}; + static PyMappingMethods tuple_as_mapping = { (inquiry)tuplelength, (binaryfunc)tuplesubscript, @@ -625,7 +637,7 @@ PyTypeObject PyTuple_Type = { 0, /* tp_weaklistoffset */ tuple_iter, /* tp_iter */ 0, /* tp_iternext */ - 0, /* tp_methods */ + tuple_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 07579aa..1abef89 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -5741,6 +5741,14 @@ unicode_endswith(PyUnicodeObject *self, } + +static PyObject * +unicode_getnewargs(PyUnicodeObject *v) +{ + return Py_BuildValue("(u#)", v->str, v->length); +} + + static PyMethodDef unicode_methods[] = { /* Order is according to common usage: often used methods should @@ -5791,6 +5799,7 @@ static PyMethodDef unicode_methods[] = { {"freelistsize", (PyCFunction) unicode_freelistsize, METH_NOARGS}, #endif + {"__getnewargs__", (PyCFunction)unicode_getnewargs, METH_NOARGS}, {NULL, NULL} }; |