diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2007-07-21 17:22:18 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2007-07-21 17:22:18 (GMT) |
commit | 9f2e346911988cda95fec7c901e8d10d34fa9563 (patch) | |
tree | 1632c78fb8e18b2f789102451bedd15996bff6c5 /Modules/itertoolsmodule.c | |
parent | b972a78e17beeb997d809d87f2e422e6622efd52 (diff) | |
download | cpython-9f2e346911988cda95fec7c901e8d10d34fa9563.zip cpython-9f2e346911988cda95fec7c901e8d10d34fa9563.tar.gz cpython-9f2e346911988cda95fec7c901e8d10d34fa9563.tar.bz2 |
Merged revisions 56467-56482 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
................
r56477 | martin.v.loewis | 2007-07-21 09:04:38 +0200 (Sa, 21 Jul 2007) | 11 lines
Merged revisions 56466-56476 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r56476 | martin.v.loewis | 2007-07-21 08:55:02 +0200 (Sa, 21 Jul 2007) | 4 lines
PEP 3123: Provide forward compatibility with Python 3.0, while keeping
backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and
PyVarObject_HEAD_INIT.
........
................
r56478 | martin.v.loewis | 2007-07-21 09:47:23 +0200 (Sa, 21 Jul 2007) | 2 lines
PEP 3123: Use proper C inheritance for PyObject.
................
r56479 | martin.v.loewis | 2007-07-21 10:06:55 +0200 (Sa, 21 Jul 2007) | 3 lines
Add longintrepr.h to Python.h, so that the compiler can
see that PyFalse is really some kind of PyObject*.
................
r56480 | martin.v.loewis | 2007-07-21 10:47:18 +0200 (Sa, 21 Jul 2007) | 2 lines
Qualify SHIFT, MASK, BASE.
................
r56482 | martin.v.loewis | 2007-07-21 19:10:57 +0200 (Sa, 21 Jul 2007) | 2 lines
Correctly refer to _ob_next.
................
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r-- | Modules/itertoolsmodule.c | 103 |
1 files changed, 43 insertions, 60 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 2685ca4..b030c12 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -59,7 +59,7 @@ groupby_dealloc(groupbyobject *gbo) Py_XDECREF(gbo->tgtkey); Py_XDECREF(gbo->currkey); Py_XDECREF(gbo->currvalue); - gbo->ob_type->tp_free(gbo); + Py_Type(gbo)->tp_free(gbo); } static int @@ -139,8 +139,7 @@ PyDoc_STRVAR(groupby_doc, (key, sub-iterator) grouped by each value of key(value).\n"); static PyTypeObject groupby_type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT(NULL, 0) "itertools.groupby", /* tp_name */ sizeof(groupbyobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -261,8 +260,7 @@ _grouper_next(_grouperobject *igo) } static PyTypeObject _grouper_type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT(NULL, 0) "itertools._grouper", /* tp_name */ sizeof(_grouperobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -415,8 +413,7 @@ teedataobject_dealloc(teedataobject *tdo) PyDoc_STRVAR(teedataobject_doc, "Data container common to multiple tee objects."); static PyTypeObject teedataobject_type = { - PyObject_HEAD_INIT(0) /* Must fill in type value later */ - 0, /* ob_size */ + PyVarObject_HEAD_INIT(0, 0) /* Must fill in type value later */ "itertools.tee_dataobject", /* tp_name */ sizeof(teedataobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -572,8 +569,7 @@ static PyMethodDef tee_methods[] = { }; static PyTypeObject tee_type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT(NULL, 0) "itertools.tee", /* tp_name */ sizeof(teeobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -718,7 +714,7 @@ cycle_dealloc(cycleobject *lz) PyObject_GC_UnTrack(lz); Py_XDECREF(lz->saved); Py_XDECREF(lz->it); - lz->ob_type->tp_free(lz); + Py_Type(lz)->tp_free(lz); } static int @@ -768,8 +764,7 @@ Return elements from the iterable until it is exhausted.\n\ Then repeat the sequence indefinitely."); static PyTypeObject cycle_type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT(NULL, 0) "itertools.cycle", /* tp_name */ sizeof(cycleobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -862,7 +857,7 @@ dropwhile_dealloc(dropwhileobject *lz) PyObject_GC_UnTrack(lz); Py_XDECREF(lz->func); Py_XDECREF(lz->it); - lz->ob_type->tp_free(lz); + Py_Type(lz)->tp_free(lz); } static int @@ -882,7 +877,7 @@ dropwhile_next(dropwhileobject *lz) PyObject *(*iternext)(PyObject *); assert(PyIter_Check(it)); - iternext = *it->ob_type->tp_iternext; + iternext = *Py_Type(it)->tp_iternext; for (;;) { item = iternext(it); if (item == NULL) @@ -912,8 +907,7 @@ Drop items from the iterable while predicate(item) is true.\n\ Afterwards, return every element until the iterable is exhausted."); static PyTypeObject dropwhile_type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT(NULL, 0) "itertools.dropwhile", /* tp_name */ sizeof(dropwhileobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -1006,7 +1000,7 @@ takewhile_dealloc(takewhileobject *lz) PyObject_GC_UnTrack(lz); Py_XDECREF(lz->func); Py_XDECREF(lz->it); - lz->ob_type->tp_free(lz); + Py_Type(lz)->tp_free(lz); } static int @@ -1028,7 +1022,7 @@ takewhile_next(takewhileobject *lz) return NULL; assert(PyIter_Check(it)); - item = (*it->ob_type->tp_iternext)(it); + item = (*Py_Type(it)->tp_iternext)(it); if (item == NULL) return NULL; @@ -1053,8 +1047,7 @@ Return successive entries from an iterable as long as the \n\ predicate evaluates to true for each entry."); static PyTypeObject takewhile_type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT(NULL, 0) "itertools.takewhile", /* tp_name */ sizeof(takewhileobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -1197,7 +1190,7 @@ islice_dealloc(isliceobject *lz) { PyObject_GC_UnTrack(lz); Py_XDECREF(lz->it); - lz->ob_type->tp_free(lz); + Py_Type(lz)->tp_free(lz); } static int @@ -1216,7 +1209,7 @@ islice_next(isliceobject *lz) PyObject *(*iternext)(PyObject *); assert(PyIter_Check(it)); - iternext = *it->ob_type->tp_iternext; + iternext = *Py_Type(it)->tp_iternext; while (lz->cnt < lz->next) { item = iternext(it); if (item == NULL) @@ -1249,8 +1242,7 @@ skipped between successive calls. Works like a slice() on a list\n\ but returns an iterator."); static PyTypeObject islice_type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT(NULL, 0) "itertools.islice", /* tp_name */ sizeof(isliceobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -1341,7 +1333,7 @@ starmap_dealloc(starmapobject *lz) PyObject_GC_UnTrack(lz); Py_XDECREF(lz->func); Py_XDECREF(lz->it); - lz->ob_type->tp_free(lz); + Py_Type(lz)->tp_free(lz); } static int @@ -1360,7 +1352,7 @@ starmap_next(starmapobject *lz) PyObject *it = lz->it; assert(PyIter_Check(it)); - args = (*it->ob_type->tp_iternext)(it); + args = (*Py_Type(it)->tp_iternext)(it); if (args == NULL) return NULL; if (!PyTuple_CheckExact(args)) { @@ -1381,8 +1373,7 @@ Return an iterator whose values are returned from the function evaluated\n\ with a argument tuple taken from the given sequence."); static PyTypeObject starmap_type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT(NULL, 0) "itertools.starmap", /* tp_name */ sizeof(starmapobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -1487,7 +1478,7 @@ imap_dealloc(imapobject *lz) PyObject_GC_UnTrack(lz); Py_XDECREF(lz->iters); Py_XDECREF(lz->func); - lz->ob_type->tp_free(lz); + Py_Type(lz)->tp_free(lz); } static int @@ -1561,8 +1552,7 @@ iterable is exhausted instead of filling in None for shorter\n\ iterables."); static PyTypeObject imap_type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT(NULL, 0) "itertools.imap", /* tp_name */ sizeof(imapobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -1666,7 +1656,7 @@ chain_dealloc(chainobject *lz) { PyObject_GC_UnTrack(lz); Py_XDECREF(lz->ittuple); - lz->ob_type->tp_free(lz); + Py_Type(lz)->tp_free(lz); } static int @@ -1706,8 +1696,7 @@ first iterable until it is exhausted, then elements from the next\n\ iterable, until all of the iterables are exhausted."); static PyTypeObject chain_type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT(NULL, 0) "itertools.chain", /* tp_name */ sizeof(chainobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -1798,7 +1787,7 @@ ifilter_dealloc(ifilterobject *lz) PyObject_GC_UnTrack(lz); Py_XDECREF(lz->func); Py_XDECREF(lz->it); - lz->ob_type->tp_free(lz); + Py_Type(lz)->tp_free(lz); } static int @@ -1818,7 +1807,7 @@ ifilter_next(ifilterobject *lz) PyObject *(*iternext)(PyObject *); assert(PyIter_Check(it)); - iternext = *it->ob_type->tp_iternext; + iternext = *Py_Type(it)->tp_iternext; for (;;) { item = iternext(it); if (item == NULL) @@ -1850,8 +1839,7 @@ Return those items of sequence for which function(item) is true.\n\ If function is None, return the items that are true."); static PyTypeObject ifilter_type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT(NULL, 0) "itertools.ifilter", /* tp_name */ sizeof(ifilterobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -1943,7 +1931,7 @@ ifilterfalse_dealloc(ifilterfalseobject *lz) PyObject_GC_UnTrack(lz); Py_XDECREF(lz->func); Py_XDECREF(lz->it); - lz->ob_type->tp_free(lz); + Py_Type(lz)->tp_free(lz); } static int @@ -1963,7 +1951,7 @@ ifilterfalse_next(ifilterfalseobject *lz) PyObject *(*iternext)(PyObject *); assert(PyIter_Check(it)); - iternext = *it->ob_type->tp_iternext; + iternext = *Py_Type(it)->tp_iternext; for (;;) { item = iternext(it); if (item == NULL) @@ -1995,8 +1983,7 @@ Return those items of sequence for which function(item) is false.\n\ If function is None, return the items that are false."); static PyTypeObject ifilterfalse_type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT(NULL, 0) "itertools.ifilterfalse", /* tp_name */ sizeof(ifilterfalseobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2094,8 +2081,7 @@ Return a count object whose .__next__() method returns consecutive\n\ integers starting from zero or, if specified, from firstval."); static PyTypeObject count_type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT(NULL, 0) "itertools.count", /* tp_name */ sizeof(countobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2214,7 +2200,7 @@ izip_dealloc(izipobject *lz) PyObject_GC_UnTrack(lz); Py_XDECREF(lz->ittuple); Py_XDECREF(lz->result); - lz->ob_type->tp_free(lz); + Py_Type(lz)->tp_free(lz); } static int @@ -2237,12 +2223,12 @@ izip_next(izipobject *lz) if (tuplesize == 0) return NULL; - if (result->ob_refcnt == 1) { + if (Py_Refcnt(result) == 1) { Py_INCREF(result); for (i=0 ; i < tuplesize ; i++) { it = PyTuple_GET_ITEM(lz->ittuple, i); assert(PyIter_Check(it)); - item = (*it->ob_type->tp_iternext)(it); + item = (*Py_Type(it)->tp_iternext)(it); if (item == NULL) { Py_DECREF(result); return NULL; @@ -2258,7 +2244,7 @@ izip_next(izipobject *lz) for (i=0 ; i < tuplesize ; i++) { it = PyTuple_GET_ITEM(lz->ittuple, i); assert(PyIter_Check(it)); - item = (*it->ob_type->tp_iternext)(it); + item = (*Py_Type(it)->tp_iternext)(it); if (item == NULL) { Py_DECREF(result); return NULL; @@ -2280,8 +2266,7 @@ function but consumes less memory by returning an iterator instead of\n\ a list."); static PyTypeObject izip_type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT(NULL, 0) "itertools.izip", /* tp_name */ sizeof(izipobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2365,7 +2350,7 @@ repeat_dealloc(repeatobject *ro) { PyObject_GC_UnTrack(ro); Py_XDECREF(ro->element); - ro->ob_type->tp_free(ro); + Py_Type(ro)->tp_free(ro); } static int @@ -2418,8 +2403,7 @@ for the specified number of times. If not specified, returns the element\n\ endlessly."); static PyTypeObject repeat_type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT(NULL, 0) "itertools.repeat", /* tp_name */ sizeof(repeatobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2551,7 +2535,7 @@ izip_longest_dealloc(iziplongestobject *lz) Py_XDECREF(lz->ittuple); Py_XDECREF(lz->result); Py_XDECREF(lz->fillvalue); - lz->ob_type->tp_free(lz); + Py_Type(lz)->tp_free(lz); } static int @@ -2577,7 +2561,7 @@ izip_longest_next(iziplongestobject *lz) return NULL; if (lz->numactive == 0) return NULL; - if (result->ob_refcnt == 1) { + if (Py_Refcnt(result) == 1) { Py_INCREF(result); for (i=0 ; i < tuplesize ; i++) { it = PyTuple_GET_ITEM(lz->ittuple, i); @@ -2586,7 +2570,7 @@ izip_longest_next(iziplongestobject *lz) item = lz->fillvalue; } else { assert(PyIter_Check(it)); - item = (*it->ob_type->tp_iternext)(it); + item = (*Py_Type(it)->tp_iternext)(it); if (item == NULL) { lz->numactive -= 1; if (lz->numactive == 0) { @@ -2615,7 +2599,7 @@ izip_longest_next(iziplongestobject *lz) item = lz->fillvalue; } else { assert(PyIter_Check(it)); - item = (*it->ob_type->tp_iternext)(it); + item = (*Py_Type(it)->tp_iternext)(it); if (item == NULL) { lz->numactive -= 1; if (lz->numactive == 0) { @@ -2647,8 +2631,7 @@ defaults to None or can be specified by a keyword argument.\n\ "); static PyTypeObject iziplongest_type = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT(NULL, 0) "itertools.izip_longest", /* tp_name */ sizeof(iziplongestobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2747,7 +2730,7 @@ inititertools(void) NULL }; - teedataobject_type.ob_type = &PyType_Type; + Py_Type(&teedataobject_type) = &PyType_Type; m = Py_InitModule3("itertools", module_methods, module_doc); if (m == NULL) return; |