[Python-checkins] python/dist/src/Modules itertoolsmodule.c,1.3,1.4
rhettinger@users.sourceforge.net
rhettinger@users.sourceforge.net
Sat, 08 Feb 2003 22:41:00 -0800
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv7878/Modules
Modified Files:
itertoolsmodule.c
Log Message:
C Code:
* Removed the ifilter flag wart by splitting it into two simpler functions.
* Fixed comment tabbing in C code.
* Factored module start-up code into a loop.
Documentation:
* Re-wrote introduction.
* Addede examples for quantifiers.
* Simplified python equivalent for islice().
* Documented split of ifilter().
Sets.py:
* Replace old ifilter() usage with new.
Index: itertoolsmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/itertoolsmodule.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** itertoolsmodule.c 7 Feb 2003 07:26:25 -0000 1.3
--- itertoolsmodule.c 9 Feb 2003 06:40:58 -0000 1.4
***************
*** 119,127 ****
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "itertools.dropwhile", /* tp_name */
! sizeof(dropwhileobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
! (destructor)dropwhile_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
--- 119,127 ----
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "itertools.dropwhile", /* tp_name */
! sizeof(dropwhileobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
! (destructor)dropwhile_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
***************
*** 140,150 ****
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
! dropwhile_doc, /* tp_doc */
(traverseproc)dropwhile_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)dropwhile_getiter, /* tp_iter */
! (iternextfunc)dropwhile_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
--- 140,150 ----
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
! dropwhile_doc, /* tp_doc */
(traverseproc)dropwhile_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)dropwhile_getiter, /* tp_iter */
! (iternextfunc)dropwhile_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
***************
*** 157,161 ****
0, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
! dropwhile_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
};
--- 157,161 ----
0, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
! dropwhile_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
};
***************
*** 272,280 ****
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "itertools.takewhile", /* tp_name */
! sizeof(takewhileobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
! (destructor)takewhile_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
--- 272,280 ----
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "itertools.takewhile", /* tp_name */
! sizeof(takewhileobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
! (destructor)takewhile_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
***************
*** 293,303 ****
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
! takewhile_doc, /* tp_doc */
(traverseproc)takewhile_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)takewhile_getiter, /* tp_iter */
! (iternextfunc)takewhile_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
--- 293,303 ----
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
! takewhile_doc, /* tp_doc */
(traverseproc)takewhile_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)takewhile_getiter, /* tp_iter */
! (iternextfunc)takewhile_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
***************
*** 310,314 ****
0, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
! takewhile_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
};
--- 310,314 ----
0, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
! takewhile_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
};
***************
*** 450,454 ****
0, /* tp_itemsize */
/* methods */
! (destructor)islice_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
--- 450,454 ----
0, /* tp_itemsize */
/* methods */
! (destructor)islice_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
***************
*** 467,477 ****
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
! islice_doc, /* tp_doc */
! (traverseproc)islice_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)islice_getiter, /* tp_iter */
! (iternextfunc)islice_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
--- 467,477 ----
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
! islice_doc, /* tp_doc */
! (traverseproc)islice_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)islice_getiter, /* tp_iter */
! (iternextfunc)islice_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
***************
*** 590,598 ****
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "itertools.starmap", /* tp_name */
! sizeof(starmapobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
! (destructor)starmap_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
--- 590,598 ----
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "itertools.starmap", /* tp_name */
! sizeof(starmapobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
! (destructor)starmap_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
***************
*** 611,621 ****
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
! starmap_doc, /* tp_doc */
! (traverseproc)starmap_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)starmap_getiter, /* tp_iter */
! (iternextfunc)starmap_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
--- 611,621 ----
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
! starmap_doc, /* tp_doc */
! (traverseproc)starmap_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)starmap_getiter, /* tp_iter */
! (iternextfunc)starmap_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
***************
*** 628,632 ****
0, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
! starmap_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
};
--- 628,632 ----
0, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
! starmap_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
};
***************
*** 784,789 ****
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "itertools.imap", /* tp_name */
! sizeof(imapobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
--- 784,789 ----
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "itertools.imap", /* tp_name */
! sizeof(imapobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
***************
*** 822,826 ****
0, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
! imap_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
};
--- 822,826 ----
0, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
! imap_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
};
***************
*** 909,914 ****
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "itertools.times", /* tp_name */
! sizeof(timesobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
--- 909,914 ----
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "itertools.times", /* tp_name */
! sizeof(timesobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
***************
*** 930,940 ****
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
! times_doc, /* tp_doc */
(traverseproc)times_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)times_getiter, /* tp_iter */
! (iternextfunc)times_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
--- 930,940 ----
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
! times_doc, /* tp_doc */
(traverseproc)times_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)times_getiter, /* tp_iter */
! (iternextfunc)times_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
***************
*** 958,962 ****
PyObject *func;
PyObject *it;
- long invert;
} ifilterobject;
--- 958,961 ----
***************
*** 966,980 ****
ifilter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
! PyObject *func, *seq, *invert=NULL;
PyObject *it;
ifilterobject *lz;
- long inv=0;
! if (!PyArg_UnpackTuple(args, "ifilter", 2, 3, &func, &seq, &invert))
return NULL;
- if (invert != NULL && PyObject_IsTrue(invert))
- inv = 1;
-
/* Get iterator. */
it = PyObject_GetIter(seq);
--- 965,975 ----
ifilter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
! PyObject *func, *seq;
PyObject *it;
ifilterobject *lz;
! if (!PyArg_UnpackTuple(args, "ifilter", 2, 2, &func, &seq))
return NULL;
/* Get iterator. */
it = PyObject_GetIter(seq);
***************
*** 991,995 ****
lz->func = func;
lz->it = it;
- lz->invert = inv;
return (PyObject *)lz;
--- 986,989 ----
***************
*** 1047,1051 ****
Py_DECREF(good);
}
! if (ok ^ lz->invert)
return item;
Py_DECREF(item);
--- 1041,1045 ----
Py_DECREF(good);
}
! if (ok)
return item;
Py_DECREF(item);
***************
*** 1061,1078 ****
PyDoc_STRVAR(ifilter_doc,
! "ifilter(function or None, sequence [, invert]) --> ifilter object\n\
\n\
! Return those items of sequence for which function(item) is true. If\n\
! invert is set to True, return items for which function(item) if False.\n\
! If function is None, return the items that are true (unless invert is set).");
PyTypeObject ifilter_type = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "itertools.ifilter", /* tp_name */
! sizeof(ifilterobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
! (destructor)ifilter_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
--- 1055,1071 ----
PyDoc_STRVAR(ifilter_doc,
! "ifilter(function or None, sequence) --> ifilter object\n\
\n\
! Return those items of sequence for which function(item) is true.\n\
! If function is None, return the items that are true.");
PyTypeObject ifilter_type = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "itertools.ifilter", /* tp_name */
! sizeof(ifilterobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
! (destructor)ifilter_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
***************
*** 1091,1101 ****
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
! ifilter_doc, /* tp_doc */
! (traverseproc)ifilter_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)ifilter_getiter, /* tp_iter */
! (iternextfunc)ifilter_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
--- 1084,1094 ----
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
! ifilter_doc, /* tp_doc */
! (traverseproc)ifilter_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)ifilter_getiter, /* tp_iter */
! (iternextfunc)ifilter_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
***************
*** 1108,1112 ****
0, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
! ifilter_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
};
--- 1101,1259 ----
0, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
! ifilter_new, /* tp_new */
! PyObject_GC_Del, /* tp_free */
! };
!
!
! /* ifilterfalse object ************************************************************/
!
! typedef struct {
! PyObject_HEAD
! PyObject *func;
! PyObject *it;
! } ifilterfalseobject;
!
! PyTypeObject ifilterfalse_type;
!
! static PyObject *
! ifilterfalse_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
! {
! PyObject *func, *seq, *invert=NULL;
! PyObject *it;
! ifilterfalseobject *lz;
!
! if (!PyArg_UnpackTuple(args, "ifilterfalse", 2, 2, &func, &seq))
! return NULL;
!
! /* Get iterator. */
! it = PyObject_GetIter(seq);
! if (it == NULL)
! return NULL;
!
! /* create ifilterfalseobject structure */
! lz = (ifilterfalseobject *)type->tp_alloc(type, 0);
! if (lz == NULL) {
! Py_DECREF(it);
! return NULL;
! }
! Py_INCREF(func);
! lz->func = func;
! lz->it = it;
!
! return (PyObject *)lz;
! }
!
! static void
! ifilterfalse_dealloc(ifilterfalseobject *lz)
! {
! PyObject_GC_UnTrack(lz);
! Py_XDECREF(lz->func);
! Py_XDECREF(lz->it);
! lz->ob_type->tp_free(lz);
! }
!
! static int
! ifilterfalse_traverse(ifilterfalseobject *lz, visitproc visit, void *arg)
! {
! int err;
!
! if (lz->it) {
! err = visit(lz->it, arg);
! if (err)
! return err;
! }
! if (lz->func) {
! err = visit(lz->func, arg);
! if (err)
! return err;
! }
! return 0;
! }
!
! static PyObject *
! ifilterfalse_next(ifilterfalseobject *lz)
! {
! PyObject *item;
! long ok;
!
! for (;;) {
! item = PyIter_Next(lz->it);
! if (item == NULL)
! return NULL;
!
! if (lz->func == Py_None) {
! ok = PyObject_IsTrue(item);
! } else {
! PyObject *good;
! good = PyObject_CallFunctionObjArgs(lz->func,
! item, NULL);
! if (good == NULL) {
! Py_DECREF(item);
! return NULL;
! }
! ok = PyObject_IsTrue(good);
! Py_DECREF(good);
! }
! if (!ok)
! return item;
! Py_DECREF(item);
! }
! }
!
! static PyObject *
! ifilterfalse_getiter(PyObject *lz)
! {
! Py_INCREF(lz);
! return lz;
! }
!
! PyDoc_STRVAR(ifilterfalse_doc,
! "ifilterfalse(function or None, sequence) --> ifilterfalse object\n\
! \n\
! Return those items of sequence for which function(item) is false.\n\
! If function is None, return the items that are false.");
!
! PyTypeObject ifilterfalse_type = {
! PyObject_HEAD_INIT(NULL)
! 0, /* ob_size */
! "itertools.ifilterfalse", /* tp_name */
! sizeof(ifilterfalseobject), /* tp_basicsize */
! 0, /* tp_itemsize */
! /* methods */
! (destructor)ifilterfalse_dealloc, /* tp_dealloc */
! 0, /* tp_print */
! 0, /* tp_getattr */
! 0, /* tp_setattr */
! 0, /* tp_compare */
! 0, /* tp_repr */
! 0, /* tp_as_number */
! 0, /* tp_as_sequence */
! 0, /* tp_as_mapping */
! 0, /* tp_hash */
! 0, /* tp_call */
! 0, /* tp_str */
! PyObject_GenericGetAttr, /* tp_getattro */
! 0, /* tp_setattro */
! 0, /* tp_as_buffer */
! Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
! Py_TPFLAGS_BASETYPE, /* tp_flags */
! ifilterfalse_doc, /* tp_doc */
! (traverseproc)ifilterfalse_traverse, /* tp_traverse */
! 0, /* tp_clear */
! 0, /* tp_richcompare */
! 0, /* tp_weaklistoffset */
! (getiterfunc)ifilterfalse_getiter, /* tp_iter */
! (iternextfunc)ifilterfalse_next, /* tp_iternext */
! 0, /* tp_methods */
! 0, /* tp_members */
! 0, /* tp_getset */
! 0, /* tp_base */
! 0, /* tp_dict */
! 0, /* tp_descr_get */
! 0, /* tp_descr_set */
! 0, /* tp_dictoffset */
! 0, /* tp_init */
! PyType_GenericAlloc, /* tp_alloc */
! ifilterfalse_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
};
***************
*** 1162,1167 ****
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "itertools.count", /* tp_name */
! sizeof(countobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
--- 1309,1314 ----
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "itertools.count", /* tp_name */
! sizeof(countobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
***************
*** 1182,1192 ****
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
! count_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)count_getiter, /* tp_iter */
! (iternextfunc)count_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
--- 1329,1339 ----
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
! count_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)count_getiter, /* tp_iter */
! (iternextfunc)count_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
***************
*** 1350,1358 ****
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "itertools.izip", /* tp_name */
! sizeof(izipobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
! (destructor)izip_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
--- 1497,1505 ----
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
! "itertools.izip", /* tp_name */
! sizeof(izipobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
! (destructor)izip_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
***************
*** 1371,1381 ****
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
! izip_doc, /* tp_doc */
(traverseproc)izip_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)izip_getiter, /* tp_iter */
! (iternextfunc)izip_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
--- 1518,1528 ----
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
! izip_doc, /* tp_doc */
(traverseproc)izip_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)izip_getiter, /* tp_iter */
! (iternextfunc)izip_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
***************
*** 1388,1392 ****
0, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
! izip_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
};
--- 1535,1539 ----
0, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
! izip_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
};
***************
*** 1459,1463 ****
0, /* tp_itemsize */
/* methods */
! (destructor)repeat_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
--- 1606,1610 ----
0, /* tp_itemsize */
/* methods */
! (destructor)repeat_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
***************
*** 1476,1486 ****
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
! repeat_doc, /* tp_doc */
! (traverseproc)repeat_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)repeat_getiter, /* tp_iter */
! (iternextfunc)repeat_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
--- 1623,1633 ----
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
! repeat_doc, /* tp_doc */
! (traverseproc)repeat_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)repeat_getiter, /* tp_iter */
! (iternextfunc)repeat_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
***************
*** 1509,1514 ****
Iterators terminating on the shortest input sequence:\n\
izip(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ... \n\
! ifilter(pred, seq, invert=False) --> elements of seq where\n\
! pred(elem) is True (or False if invert is set)\n\
islice(seq, [start,] stop [, step]) --> elements from\n\
seq[start:stop:step]\n\
--- 1656,1661 ----
Iterators terminating on the shortest input sequence:\n\
izip(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ... \n\
! ifilter(pred, seq) --> elements of seq where pred(elem) is True\n\
! ifilterfalse(pred, seq) --> elements of seq where pred(elem) is False\n\
islice(seq, [start,] stop [, step]) --> elements from\n\
seq[start:stop:step]\n\
***************
*** 1524,1578 ****
inititertools(void)
{
PyObject *m;
! m = Py_InitModule3("itertools", NULL, module_doc);
!
! PyModule_AddObject(m, "dropwhile", (PyObject *)&dropwhile_type);
! if (PyType_Ready(&dropwhile_type) < 0)
! return;
! Py_INCREF(&dropwhile_type);
!
! PyModule_AddObject(m, "takewhile", (PyObject *)&takewhile_type);
! if (PyType_Ready(&takewhile_type) < 0)
! return;
! Py_INCREF(&takewhile_type);
!
! PyModule_AddObject(m, "islice", (PyObject *)&islice_type);
! if (PyType_Ready(&islice_type) < 0)
! return;
! Py_INCREF(&islice_type);
!
! PyModule_AddObject(m, "starmap", (PyObject *)&starmap_type);
! if (PyType_Ready(&starmap_type) < 0)
! return;
! Py_INCREF(&starmap_type);
!
! PyModule_AddObject(m, "imap", (PyObject *)&imap_type);
! if (PyType_Ready(&imap_type) < 0)
! return;
! Py_INCREF(&imap_type);
!
! PyModule_AddObject(m, "times", (PyObject *)×_type);
! if (PyType_Ready(×_type) < 0)
! return;
! Py_INCREF(×_type);
!
! if (PyType_Ready(&ifilter_type) < 0)
! return;
! Py_INCREF(&ifilter_type);
! PyModule_AddObject(m, "ifilter", (PyObject *)&ifilter_type);
!
! if (PyType_Ready(&count_type) < 0)
! return;
! Py_INCREF(&count_type);
! PyModule_AddObject(m, "count", (PyObject *)&count_type);
! if (PyType_Ready(&izip_type) < 0)
! return;
! Py_INCREF(&izip_type);
! PyModule_AddObject(m, "izip", (PyObject *)&izip_type);
! if (PyType_Ready(&repeat_type) < 0)
! return;
! Py_INCREF(&repeat_type);
! PyModule_AddObject(m, "repeat", (PyObject *)&repeat_type);
}
--- 1671,1702 ----
inititertools(void)
{
+ int i;
PyObject *m;
! char *name;
! PyTypeObject *typelist[] = {
! &dropwhile_type,
! &takewhile_type,
! &islice_type,
! &starmap_type,
! &imap_type,
! ×_type,
! &ifilter_type,
! &ifilterfalse_type,
! &count_type,
! &izip_type,
! &repeat_type,
! NULL
! };
! m = Py_InitModule3("itertools", NULL, module_doc);
! for (i=0 ; typelist[i] != NULL ; i++) {
! if (PyType_Ready(typelist[i]) < 0)
! return;
! name = strchr(typelist[i]->tp_name, '.') + 1;
! if (name == NULL)
! return;
! Py_INCREF(typelist[i]);
! PyModule_AddObject(m, name, (PyObject *)typelist[i]);
! }
}