[Python-checkins] CVS: python/dist/src/Objects listobject.c,2.71,2.72 rangeobject.c,2.12,2.13 tupleobject.c,2.34,2.35

Fred L. Drake python-dev@python.org
Thu, 15 Jun 2000 07:50:23 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory slayer.i.sourceforge.net:/tmp/cvs-serv28425

Modified Files:
	listobject.c rangeobject.c tupleobject.c 
Log Message:

Thomas Wouters <thomas@xs4all.net>:
The following patch adds "sq_contains" support to rangeobject, and enables
the already-written support for sq_contains in listobject and tupleobject.

The rangeobject "contains" code should be a bit more efficient than the
current default "in" implementation ;-) It might not get used much, but it's
not that much to add.

listobject.c and tupleobject.c already had code for sq_contains, and the
proper struct member was set, but the PyType structure was not extended to
include tp_flags, so the object-specific code was not getting called (Go
ahead, test it ;-). I also did this for the immutable_list_type in
listobject.c, eventhough it is probably never used. Symmetry and all that.


Index: listobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/listobject.c,v
retrieving revision 2.71
retrieving revision 2.72
diff -C2 -r2.71 -r2.72
*** listobject.c	2000/06/01 14:31:03	2.71
--- listobject.c	2000/06/15 14:50:20	2.72
***************
*** 1490,1493 ****
--- 1490,1500 ----
  	&list_as_sequence,	/*tp_as_sequence*/
  	0,		/*tp_as_mapping*/
+ 	0,		/*tp_hash*/
+ 	0,		/*tp_call*/
+ 	0,		/*tp_str*/
+ 	0,		/*tp_getattro*/
+ 	0,		/*tp_setattro*/
+ 	0,		/*tp_as_buffer*/
+ 	Py_TPFLAGS_DEFAULT,	/*tp_flags*/
  };
  
***************
*** 1541,1544 ****
--- 1548,1552 ----
  	(intobjargproc)immutable_list_ass, /*sq_ass_item*/
  	(intintobjargproc)immutable_list_ass, /*sq_ass_slice*/
+ 	(objobjproc)list_contains, /*sq_contains*/
  };
  
***************
*** 1558,1561 ****
--- 1566,1576 ----
  	&immutable_list_as_sequence,	/*tp_as_sequence*/
  	0,		/*tp_as_mapping*/
+ 	0,		/*tp_hash*/
+ 	0,		/*tp_call*/
+ 	0,		/*tp_str*/
+ 	0,		/*tp_getattro*/
+ 	0,		/*tp_setattro*/
+ 	0,		/*tp_as_buffer*/
+ 	Py_TPFLAGS_DEFAULT,	/*tp_flags*/
  };
  

Index: rangeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/rangeobject.c,v
retrieving revision 2.12
retrieving revision 2.13
diff -C2 -r2.12 -r2.13
*** rangeobject.c	2000/05/03 23:44:35	2.12
--- rangeobject.c	2000/06/15 14:50:20	2.13
***************
*** 238,241 ****
--- 238,258 ----
  }
  
+ static int
+ range_contains(r, obj)
+ 	rangeobject * r;
+ 	PyObject * obj;
+ {
+ 	long num = PyInt_AsLong(obj);
+ 	
+ 	if (num < 0 && PyErr_Occurred())
+ 		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*/
***************
*** 246,249 ****
--- 263,267 ----
  	0,		/*sq_ass_item*/
  	0,		/*sq_ass_slice*/
+ 	(objobjproc)range_contains, /*sq_contains*/
  };
  
***************
*** 263,265 ****
--- 281,290 ----
  	&range_as_sequence,	/*tp_as_sequence*/
  	0,			/*tp_as_mapping*/
+ 	0,			/*tp_hash*/
+ 	0,			/*tp_call*/
+ 	0,			/*tp_str*/
+ 	0,			/*tp_getattro*/
+ 	0,			/*tp_setattro*/
+ 	0,			/*tp_as_buffer*/
+ 	Py_TPFLAGS_DEFAULT,	/*tp_flags*/
  };

Index: tupleobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/tupleobject.c,v
retrieving revision 2.34
retrieving revision 2.35
diff -C2 -r2.34 -r2.35
*** tupleobject.c	2000/06/01 03:12:13	2.34
--- tupleobject.c	2000/06/15 14:50:20	2.35
***************
*** 448,451 ****
--- 448,457 ----
  	0,		/*tp_as_mapping*/
  	(hashfunc)tuplehash, /*tp_hash*/
+ 	0,		/*tp_call*/
+ 	0,		/*tp_str*/
+ 	0,		/*tp_getattro*/
+ 	0,		/*tp_setattro*/
+ 	0,		/*tp_as_buffer*/
+ 	Py_TPFLAGS_DEFAULT, /*tp_flags*/
  };