Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(26469)

Side by Side Diff: Modules/itertoolsmodule.c

Issue 14010: deeply nested filter segfaults
Patch Set: Created 6 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_itertools.py ('k') | Objects/abstract.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 #include "Python.h" 2 #include "Python.h"
3 #include "structmember.h" 3 #include "structmember.h"
4 4
5 /* Itertools module written and maintained 5 /* Itertools module written and maintained
6 by Raymond D. Hettinger <python@rcn.com> 6 by Raymond D. Hettinger <python@rcn.com>
7 Copyright (c) 2003 Python Software Foundation. 7 Copyright (c) 2003 Python Software Foundation.
8 All rights reserved. 8 All rights reserved.
9 */ 9 */
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 Py_DECREF(gbo); 47 Py_DECREF(gbo);
48 return NULL; 48 return NULL;
49 } 49 }
50 return (PyObject *)gbo; 50 return (PyObject *)gbo;
51 } 51 }
52 52
53 static void 53 static void
54 groupby_dealloc(groupbyobject *gbo) 54 groupby_dealloc(groupbyobject *gbo)
55 { 55 {
56 PyObject_GC_UnTrack(gbo); 56 PyObject_GC_UnTrack(gbo);
57 Py_TRASHCAN_SAFE_BEGIN(gbo)
57 Py_XDECREF(gbo->it); 58 Py_XDECREF(gbo->it);
58 Py_XDECREF(gbo->keyfunc); 59 Py_XDECREF(gbo->keyfunc);
59 Py_XDECREF(gbo->tgtkey); 60 Py_XDECREF(gbo->tgtkey);
60 Py_XDECREF(gbo->currkey); 61 Py_XDECREF(gbo->currkey);
61 Py_XDECREF(gbo->currvalue); 62 Py_XDECREF(gbo->currvalue);
62 Py_TYPE(gbo)->tp_free(gbo); 63 Py_TYPE(gbo)->tp_free(gbo);
64 Py_TRASHCAN_SAFE_END(gbo)
63 } 65 }
64 66
65 static int 67 static int
66 groupby_traverse(groupbyobject *gbo, visitproc visit, void *arg) 68 groupby_traverse(groupbyobject *gbo, visitproc visit, void *arg)
67 { 69 {
68 Py_VISIT(gbo->it); 70 Py_VISIT(gbo->it);
69 Py_VISIT(gbo->keyfunc); 71 Py_VISIT(gbo->keyfunc);
70 Py_VISIT(gbo->tgtkey); 72 Py_VISIT(gbo->tgtkey);
71 Py_VISIT(gbo->currkey); 73 Py_VISIT(gbo->currkey);
72 Py_VISIT(gbo->currvalue); 74 Py_VISIT(gbo->currvalue);
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 lz->saved = saved; 906 lz->saved = saved;
905 lz->firstpass = 0; 907 lz->firstpass = 0;
906 908
907 return (PyObject *)lz; 909 return (PyObject *)lz;
908 } 910 }
909 911
910 static void 912 static void
911 cycle_dealloc(cycleobject *lz) 913 cycle_dealloc(cycleobject *lz)
912 { 914 {
913 PyObject_GC_UnTrack(lz); 915 PyObject_GC_UnTrack(lz);
916 Py_TRASHCAN_SAFE_BEGIN(lz)
914 Py_XDECREF(lz->saved); 917 Py_XDECREF(lz->saved);
915 Py_XDECREF(lz->it); 918 Py_XDECREF(lz->it);
916 Py_TYPE(lz)->tp_free(lz); 919 Py_TYPE(lz)->tp_free(lz);
920 Py_TRASHCAN_SAFE_END(lz)
917 } 921 }
918 922
919 static int 923 static int
920 cycle_traverse(cycleobject *lz, visitproc visit, void *arg) 924 cycle_traverse(cycleobject *lz, visitproc visit, void *arg)
921 { 925 {
922 Py_VISIT(lz->it); 926 Py_VISIT(lz->it);
923 Py_VISIT(lz->saved); 927 Py_VISIT(lz->saved);
924 return 0; 928 return 0;
925 } 929 }
926 930
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 lz->it = it; 1085 lz->it = it;
1082 lz->start = 0; 1086 lz->start = 0;
1083 1087
1084 return (PyObject *)lz; 1088 return (PyObject *)lz;
1085 } 1089 }
1086 1090
1087 static void 1091 static void
1088 dropwhile_dealloc(dropwhileobject *lz) 1092 dropwhile_dealloc(dropwhileobject *lz)
1089 { 1093 {
1090 PyObject_GC_UnTrack(lz); 1094 PyObject_GC_UnTrack(lz);
1095 Py_TRASHCAN_SAFE_BEGIN(lz)
1091 Py_XDECREF(lz->func); 1096 Py_XDECREF(lz->func);
1092 Py_XDECREF(lz->it); 1097 Py_XDECREF(lz->it);
1093 Py_TYPE(lz)->tp_free(lz); 1098 Py_TYPE(lz)->tp_free(lz);
1099 Py_TRASHCAN_SAFE_END(lz)
1094 } 1100 }
1095 1101
1096 static int 1102 static int
1097 dropwhile_traverse(dropwhileobject *lz, visitproc visit, void *arg) 1103 dropwhile_traverse(dropwhileobject *lz, visitproc visit, void *arg)
1098 { 1104 {
1099 Py_VISIT(lz->it); 1105 Py_VISIT(lz->it);
1100 Py_VISIT(lz->func); 1106 Py_VISIT(lz->func);
1101 return 0; 1107 return 0;
1102 } 1108 }
1103 1109
1104 static PyObject * 1110 static PyObject *
1105 dropwhile_next(dropwhileobject *lz) 1111 dropwhile_next(dropwhileobject *lz)
1106 { 1112 {
1107 PyObject *item, *good; 1113 PyObject *item, *good;
1108 PyObject *it = lz->it; 1114 PyObject *it = lz->it;
1109 long ok; 1115 long ok;
1110 PyObject *(*iternext)(PyObject *); 1116 PyObject *(*iternext)(PyObject *);
1111 1117
1112 iternext = *Py_TYPE(it)->tp_iternext; 1118 iternext = *Py_TYPE(it)->tp_iternext;
1113 for (;;) { 1119 for (;;) {
1120 if (Py_EnterRecursiveCall(" while iterating"))
1121 return NULL;
1114 item = iternext(it); 1122 item = iternext(it);
1123 Py_LeaveRecursiveCall();
1115 if (item == NULL) 1124 if (item == NULL)
1116 return NULL; 1125 return NULL;
1117 if (lz->start == 1) 1126 if (lz->start == 1)
1118 return item; 1127 return item;
1119 1128
1120 good = PyObject_CallFunctionObjArgs(lz->func, item, NULL); 1129 good = PyObject_CallFunctionObjArgs(lz->func, item, NULL);
1121 if (good == NULL) { 1130 if (good == NULL) {
1122 Py_DECREF(item); 1131 Py_DECREF(item);
1123 return NULL; 1132 return NULL;
1124 } 1133 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 lz->it = it; 1259 lz->it = it;
1251 lz->stop = 0; 1260 lz->stop = 0;
1252 1261
1253 return (PyObject *)lz; 1262 return (PyObject *)lz;
1254 } 1263 }
1255 1264
1256 static void 1265 static void
1257 takewhile_dealloc(takewhileobject *lz) 1266 takewhile_dealloc(takewhileobject *lz)
1258 { 1267 {
1259 PyObject_GC_UnTrack(lz); 1268 PyObject_GC_UnTrack(lz);
1269 Py_TRASHCAN_SAFE_BEGIN(lz)
1260 Py_XDECREF(lz->func); 1270 Py_XDECREF(lz->func);
1261 Py_XDECREF(lz->it); 1271 Py_XDECREF(lz->it);
1262 Py_TYPE(lz)->tp_free(lz); 1272 Py_TYPE(lz)->tp_free(lz);
1273 Py_TRASHCAN_SAFE_END(lz)
1263 } 1274 }
1264 1275
1265 static int 1276 static int
1266 takewhile_traverse(takewhileobject *lz, visitproc visit, void *arg) 1277 takewhile_traverse(takewhileobject *lz, visitproc visit, void *arg)
1267 { 1278 {
1268 Py_VISIT(lz->it); 1279 Py_VISIT(lz->it);
1269 Py_VISIT(lz->func); 1280 Py_VISIT(lz->func);
1270 return 0; 1281 return 0;
1271 } 1282 }
1272 1283
1273 static PyObject * 1284 static PyObject *
1274 takewhile_next(takewhileobject *lz) 1285 takewhile_next(takewhileobject *lz)
1275 { 1286 {
1276 PyObject *item, *good; 1287 PyObject *item, *good;
1277 PyObject *it = lz->it; 1288 PyObject *it = lz->it;
1278 long ok; 1289 long ok;
1279 1290
1280 if (lz->stop == 1) 1291 if (lz->stop == 1)
1281 return NULL; 1292 return NULL;
1282 1293
1294 if (Py_EnterRecursiveCall(" while iterating"))
1295 return NULL;
1283 item = (*Py_TYPE(it)->tp_iternext)(it); 1296 item = (*Py_TYPE(it)->tp_iternext)(it);
1297 Py_LeaveRecursiveCall();
1284 if (item == NULL) 1298 if (item == NULL)
1285 return NULL; 1299 return NULL;
1286 1300
1287 good = PyObject_CallFunctionObjArgs(lz->func, item, NULL); 1301 good = PyObject_CallFunctionObjArgs(lz->func, item, NULL);
1288 if (good == NULL) { 1302 if (good == NULL) {
1289 Py_DECREF(item); 1303 Py_DECREF(item);
1290 return NULL; 1304 return NULL;
1291 } 1305 }
1292 ok = PyObject_IsTrue(good); 1306 ok = PyObject_IsTrue(good);
1293 Py_DECREF(good); 1307 Py_DECREF(good);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 lz->step = step; 1479 lz->step = step;
1466 lz->cnt = 0L; 1480 lz->cnt = 0L;
1467 1481
1468 return (PyObject *)lz; 1482 return (PyObject *)lz;
1469 } 1483 }
1470 1484
1471 static void 1485 static void
1472 islice_dealloc(isliceobject *lz) 1486 islice_dealloc(isliceobject *lz)
1473 { 1487 {
1474 PyObject_GC_UnTrack(lz); 1488 PyObject_GC_UnTrack(lz);
1489 Py_TRASHCAN_SAFE_BEGIN(lz)
1475 Py_XDECREF(lz->it); 1490 Py_XDECREF(lz->it);
1476 Py_TYPE(lz)->tp_free(lz); 1491 Py_TYPE(lz)->tp_free(lz);
1492 Py_TRASHCAN_SAFE_END(lz)
1477 } 1493 }
1478 1494
1479 static int 1495 static int
1480 islice_traverse(isliceobject *lz, visitproc visit, void *arg) 1496 islice_traverse(isliceobject *lz, visitproc visit, void *arg)
1481 { 1497 {
1482 Py_VISIT(lz->it); 1498 Py_VISIT(lz->it);
1483 return 0; 1499 return 0;
1484 } 1500 }
1485 1501
1486 static PyObject * 1502 static PyObject *
1487 islice_next(isliceobject *lz) 1503 islice_next(isliceobject *lz)
1488 { 1504 {
1489 PyObject *item; 1505 PyObject *item;
1490 PyObject *it = lz->it; 1506 PyObject *it = lz->it;
1491 Py_ssize_t stop = lz->stop; 1507 Py_ssize_t stop = lz->stop;
1492 Py_ssize_t oldnext; 1508 Py_ssize_t oldnext;
1493 PyObject *(*iternext)(PyObject *); 1509 PyObject *(*iternext)(PyObject *);
1494 1510
1495 iternext = *Py_TYPE(it)->tp_iternext; 1511 iternext = *Py_TYPE(it)->tp_iternext;
1496 while (lz->cnt < lz->next) { 1512 while (lz->cnt < lz->next) {
1513 if (Py_EnterRecursiveCall(" while iterating"))
1514 return NULL;
1497 item = iternext(it); 1515 item = iternext(it);
1516 Py_LeaveRecursiveCall();
1498 if (item == NULL) 1517 if (item == NULL)
1499 return NULL; 1518 return NULL;
1500 Py_DECREF(item); 1519 Py_DECREF(item);
1501 lz->cnt++; 1520 lz->cnt++;
1502 } 1521 }
1503 if (stop != -1 && lz->cnt >= stop) 1522 if (stop != -1 && lz->cnt >= stop)
1504 return NULL; 1523 return NULL;
1524 if (Py_EnterRecursiveCall(" while iterating"))
1525 return NULL;
1505 item = iternext(it); 1526 item = iternext(it);
1527 Py_LeaveRecursiveCall();
1506 if (item == NULL) 1528 if (item == NULL)
1507 return NULL; 1529 return NULL;
1508 lz->cnt++; 1530 lz->cnt++;
1509 oldnext = lz->next; 1531 oldnext = lz->next;
1510 /* The (size_t) cast below avoids the danger of undefined 1532 /* The (size_t) cast below avoids the danger of undefined
1511 behaviour from signed integer overflow. */ 1533 behaviour from signed integer overflow. */
1512 lz->next += (size_t)lz->step; 1534 lz->next += (size_t)lz->step;
1513 if (lz->next < oldnext || (stop != -1 && lz->next > stop)) 1535 if (lz->next < oldnext || (stop != -1 && lz->next > stop))
1514 lz->next = stop; 1536 lz->next = stop;
1515 return item; 1537 return item;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 lz->func = func; 1668 lz->func = func;
1647 lz->it = it; 1669 lz->it = it;
1648 1670
1649 return (PyObject *)lz; 1671 return (PyObject *)lz;
1650 } 1672 }
1651 1673
1652 static void 1674 static void
1653 starmap_dealloc(starmapobject *lz) 1675 starmap_dealloc(starmapobject *lz)
1654 { 1676 {
1655 PyObject_GC_UnTrack(lz); 1677 PyObject_GC_UnTrack(lz);
1678 Py_TRASHCAN_SAFE_BEGIN(lz)
1656 Py_XDECREF(lz->func); 1679 Py_XDECREF(lz->func);
1657 Py_XDECREF(lz->it); 1680 Py_XDECREF(lz->it);
1658 Py_TYPE(lz)->tp_free(lz); 1681 Py_TYPE(lz)->tp_free(lz);
1682 Py_TRASHCAN_SAFE_END(lz)
1659 } 1683 }
1660 1684
1661 static int 1685 static int
1662 starmap_traverse(starmapobject *lz, visitproc visit, void *arg) 1686 starmap_traverse(starmapobject *lz, visitproc visit, void *arg)
1663 { 1687 {
1664 Py_VISIT(lz->it); 1688 Py_VISIT(lz->it);
1665 Py_VISIT(lz->func); 1689 Py_VISIT(lz->func);
1666 return 0; 1690 return 0;
1667 } 1691 }
1668 1692
1669 static PyObject * 1693 static PyObject *
1670 starmap_next(starmapobject *lz) 1694 starmap_next(starmapobject *lz)
1671 { 1695 {
1672 PyObject *args; 1696 PyObject *args;
1673 PyObject *result; 1697 PyObject *result;
1674 PyObject *it = lz->it; 1698 PyObject *it = lz->it;
1675 1699
1700 if (Py_EnterRecursiveCall(" while iterating"))
1701 return NULL;
1676 args = (*Py_TYPE(it)->tp_iternext)(it); 1702 args = (*Py_TYPE(it)->tp_iternext)(it);
1703 Py_LeaveRecursiveCall();
1677 if (args == NULL) 1704 if (args == NULL)
1678 return NULL; 1705 return NULL;
1679 if (!PyTuple_CheckExact(args)) { 1706 if (!PyTuple_CheckExact(args)) {
1680 PyObject *newargs = PySequence_Tuple(args); 1707 PyObject *newargs = PySequence_Tuple(args);
1681 Py_DECREF(args); 1708 Py_DECREF(args);
1682 if (newargs == NULL) 1709 if (newargs == NULL)
1683 return NULL; 1710 return NULL;
1684 args = newargs; 1711 args = newargs;
1685 } 1712 }
1686 result = PyObject_Call(lz->func, args, NULL); 1713 result = PyObject_Call(lz->func, args, NULL);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1802 if (source == NULL) 1829 if (source == NULL)
1803 return NULL; 1830 return NULL;
1804 1831
1805 return chain_new_internal(type, source); 1832 return chain_new_internal(type, source);
1806 } 1833 }
1807 1834
1808 static void 1835 static void
1809 chain_dealloc(chainobject *lz) 1836 chain_dealloc(chainobject *lz)
1810 { 1837 {
1811 PyObject_GC_UnTrack(lz); 1838 PyObject_GC_UnTrack(lz);
1839 Py_TRASHCAN_SAFE_BEGIN(lz)
1812 Py_XDECREF(lz->active); 1840 Py_XDECREF(lz->active);
1813 Py_XDECREF(lz->source); 1841 Py_XDECREF(lz->source);
1814 Py_TYPE(lz)->tp_free(lz); 1842 Py_TYPE(lz)->tp_free(lz);
1843 Py_TRASHCAN_SAFE_END(lz)
1815 } 1844 }
1816 1845
1817 static int 1846 static int
1818 chain_traverse(chainobject *lz, visitproc visit, void *arg) 1847 chain_traverse(chainobject *lz, visitproc visit, void *arg)
1819 { 1848 {
1820 Py_VISIT(lz->source); 1849 Py_VISIT(lz->source);
1821 Py_VISIT(lz->active); 1850 Py_VISIT(lz->active);
1822 return 0; 1851 return 0;
1823 } 1852 }
1824 1853
(...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after
3333 } 3362 }
3334 lz->total = NULL; 3363 lz->total = NULL;
3335 lz->it = it; 3364 lz->it = it;
3336 return (PyObject *)lz; 3365 return (PyObject *)lz;
3337 } 3366 }
3338 3367
3339 static void 3368 static void
3340 accumulate_dealloc(accumulateobject *lz) 3369 accumulate_dealloc(accumulateobject *lz)
3341 { 3370 {
3342 PyObject_GC_UnTrack(lz); 3371 PyObject_GC_UnTrack(lz);
3372 Py_TRASHCAN_SAFE_BEGIN(lz)
3343 Py_XDECREF(lz->binop); 3373 Py_XDECREF(lz->binop);
3344 Py_XDECREF(lz->total); 3374 Py_XDECREF(lz->total);
3345 Py_XDECREF(lz->it); 3375 Py_XDECREF(lz->it);
3346 Py_TYPE(lz)->tp_free(lz); 3376 Py_TYPE(lz)->tp_free(lz);
3377 Py_TRASHCAN_SAFE_END(lz)
3347 } 3378 }
3348 3379
3349 static int 3380 static int
3350 accumulate_traverse(accumulateobject *lz, visitproc visit, void *arg) 3381 accumulate_traverse(accumulateobject *lz, visitproc visit, void *arg)
3351 { 3382 {
3352 Py_VISIT(lz->binop); 3383 Py_VISIT(lz->binop);
3353 Py_VISIT(lz->it); 3384 Py_VISIT(lz->it);
3354 Py_VISIT(lz->total); 3385 Py_VISIT(lz->total);
3355 return 0; 3386 return 0;
3356 } 3387 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
3507 fail: 3538 fail:
3508 Py_XDECREF(data); 3539 Py_XDECREF(data);
3509 Py_XDECREF(selectors); 3540 Py_XDECREF(selectors);
3510 return NULL; 3541 return NULL;
3511 } 3542 }
3512 3543
3513 static void 3544 static void
3514 compress_dealloc(compressobject *lz) 3545 compress_dealloc(compressobject *lz)
3515 { 3546 {
3516 PyObject_GC_UnTrack(lz); 3547 PyObject_GC_UnTrack(lz);
3548 Py_TRASHCAN_SAFE_BEGIN(lz)
3517 Py_XDECREF(lz->data); 3549 Py_XDECREF(lz->data);
3518 Py_XDECREF(lz->selectors); 3550 Py_XDECREF(lz->selectors);
3519 Py_TYPE(lz)->tp_free(lz); 3551 Py_TYPE(lz)->tp_free(lz);
3552 Py_TRASHCAN_SAFE_END(lz)
3520 } 3553 }
3521 3554
3522 static int 3555 static int
3523 compress_traverse(compressobject *lz, visitproc visit, void *arg) 3556 compress_traverse(compressobject *lz, visitproc visit, void *arg)
3524 { 3557 {
3525 Py_VISIT(lz->data); 3558 Py_VISIT(lz->data);
3526 Py_VISIT(lz->selectors); 3559 Py_VISIT(lz->selectors);
3527 return 0; 3560 return 0;
3528 } 3561 }
3529 3562
3530 static PyObject * 3563 static PyObject *
3531 compress_next(compressobject *lz) 3564 compress_next(compressobject *lz)
3532 { 3565 {
3533 PyObject *data = lz->data, *selectors = lz->selectors; 3566 PyObject *data = lz->data, *selectors = lz->selectors;
3534 PyObject *datum, *selector; 3567 PyObject *datum, *selector;
3535 PyObject *(*datanext)(PyObject *) = *Py_TYPE(data)->tp_iternext; 3568 PyObject *(*datanext)(PyObject *) = *Py_TYPE(data)->tp_iternext;
3536 PyObject *(*selectornext)(PyObject *) = *Py_TYPE(selectors)->tp_iternext; 3569 PyObject *(*selectornext)(PyObject *) = *Py_TYPE(selectors)->tp_iternext;
3537 int ok; 3570 int ok;
3538 3571
3539 while (1) { 3572 while (1) {
3540 /* Steps: get datum, get selector, evaluate selector. 3573 /* Steps: get datum, get selector, evaluate selector.
3541 Order is important (to match the pure python version 3574 Order is important (to match the pure python version
3542 in terms of which input gets a chance to raise an 3575 in terms of which input gets a chance to raise an
3543 exception first). 3576 exception first).
3544 */ 3577 */
3545 3578
3579 if (Py_EnterRecursiveCall(" while iterating"))
3580 return NULL;
3546 datum = datanext(data); 3581 datum = datanext(data);
3582 Py_LeaveRecursiveCall();
3547 if (datum == NULL) 3583 if (datum == NULL)
3548 return NULL; 3584 return NULL;
3549 3585
3586 if (Py_EnterRecursiveCall(" while iterating")) {
3587 Py_DECREF(datum);
3588 return NULL;
3589 }
3550 selector = selectornext(selectors); 3590 selector = selectornext(selectors);
3591 Py_LeaveRecursiveCall();
3551 if (selector == NULL) { 3592 if (selector == NULL) {
3552 Py_DECREF(datum); 3593 Py_DECREF(datum);
3553 return NULL; 3594 return NULL;
3554 } 3595 }
3555 3596
3556 ok = PyObject_IsTrue(selector); 3597 ok = PyObject_IsTrue(selector);
3557 Py_DECREF(selector); 3598 Py_DECREF(selector);
3558 if (ok == 1) 3599 if (ok == 1)
3559 return datum; 3600 return datum;
3560 Py_DECREF(datum); 3601 Py_DECREF(datum);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
3667 lz->func = func; 3708 lz->func = func;
3668 lz->it = it; 3709 lz->it = it;
3669 3710
3670 return (PyObject *)lz; 3711 return (PyObject *)lz;
3671 } 3712 }
3672 3713
3673 static void 3714 static void
3674 filterfalse_dealloc(filterfalseobject *lz) 3715 filterfalse_dealloc(filterfalseobject *lz)
3675 { 3716 {
3676 PyObject_GC_UnTrack(lz); 3717 PyObject_GC_UnTrack(lz);
3718 Py_TRASHCAN_SAFE_BEGIN(lz)
3677 Py_XDECREF(lz->func); 3719 Py_XDECREF(lz->func);
3678 Py_XDECREF(lz->it); 3720 Py_XDECREF(lz->it);
3679 Py_TYPE(lz)->tp_free(lz); 3721 Py_TYPE(lz)->tp_free(lz);
3722 Py_TRASHCAN_SAFE_END(lz)
3680 } 3723 }
3681 3724
3682 static int 3725 static int
3683 filterfalse_traverse(filterfalseobject *lz, visitproc visit, void *arg) 3726 filterfalse_traverse(filterfalseobject *lz, visitproc visit, void *arg)
3684 { 3727 {
3685 Py_VISIT(lz->it); 3728 Py_VISIT(lz->it);
3686 Py_VISIT(lz->func); 3729 Py_VISIT(lz->func);
3687 return 0; 3730 return 0;
3688 } 3731 }
3689 3732
3690 static PyObject * 3733 static PyObject *
3691 filterfalse_next(filterfalseobject *lz) 3734 filterfalse_next(filterfalseobject *lz)
3692 { 3735 {
3693 PyObject *item; 3736 PyObject *item;
3694 PyObject *it = lz->it; 3737 PyObject *it = lz->it;
3695 long ok; 3738 long ok;
3696 PyObject *(*iternext)(PyObject *); 3739 PyObject *(*iternext)(PyObject *);
3697 3740
3698 iternext = *Py_TYPE(it)->tp_iternext; 3741 iternext = *Py_TYPE(it)->tp_iternext;
3699 for (;;) { 3742 for (;;) {
3743 if (Py_EnterRecursiveCall(" while iterating"))
3744 return NULL;
3700 item = iternext(it); 3745 item = iternext(it);
3746 Py_LeaveRecursiveCall();
3701 if (item == NULL) 3747 if (item == NULL)
3702 return NULL; 3748 return NULL;
3703 3749
3704 if (lz->func == Py_None || lz->func == (PyObject *)&PyBool_Type) { 3750 if (lz->func == Py_None || lz->func == (PyObject *)&PyBool_Type) {
3705 ok = PyObject_IsTrue(item); 3751 ok = PyObject_IsTrue(item);
3706 } else { 3752 } else {
3707 PyObject *good; 3753 PyObject *good;
3708 good = PyObject_CallFunctionObjArgs(lz->func, 3754 good = PyObject_CallFunctionObjArgs(lz->func,
3709 item, NULL); 3755 item, NULL);
3710 if (good == NULL) { 3756 if (good == NULL) {
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
4254 lz->result = result; 4300 lz->result = result;
4255 Py_INCREF(fillvalue); 4301 Py_INCREF(fillvalue);
4256 lz->fillvalue = fillvalue; 4302 lz->fillvalue = fillvalue;
4257 return (PyObject *)lz; 4303 return (PyObject *)lz;
4258 } 4304 }
4259 4305
4260 static void 4306 static void
4261 zip_longest_dealloc(ziplongestobject *lz) 4307 zip_longest_dealloc(ziplongestobject *lz)
4262 { 4308 {
4263 PyObject_GC_UnTrack(lz); 4309 PyObject_GC_UnTrack(lz);
4310 Py_TRASHCAN_SAFE_BEGIN(lz)
4264 Py_XDECREF(lz->ittuple); 4311 Py_XDECREF(lz->ittuple);
4265 Py_XDECREF(lz->result); 4312 Py_XDECREF(lz->result);
4266 Py_XDECREF(lz->fillvalue); 4313 Py_XDECREF(lz->fillvalue);
4267 Py_TYPE(lz)->tp_free(lz); 4314 Py_TYPE(lz)->tp_free(lz);
4315 Py_TRASHCAN_SAFE_END(lz)
4268 } 4316 }
4269 4317
4270 static int 4318 static int
4271 zip_longest_traverse(ziplongestobject *lz, visitproc visit, void *arg) 4319 zip_longest_traverse(ziplongestobject *lz, visitproc visit, void *arg)
4272 { 4320 {
4273 Py_VISIT(lz->ittuple); 4321 Py_VISIT(lz->ittuple);
4274 Py_VISIT(lz->result); 4322 Py_VISIT(lz->result);
4275 Py_VISIT(lz->fillvalue); 4323 Py_VISIT(lz->fillvalue);
4276 return 0; 4324 return 0;
4277 } 4325 }
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
4535 if (PyType_Ready(typelist[i]) < 0) 4583 if (PyType_Ready(typelist[i]) < 0)
4536 return NULL; 4584 return NULL;
4537 name = strchr(typelist[i]->tp_name, '.'); 4585 name = strchr(typelist[i]->tp_name, '.');
4538 assert (name != NULL); 4586 assert (name != NULL);
4539 Py_INCREF(typelist[i]); 4587 Py_INCREF(typelist[i]);
4540 PyModule_AddObject(m, name+1, (PyObject *)typelist[i]); 4588 PyModule_AddObject(m, name+1, (PyObject *)typelist[i]);
4541 } 4589 }
4542 4590
4543 return m; 4591 return m;
4544 } 4592 }
OLDNEW
« no previous file with comments | « Lib/test/test_itertools.py ('k') | Objects/abstract.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+