[Python-checkins] CVS: python/dist/src/Objects rangeobject.c,2.21,2.22

Fred L. Drake python-dev@python.org
Wed, 8 Nov 2000 11:42:46 -0800


Update of /cvsroot/python/python/dist/src/Objects
In directory slayer.i.sourceforge.net:/tmp/cvs-serv8961/Objects
Modified Files:
	rangeobject.c 
Log Message:
Fixed support for containment test when a negative step is used; this
*really* closes bug #121965.
Added three attributes to the xrange object: start, stop, and step. These
are the same as for the slice objects.
Index: rangeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/rangeobject.c,v
retrieving revision 2.21
retrieving revision 2.22
diff -C2 -r2.21 -r2.22
*** rangeobject.c	2000年11月08日 18:37:05	2.21
--- rangeobject.c	2000年11月08日 19:42:43	2.22
***************
*** 3,6 ****
--- 3,8 ----
 
 #include "Python.h"
+ #include "structmember.h"
+ #include <string.h>
 
 typedef struct {
***************
*** 176,179 ****
--- 178,183 ----
 range_getattr(rangeobject *r, char *name)
 {
+ 	PyObject *result;
+ 
 	static PyMethodDef range_methods[] = {
 		{"tolist",	(PyCFunction)range_tolist, METH_VARARGS,
***************
*** 182,187 ****
 		{NULL,		NULL}
 	};
 
! 	return Py_FindMethod(range_methods, (PyObject *) r, name);
 }
 
--- 186,205 ----
 		{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);
! 	}
! 	return result;
 }
 
***************
*** 194,212 ****
 		return -1;
 
! 	if ((num < r->start) || ((num - r->start) % r->step))
! 		return 0;
! 	if (num >= (r->start + (r->len * r->step)))
! 		return 0;
 	return 1;
 }
 
 static PySequenceMethods range_as_sequence = {
! 	(inquiry)range_length, /*sq_length*/
 	(binaryfunc)range_concat, /*sq_concat*/
 	(intargfunc)range_repeat, /*sq_repeat*/
 	(intargfunc)range_item, /*sq_item*/
 	(intintargfunc)range_slice, /*sq_slice*/
! 	0,		/*sq_ass_item*/
! 	0,		/*sq_ass_slice*/
 	(objobjproc)range_contains, /*sq_contains*/
 };
--- 212,238 ----
 		return -1;
 
! 	if (r->step > 0) {
! 		if ((num < r->start) || ((num - r->start) % r->step))
! 			return 0;
! 		if (num >= (r->start + (r->len * r->step)))
! 			return 0;
! 	}
! 	else {
! 		if ((num > r->start) || ((num - r->start) % r->step))
! 			return 0;
! 		if (num <= (r->start + (r->len * r->step)))
! 			return 0;
! 	}
 	return 1;
 }
 
 static PySequenceMethods range_as_sequence = {
! 	(inquiry)range_length,	/*sq_length*/
 	(binaryfunc)range_concat, /*sq_concat*/
 	(intargfunc)range_repeat, /*sq_repeat*/
 	(intargfunc)range_item, /*sq_item*/
 	(intintargfunc)range_slice, /*sq_slice*/
! 	0,			/*sq_ass_item*/
! 	0,			/*sq_ass_slice*/
 	(objobjproc)range_contains, /*sq_contains*/
 };

AltStyle によって変換されたページ (->オリジナル) /