[Python-checkins] CVS: python/dist/src/Include abstract.h,2.36,2.37

Tim Peters tim_one@users.sourceforge.net
Fri, 07 Sep 2001 21:00:14 -0700


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

Modified Files:
	abstract.h 
Log Message:
Generalize operator.indexOf (PySequence_Index) to work with any
iterable object.  I'm not sure how that got overlooked before!

Got rid of the internal _PySequence_IterContains, introduced a new
internal _PySequence_IterSearch, and rewrote all the iteration-based
"count of", "index of", and "is the object in it or not?" routines to
just call the new function.  I suppose it's slower this way, but the
code duplication was getting depressing.


Index: abstract.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/abstract.h,v
retrieving revision 2.36
retrieving revision 2.37
diff -C2 -d -r2.36 -r2.37
*** abstract.h	2001/08/08 05:00:17	2.36
--- abstract.h	2001/09/08 04:00:11	2.37
***************
*** 989,1000 ****
         /*
           Return -1 if error; 1 if ob in seq; 0 if ob not in seq.
!          Use __contains__ if possible, else _PySequence_IterContains().
         */
  
!      DL_IMPORT(int) _PySequence_IterContains(PyObject *seq, PyObject *ob);
!        /*
!          Return -1 if error; 1 if ob in seq; 0 if ob not in seq.
!          Always uses the iteration protocol, and only Py_EQ comparisons.
!        */
  
  /* For DLL-level backwards compatibility */
--- 989,1010 ----
         /*
           Return -1 if error; 1 if ob in seq; 0 if ob not in seq.
!          Use __contains__ if possible, else _PySequence_IterSearch().
         */
  
! #define PY_ITERSEARCH_COUNT    1
! #define PY_ITERSEARCH_INDEX    2
! #define PY_ITERSEARCH_CONTAINS 3
!      DL_IMPORT(int) _PySequence_IterSearch(PyObject *seq, PyObject *obj,
!      		    int operation);
! 	/*
! 	  Iterate over seq.  Result depends on the operation:
! 	  PY_ITERSEARCH_COUNT:  return # of times obj appears in seq; -1 if
! 	  	error.
! 	  PY_ITERSEARCH_INDEX:  return 0-based index of first occurence of
! 	  	obj in seq; set ValueError and return -1 if none found;
! 	  	also return -1 on error.
! 	  PY_ITERSEARCH_CONTAINS:  return 1 if obj in seq, else 0; -1 on
! 	  	error.
! 	*/
  
  /* For DLL-level backwards compatibility */