[Python-checkins] CVS: python/dist/src/Include iterobject.h,NONE,1.1.2.1 Python.h,2.31,2.31.2.1 abstract.h,2.28,2.28.2.1 object.h,2.77,2.77.2.1 opcode.h,2.34,2.34.2.1

Guido van Rossum gvanrossum@usw-pr-cvs1.sourceforge.net
Tue, 13 Mar 2001 02:07:44 -0800


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

Modified Files:
      Tag: iter-branch
	Python.h abstract.h object.h opcode.h 
Added Files:
      Tag: iter-branch
	iterobject.h 
Log Message:
This is the first iteration of my iterator patches.  Don't worry, this
is on a branch (iter-branch), and it may still change.

Caveats:

- It's incomplete: class instances don't support __iter__ yet.

- It's currently using call notation to get the next item from the
  iterator; there have been arguments for making this use the next()
  method.

- The iter() built-in function is overloaded: iter(x) returns the
  iterator from x, iter(func, value) returns an iterator that calls a
  function until it returns or raises value.  Note: the 'raises' part
  is experimental.

- There is no test suite or documentation yet.

Enjoy!



--- NEW FILE: iterobject.h ---
/* Iterators (the basic kind, over a sequence) */

extern DL_IMPORT(PyTypeObject) PyIter_Type;

#define PyIter_Check(op) ((op)->ob_type == &PyIter_Type)

extern DL_IMPORT(PyObject *) PyIter_New(PyObject *);

extern DL_IMPORT(PyTypeObject) PyCallIter_Type;

#define PyCallIter_Check(op) ((op)->ob_type == &PyCallIter_Type)

extern DL_IMPORT(PyObject *) PyCallIter_New(PyObject *, PyObject *);

Index: Python.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/Python.h,v
retrieving revision 2.31
retrieving revision 2.31.2.1
diff -C2 -r2.31 -r2.31.2.1
*** Python.h	2001/01/25 20:04:14	2.31
--- Python.h	2001/03/13 10:07:41	2.31.2.1
***************
*** 83,86 ****
--- 83,87 ----
  #include "sliceobject.h"
  #include "cellobject.h"
+ #include "iterobject.h"
  
  #include "codecs.h"

Index: abstract.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/abstract.h,v
retrieving revision 2.28
retrieving revision 2.28.2.1
diff -C2 -r2.28 -r2.28.2.1
*** abstract.h	2001/01/17 17:09:53	2.28
--- abstract.h	2001/03/13 10:07:41	2.28.2.1
***************
*** 471,474 ****
--- 471,479 ----
         */
  
+      DL_IMPORT(PyObject *) PyObject_GetIter(PyObject *);
+      /* Takes an object and returns an iterator for it.
+         This is typically a new iterator but of the argument
+ 	is an iterator, this returns itself. */
+ 
  /*  Number Protocol:*/
  

Index: object.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/object.h,v
retrieving revision 2.77
retrieving revision 2.77.2.1
diff -C2 -r2.77 -r2.77.2.1
*** object.h	2001/02/26 18:56:37	2.77
--- object.h	2001/03/13 10:07:41	2.77.2.1
***************
*** 201,204 ****
--- 201,205 ----
  typedef long (*hashfunc)(PyObject *);
  typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
+ typedef PyObject *(*getiterfunc) (PyObject *);
  
  typedef struct _typeobject {
***************
*** 250,255 ****
  	long tp_weaklistoffset;
  
  #ifdef COUNT_ALLOCS
! 	/* these must be last */
  	int tp_alloc;
  	int tp_free;
--- 251,259 ----
  	long tp_weaklistoffset;
  
+ 	/* Iterators */
+ 	getiterfunc tp_iter;
+ 
  #ifdef COUNT_ALLOCS
! 	/* these must be last and never explicitly initialized */
  	int tp_alloc;
  	int tp_free;
***************
*** 343,354 ****
  #define Py_TPFLAGS_CHECKTYPES (1L<<4)
  
  #define Py_TPFLAGS_HAVE_RICHCOMPARE (1L<<5)
  
  /* Objects which are weakly referencable if their tp_weaklistoffset is >0 */
- /* XXX Should this have the same value as Py_TPFLAGS_HAVE_RICHCOMPARE?
-  * These both indicate a feature that appeared in the same alpha release.
-  */
  #define Py_TPFLAGS_HAVE_WEAKREFS (1L<<6)
  
  #define Py_TPFLAGS_DEFAULT  ( \
                               Py_TPFLAGS_HAVE_GETCHARBUFFER | \
--- 347,359 ----
  #define Py_TPFLAGS_CHECKTYPES (1L<<4)
  
+ /* tp_richcompare is defined */
  #define Py_TPFLAGS_HAVE_RICHCOMPARE (1L<<5)
  
  /* Objects which are weakly referencable if their tp_weaklistoffset is >0 */
  #define Py_TPFLAGS_HAVE_WEAKREFS (1L<<6)
  
+ /* tp_iter is defined */
+ #define Py_TPFLAGS_HAVE_ITER (1L<<7)
+ 
  #define Py_TPFLAGS_DEFAULT  ( \
                               Py_TPFLAGS_HAVE_GETCHARBUFFER | \
***************
*** 357,360 ****
--- 362,366 ----
                               Py_TPFLAGS_HAVE_RICHCOMPARE | \
                               Py_TPFLAGS_HAVE_WEAKREFS | \
+                              Py_TPFLAGS_HAVE_ITER | \
                              0)
  

Index: opcode.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/opcode.h,v
retrieving revision 2.34
retrieving revision 2.34.2.1
diff -C2 -r2.34 -r2.34.2.1
*** opcode.h	2001/02/01 22:48:12	2.34
--- opcode.h	2001/03/13 10:07:41	2.34.2.1
***************
*** 54,57 ****
--- 54,58 ----
  #define BINARY_OR	66
  #define INPLACE_POWER	67
+ #define GET_ITER	68
  
  #define PRINT_EXPR	70
***************
*** 81,84 ****
--- 82,86 ----
  #define DELETE_NAME	91	/* "" */
  #define UNPACK_SEQUENCE	92	/* Number of sequence items */
+ #define FOR_ITER	93
  
  #define STORE_ATTR	95	/* Index in name list */