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

Unified Diff: Modules/itertoolsmodule.c

Issue 14010: deeply nested filter segfaults
Patch Set: Created 6 years, 6 months ago
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/test/test_itertools.py ('k') | Objects/abstract.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Modules/itertoolsmodule.c Tue Mar 19 13:27:24 2013 +0200
+++ b/Modules/itertoolsmodule.c Tue Mar 19 20:08:58 2013 +0200
@@ -54,12 +54,14 @@
groupby_dealloc(groupbyobject *gbo)
{
PyObject_GC_UnTrack(gbo);
+ Py_TRASHCAN_SAFE_BEGIN(gbo)
Py_XDECREF(gbo->it);
Py_XDECREF(gbo->keyfunc);
Py_XDECREF(gbo->tgtkey);
Py_XDECREF(gbo->currkey);
Py_XDECREF(gbo->currvalue);
Py_TYPE(gbo)->tp_free(gbo);
+ Py_TRASHCAN_SAFE_END(gbo)
}
static int
@@ -911,9 +913,11 @@
cycle_dealloc(cycleobject *lz)
{
PyObject_GC_UnTrack(lz);
+ Py_TRASHCAN_SAFE_BEGIN(lz)
Py_XDECREF(lz->saved);
Py_XDECREF(lz->it);
Py_TYPE(lz)->tp_free(lz);
+ Py_TRASHCAN_SAFE_END(lz)
}
static int
@@ -1088,9 +1092,11 @@
dropwhile_dealloc(dropwhileobject *lz)
{
PyObject_GC_UnTrack(lz);
+ Py_TRASHCAN_SAFE_BEGIN(lz)
Py_XDECREF(lz->func);
Py_XDECREF(lz->it);
Py_TYPE(lz)->tp_free(lz);
+ Py_TRASHCAN_SAFE_END(lz)
}
static int
@@ -1111,7 +1117,10 @@
iternext = *Py_TYPE(it)->tp_iternext;
for (;;) {
+ if (Py_EnterRecursiveCall(" while iterating"))
+ return NULL;
item = iternext(it);
+ Py_LeaveRecursiveCall();
if (item == NULL)
return NULL;
if (lz->start == 1)
@@ -1257,9 +1266,11 @@
takewhile_dealloc(takewhileobject *lz)
{
PyObject_GC_UnTrack(lz);
+ Py_TRASHCAN_SAFE_BEGIN(lz)
Py_XDECREF(lz->func);
Py_XDECREF(lz->it);
Py_TYPE(lz)->tp_free(lz);
+ Py_TRASHCAN_SAFE_END(lz)
}
static int
@@ -1280,7 +1291,10 @@
if (lz->stop == 1)
return NULL;
+ if (Py_EnterRecursiveCall(" while iterating"))
+ return NULL;
item = (*Py_TYPE(it)->tp_iternext)(it);
+ Py_LeaveRecursiveCall();
if (item == NULL)
return NULL;
@@ -1472,8 +1486,10 @@
islice_dealloc(isliceobject *lz)
{
PyObject_GC_UnTrack(lz);
+ Py_TRASHCAN_SAFE_BEGIN(lz)
Py_XDECREF(lz->it);
Py_TYPE(lz)->tp_free(lz);
+ Py_TRASHCAN_SAFE_END(lz)
}
static int
@@ -1494,7 +1510,10 @@
iternext = *Py_TYPE(it)->tp_iternext;
while (lz->cnt < lz->next) {
+ if (Py_EnterRecursiveCall(" while iterating"))
+ return NULL;
item = iternext(it);
+ Py_LeaveRecursiveCall();
if (item == NULL)
return NULL;
Py_DECREF(item);
@@ -1502,7 +1521,10 @@
}
if (stop != -1 && lz->cnt >= stop)
return NULL;
+ if (Py_EnterRecursiveCall(" while iterating"))
+ return NULL;
item = iternext(it);
+ Py_LeaveRecursiveCall();
if (item == NULL)
return NULL;
lz->cnt++;
@@ -1653,9 +1675,11 @@
starmap_dealloc(starmapobject *lz)
{
PyObject_GC_UnTrack(lz);
+ Py_TRASHCAN_SAFE_BEGIN(lz)
Py_XDECREF(lz->func);
Py_XDECREF(lz->it);
Py_TYPE(lz)->tp_free(lz);
+ Py_TRASHCAN_SAFE_END(lz)
}
static int
@@ -1673,7 +1697,10 @@
PyObject *result;
PyObject *it = lz->it;
+ if (Py_EnterRecursiveCall(" while iterating"))
+ return NULL;
args = (*Py_TYPE(it)->tp_iternext)(it);
+ Py_LeaveRecursiveCall();
if (args == NULL)
return NULL;
if (!PyTuple_CheckExact(args)) {
@@ -1809,9 +1836,11 @@
chain_dealloc(chainobject *lz)
{
PyObject_GC_UnTrack(lz);
+ Py_TRASHCAN_SAFE_BEGIN(lz)
Py_XDECREF(lz->active);
Py_XDECREF(lz->source);
Py_TYPE(lz)->tp_free(lz);
+ Py_TRASHCAN_SAFE_END(lz)
}
static int
@@ -3340,10 +3369,12 @@
accumulate_dealloc(accumulateobject *lz)
{
PyObject_GC_UnTrack(lz);
+ Py_TRASHCAN_SAFE_BEGIN(lz)
Py_XDECREF(lz->binop);
Py_XDECREF(lz->total);
Py_XDECREF(lz->it);
Py_TYPE(lz)->tp_free(lz);
+ Py_TRASHCAN_SAFE_END(lz)
}
static int
@@ -3514,9 +3545,11 @@
compress_dealloc(compressobject *lz)
{
PyObject_GC_UnTrack(lz);
+ Py_TRASHCAN_SAFE_BEGIN(lz)
Py_XDECREF(lz->data);
Py_XDECREF(lz->selectors);
Py_TYPE(lz)->tp_free(lz);
+ Py_TRASHCAN_SAFE_END(lz)
}
static int
@@ -3543,11 +3576,19 @@
exception first).
*/
+ if (Py_EnterRecursiveCall(" while iterating"))
+ return NULL;
datum = datanext(data);
+ Py_LeaveRecursiveCall();
if (datum == NULL)
return NULL;
+ if (Py_EnterRecursiveCall(" while iterating")) {
+ Py_DECREF(datum);
+ return NULL;
+ }
selector = selectornext(selectors);
+ Py_LeaveRecursiveCall();
if (selector == NULL) {
Py_DECREF(datum);
return NULL;
@@ -3674,9 +3715,11 @@
filterfalse_dealloc(filterfalseobject *lz)
{
PyObject_GC_UnTrack(lz);
+ Py_TRASHCAN_SAFE_BEGIN(lz)
Py_XDECREF(lz->func);
Py_XDECREF(lz->it);
Py_TYPE(lz)->tp_free(lz);
+ Py_TRASHCAN_SAFE_END(lz)
}
static int
@@ -3697,7 +3740,10 @@
iternext = *Py_TYPE(it)->tp_iternext;
for (;;) {
+ if (Py_EnterRecursiveCall(" while iterating"))
+ return NULL;
item = iternext(it);
+ Py_LeaveRecursiveCall();
if (item == NULL)
return NULL;
@@ -4261,10 +4307,12 @@
zip_longest_dealloc(ziplongestobject *lz)
{
PyObject_GC_UnTrack(lz);
+ Py_TRASHCAN_SAFE_BEGIN(lz)
Py_XDECREF(lz->ittuple);
Py_XDECREF(lz->result);
Py_XDECREF(lz->fillvalue);
Py_TYPE(lz)->tp_free(lz);
+ Py_TRASHCAN_SAFE_END(lz)
}
static int
« 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+