[Python-checkins] python/dist/src/Objects rangeobject.c,2.33,2.34

fdrake@sourceforge.net fdrake@sourceforge.net
Thu, 02 May 2002 09:05:29 -0700


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

Modified Files:
	rangeobject.c 
Log Message:
Fix attribute access for the xrange objects.  The tp_getattr and tp_getattro
handlers were both set, but were not compatible.  This change uses only the
tp_getattro handler with a more "modern" approach.
This fixes SF bug #551285.


Index: rangeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/rangeobject.c,v
retrieving revision 2.33
retrieving revision 2.34
diff -C2 -d -r2.33 -r2.34
*** rangeobject.c	12 Apr 2002 02:44:55 -0000	2.33
--- rangeobject.c	2 May 2002 16:05:27 -0000	2.34
***************
*** 265,296 ****
  
  static PyObject *
! range_getattr(rangeobject *r, char *name)
  {
! 	PyObject *result;
  
! 	static PyMethodDef range_methods[] = {
! 		{"tolist",	(PyCFunction)range_tolist, METH_NOARGS,
!                  "tolist() -> list\n"
!                  "Return a list object with the same values.\n"
!                  "(This method is deprecated; use list() instead.)"},
! 		{NULL,		NULL}
! 	};
! 	static struct memberlist range_members[] = {
! 		{"step",  T_LONG, offsetof(rangeobject, step), RO},
! 		{"start", T_LONG, offsetof(rangeobject, start), RO},
! 		{"stop",  T_LONG, 0, RO},
! 		{NULL, 0, 0, 0}
! 	};
  
! 	result = Py_FindMethod(range_methods, (PyObject *) r, name);
! 	if (result == NULL) {
! 		PyErr_Clear();
! 		if (strcmp("stop", name) == 0)
! 			result = PyInt_FromLong(r->start + (r->len * r->step));
! 		else
! 			result = PyMember_Get((char *)r, range_members, name);
! 		if (result)
! 			WARN("xrange object's 'start', 'stop' and 'step' "
! 			     "attributes are deprecated");
  	}
  	return result;
--- 265,303 ----
  
  static PyObject *
! range_get_stop(rangeobject *self, void *closure)
  {
! 	return PyInt_FromLong(self->start + (self->len * self->step));
! }
  
! static PyMethodDef range_methods[] = {
! 	{"tolist",	(PyCFunction)range_tolist, METH_NOARGS,
!          "tolist() -> list\n"
!          "Return a list object with the same values.\n"
!          "(This method is deprecated; use list() instead.)"},
! 	{NULL,		NULL}
! };
  
! static PyMemberDef range_members[] = {
! 	{"step",  T_LONG, offsetof(rangeobject, step),  RO,
! 	 "Interval between indexes of the slice; also known as the 'stride'."},
! 	{"start", T_LONG, offsetof(rangeobject, start), RO,
! 	 "First index of the slice."},
! 	{NULL, 0, 0, 0}
! };
! 
! static PyGetSetDef range_getsets[] = {
! 	{"stop", (getter)range_get_stop, NULL,
! 	 ""},
! 	{NULL},
! };
! 
! static PyObject *
! range_getattro(rangeobject *self, PyObject *name)
! {
! 	PyObject *result;
! 	result = PyObject_GenericGetAttr((PyObject *)self, name);
! 	if (result && PyInt_CheckExact(result)) {
! 		WARN("xrange object's 'start', 'stop' and 'step' "
! 		     "attributes are deprecated");
  	}
  	return result;
***************
*** 316,320 ****
  	(destructor)range_dealloc,		/*tp_dealloc*/
  	0,					/*tp_print*/
! 	(getattrfunc)range_getattr,		/*tp_getattr*/
  	0,					/*tp_setattr*/
  	(cmpfunc)range_compare,			/*tp_compare*/
--- 323,327 ----
  	(destructor)range_dealloc,		/*tp_dealloc*/
  	0,					/*tp_print*/
! 	0,					/*tp_getattr*/
  	0,					/*tp_setattr*/
  	(cmpfunc)range_compare,			/*tp_compare*/
***************
*** 326,330 ****
  	0,					/*tp_call*/
  	0,					/*tp_str*/
! 	PyObject_GenericGetAttr,		/*tp_getattro*/
  	0,					/*tp_setattro*/
  	0,					/*tp_as_buffer*/
--- 333,337 ----
  	0,					/*tp_call*/
  	0,					/*tp_str*/
! 	(getattrofunc)range_getattro,		/*tp_getattro*/
  	0,					/*tp_setattro*/
  	0,					/*tp_as_buffer*/
***************
*** 337,343 ****
  	0,					/* tp_iter */
  	0,					/* tp_iternext */
! 	0,					/* tp_methods */
! 	0,					/* tp_members */
! 	0,					/* tp_getset */
  	0,					/* tp_base */
  	0,					/* tp_dict */
--- 344,350 ----
  	0,					/* tp_iter */
  	0,					/* tp_iternext */
! 	range_methods,				/* tp_methods */
! 	range_members,				/* tp_members */
! 	range_getsets,				/* tp_getset */
  	0,					/* tp_base */
  	0,					/* tp_dict */