[Python-checkins] python/dist/src/Objects complexobject.c,2.64,2.65 floatobject.c,2.119,2.120 intobject.c,2.99,2.100 longobject.c,1.147,1.148 stringobject.c,2.204,2.205 tupleobject.c,2.75,2.76 unicodeobject.c,2.178,2.179

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Wed, 29 Jan 2003 09:58:48 -0800


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv6662/Objects

Modified Files:
	complexobject.c floatobject.c intobject.c longobject.c 
	stringobject.c tupleobject.c unicodeobject.c 
Log Message:
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.

Index: complexobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/complexobject.c,v
retrieving revision 2.64
retrieving revision 2.65
diff -C2 -d -r2.64 -r2.65
*** complexobject.c	29 Aug 2002 14:22:50 -0000	2.64
--- complexobject.c	29 Jan 2003 17:58:44 -0000	2.65
***************
*** 640,645 ****
--- 640,652 ----
  }
  
+ 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 */
  };

Index: floatobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/floatobject.c,v
retrieving revision 2.119
retrieving revision 2.120
diff -C2 -d -r2.119 -r2.120
*** floatobject.c	28 Jan 2003 19:21:24 -0000	2.119
--- floatobject.c	29 Jan 2003 17:58:45 -0000	2.120
***************
*** 727,730 ****
--- 727,741 ----
  }
  
+ 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\
***************
*** 804,808 ****
  	0,					/* tp_iter */
  	0,					/* tp_iternext */
! 	0,					/* tp_methods */
  	0,					/* tp_members */
  	0,					/* tp_getset */
--- 815,819 ----
  	0,					/* tp_iter */
  	0,					/* tp_iternext */
! 	float_methods,				/* tp_methods */
  	0,					/* tp_members */
  	0,					/* tp_getset */

Index: intobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/intobject.c,v
retrieving revision 2.99
retrieving revision 2.100
diff -C2 -d -r2.99 -r2.100
*** intobject.c	19 Jan 2003 15:40:09 -0000	2.99
--- intobject.c	29 Jan 2003 17:58:45 -0000	2.100
***************
*** 851,854 ****
--- 851,865 ----
  }
  
+ 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\
***************
*** 932,936 ****
  	0,					/* tp_iter */
  	0,					/* tp_iternext */
! 	0,					/* tp_methods */
  	0,					/* tp_members */
  	0,					/* tp_getset */
--- 943,947 ----
  	0,					/* tp_iter */
  	0,					/* tp_iternext */
! 	int_methods,				/* tp_methods */
  	0,					/* tp_members */
  	0,					/* tp_getset */

Index: longobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/longobject.c,v
retrieving revision 1.147
retrieving revision 1.148
diff -C2 -d -r1.147 -r1.148
*** longobject.c	28 Jan 2003 20:37:45 -0000	1.147
--- longobject.c	29 Jan 2003 17:58:45 -0000	1.148
***************
*** 2647,2650 ****
--- 2647,2661 ----
  }
  
+ 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\
***************
*** 2727,2731 ****
  	0,					/* tp_iter */
  	0,					/* tp_iternext */
! 	0,					/* tp_methods */
  	0,					/* tp_members */
  	0,					/* tp_getset */
--- 2738,2742 ----
  	0,					/* tp_iter */
  	0,					/* tp_iternext */
! 	long_methods,				/* tp_methods */
  	0,					/* tp_members */
  	0,					/* tp_getset */

Index: stringobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.204
retrieving revision 2.205
diff -C2 -d -r2.204 -r2.205
*** stringobject.c	15 Jan 2003 05:32:57 -0000	2.204
--- stringobject.c	29 Jan 2003 17:58:45 -0000	2.205
***************
*** 3046,3049 ****
--- 3046,3055 ----
  #undef SPLIT_APPEND
  
+ static PyObject *
+ string_getnewargs(PyStringObject *v)
+ {
+ 	return Py_BuildValue("(s#)", v->ob_sval, v->ob_size);
+ }
+ 
  
  static PyMethodDef
***************
*** 3092,3095 ****
--- 3098,3102 ----
  	{"splitlines", (PyCFunction)string_splitlines, METH_VARARGS,
  	 splitlines__doc__},
+ 	{"__getnewargs__",	(PyCFunction)string_getnewargs,	METH_NOARGS},
  	{NULL,     NULL}		     /* sentinel */
  };

Index: tupleobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/tupleobject.c,v
retrieving revision 2.75
retrieving revision 2.76
diff -C2 -d -r2.75 -r2.76
*** tupleobject.c	11 Oct 2002 21:05:56 -0000	2.75
--- tupleobject.c	29 Jan 2003 17:58:45 -0000	2.76
***************
*** 588,591 ****
--- 588,603 ----
  }
  
+ 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,
***************
*** 626,630 ****
  	tuple_iter,	    			/* tp_iter */
  	0,					/* tp_iternext */
! 	0,					/* tp_methods */
  	0,					/* tp_members */
  	0,					/* tp_getset */
--- 638,642 ----
  	tuple_iter,	    			/* tp_iter */
  	0,					/* tp_iternext */
! 	tuple_methods,				/* tp_methods */
  	0,					/* tp_members */
  	0,					/* tp_getset */

Index: unicodeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/unicodeobject.c,v
retrieving revision 2.178
retrieving revision 2.179
diff -C2 -d -r2.178 -r2.179
*** unicodeobject.c	8 Jan 2003 22:01:33 -0000	2.178
--- unicodeobject.c	29 Jan 2003 17:58:45 -0000	2.179
***************
*** 5742,5745 ****
--- 5742,5753 ----
  
  
+ 
+ static PyObject *
+ unicode_getnewargs(PyUnicodeObject *v)
+ {
+ 	return Py_BuildValue("(u#)", v->str, v->length);
+ }
+ 
+ 
  static PyMethodDef unicode_methods[] = {
  
***************
*** 5792,5795 ****
--- 5800,5804 ----
  #endif
  
+     {"__getnewargs__",	(PyCFunction)unicode_getnewargs, METH_NOARGS},
      {NULL, NULL}
  };