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

Side by Side Diff: Python/bltinmodule.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 | « Objects/abstract.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Built-in functions */ 1 /* Built-in functions */
2 2
3 #include "Python.h" 3 #include "Python.h"
4 #include "Python-ast.h" 4 #include "Python-ast.h"
5 5
6 #include "node.h" 6 #include "node.h"
7 #include "code.h" 7 #include "code.h"
8 8
9 #include "asdl.h" 9 #include "asdl.h"
10 #include "ast.h" 10 #include "ast.h"
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 lz->func = func; 384 lz->func = func;
385 lz->it = it; 385 lz->it = it;
386 386
387 return (PyObject *)lz; 387 return (PyObject *)lz;
388 } 388 }
389 389
390 static void 390 static void
391 filter_dealloc(filterobject *lz) 391 filter_dealloc(filterobject *lz)
392 { 392 {
393 PyObject_GC_UnTrack(lz); 393 PyObject_GC_UnTrack(lz);
394 Py_TRASHCAN_SAFE_BEGIN(lz)
394 Py_XDECREF(lz->func); 395 Py_XDECREF(lz->func);
395 Py_XDECREF(lz->it); 396 Py_XDECREF(lz->it);
396 Py_TYPE(lz)->tp_free(lz); 397 Py_TYPE(lz)->tp_free(lz);
398 Py_TRASHCAN_SAFE_END(lz)
397 } 399 }
398 400
399 static int 401 static int
400 filter_traverse(filterobject *lz, visitproc visit, void *arg) 402 filter_traverse(filterobject *lz, visitproc visit, void *arg)
401 { 403 {
402 Py_VISIT(lz->it); 404 Py_VISIT(lz->it);
403 Py_VISIT(lz->func); 405 Py_VISIT(lz->func);
404 return 0; 406 return 0;
405 } 407 }
406 408
407 static PyObject * 409 static PyObject *
408 filter_next(filterobject *lz) 410 filter_next(filterobject *lz)
409 { 411 {
410 PyObject *item; 412 PyObject *item;
411 PyObject *it = lz->it; 413 PyObject *it = lz->it;
412 long ok; 414 long ok;
413 PyObject *(*iternext)(PyObject *); 415 PyObject *(*iternext)(PyObject *);
414 416
415 iternext = *Py_TYPE(it)->tp_iternext; 417 iternext = *Py_TYPE(it)->tp_iternext;
416 for (;;) { 418 for (;;) {
419 if (Py_EnterRecursiveCall(" while iterating"))
420 return NULL;
417 item = iternext(it); 421 item = iternext(it);
422 Py_LeaveRecursiveCall();
418 if (item == NULL) 423 if (item == NULL)
419 return NULL; 424 return NULL;
420 425
421 if (lz->func == Py_None || lz->func == (PyObject *)&PyBool_Type) { 426 if (lz->func == Py_None || lz->func == (PyObject *)&PyBool_Type) {
422 ok = PyObject_IsTrue(item); 427 ok = PyObject_IsTrue(item);
423 } else { 428 } else {
424 PyObject *good; 429 PyObject *good;
425 good = PyObject_CallFunctionObjArgs(lz->func, 430 good = PyObject_CallFunctionObjArgs(lz->func,
426 item, NULL); 431 item, NULL);
427 if (good == NULL) { 432 if (good == NULL) {
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 Py_INCREF(func); 1029 Py_INCREF(func);
1025 lz->func = func; 1030 lz->func = func;
1026 1031
1027 return (PyObject *)lz; 1032 return (PyObject *)lz;
1028 } 1033 }
1029 1034
1030 static void 1035 static void
1031 map_dealloc(mapobject *lz) 1036 map_dealloc(mapobject *lz)
1032 { 1037 {
1033 PyObject_GC_UnTrack(lz); 1038 PyObject_GC_UnTrack(lz);
1039 Py_TRASHCAN_SAFE_BEGIN(lz)
1034 Py_XDECREF(lz->iters); 1040 Py_XDECREF(lz->iters);
1035 Py_XDECREF(lz->func); 1041 Py_XDECREF(lz->func);
1036 Py_TYPE(lz)->tp_free(lz); 1042 Py_TYPE(lz)->tp_free(lz);
1043 Py_TRASHCAN_SAFE_END(lz)
1037 } 1044 }
1038 1045
1039 static int 1046 static int
1040 map_traverse(mapobject *lz, visitproc visit, void *arg) 1047 map_traverse(mapobject *lz, visitproc visit, void *arg)
1041 { 1048 {
1042 Py_VISIT(lz->iters); 1049 Py_VISIT(lz->iters);
1043 Py_VISIT(lz->func); 1050 Py_VISIT(lz->func);
1044 return 0; 1051 return 0;
1045 } 1052 }
1046 1053
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after
2212 lz->tuplesize = tuplesize; 2219 lz->tuplesize = tuplesize;
2213 lz->result = result; 2220 lz->result = result;
2214 2221
2215 return (PyObject *)lz; 2222 return (PyObject *)lz;
2216 } 2223 }
2217 2224
2218 static void 2225 static void
2219 zip_dealloc(zipobject *lz) 2226 zip_dealloc(zipobject *lz)
2220 { 2227 {
2221 PyObject_GC_UnTrack(lz); 2228 PyObject_GC_UnTrack(lz);
2229 Py_TRASHCAN_SAFE_BEGIN(lz)
2222 Py_XDECREF(lz->ittuple); 2230 Py_XDECREF(lz->ittuple);
2223 Py_XDECREF(lz->result); 2231 Py_XDECREF(lz->result);
2224 Py_TYPE(lz)->tp_free(lz); 2232 Py_TYPE(lz)->tp_free(lz);
2233 Py_TRASHCAN_SAFE_END(lz)
2225 } 2234 }
2226 2235
2227 static int 2236 static int
2228 zip_traverse(zipobject *lz, visitproc visit, void *arg) 2237 zip_traverse(zipobject *lz, visitproc visit, void *arg)
2229 { 2238 {
2230 Py_VISIT(lz->ittuple); 2239 Py_VISIT(lz->ittuple);
2231 Py_VISIT(lz->result); 2240 Py_VISIT(lz->result);
2232 return 0; 2241 return 0;
2233 } 2242 }
2234 2243
2235 static PyObject * 2244 static PyObject *
2236 zip_next(zipobject *lz) 2245 zip_next(zipobject *lz)
2237 { 2246 {
2238 Py_ssize_t i; 2247 Py_ssize_t i;
2239 Py_ssize_t tuplesize = lz->tuplesize; 2248 Py_ssize_t tuplesize = lz->tuplesize;
2240 PyObject *result = lz->result; 2249 PyObject *result = lz->result;
2241 PyObject *it; 2250 PyObject *it;
2242 PyObject *item; 2251 PyObject *item;
2243 PyObject *olditem; 2252 PyObject *olditem;
2244 2253
2245 if (tuplesize == 0) 2254 if (tuplesize == 0)
2255 return NULL;
2256 if (Py_EnterRecursiveCall(" while iterating"))
2246 return NULL; 2257 return NULL;
2247 if (Py_REFCNT(result) == 1) { 2258 if (Py_REFCNT(result) == 1) {
2248 Py_INCREF(result); 2259 Py_INCREF(result);
2249 for (i=0 ; i < tuplesize ; i++) { 2260 for (i=0 ; i < tuplesize ; i++) {
2250 it = PyTuple_GET_ITEM(lz->ittuple, i); 2261 it = PyTuple_GET_ITEM(lz->ittuple, i);
2251 item = (*Py_TYPE(it)->tp_iternext)(it); 2262 item = (*Py_TYPE(it)->tp_iternext)(it);
2252 if (item == NULL) { 2263 if (item == NULL) {
2264 Py_LeaveRecursiveCall();
2253 Py_DECREF(result); 2265 Py_DECREF(result);
2254 return NULL; 2266 return NULL;
2255 } 2267 }
2256 olditem = PyTuple_GET_ITEM(result, i); 2268 olditem = PyTuple_GET_ITEM(result, i);
2257 PyTuple_SET_ITEM(result, i, item); 2269 PyTuple_SET_ITEM(result, i, item);
2258 Py_DECREF(olditem); 2270 Py_DECREF(olditem);
2259 } 2271 }
2260 } else { 2272 } else {
2261 result = PyTuple_New(tuplesize); 2273 result = PyTuple_New(tuplesize);
2262 if (result == NULL) 2274 if (result == NULL) {
2275 Py_LeaveRecursiveCall();
2263 return NULL; 2276 return NULL;
2277 }
2264 for (i=0 ; i < tuplesize ; i++) { 2278 for (i=0 ; i < tuplesize ; i++) {
2265 it = PyTuple_GET_ITEM(lz->ittuple, i); 2279 it = PyTuple_GET_ITEM(lz->ittuple, i);
2266 item = (*Py_TYPE(it)->tp_iternext)(it); 2280 item = (*Py_TYPE(it)->tp_iternext)(it);
2267 if (item == NULL) { 2281 if (item == NULL) {
2282 Py_LeaveRecursiveCall();
2268 Py_DECREF(result); 2283 Py_DECREF(result);
2269 return NULL; 2284 return NULL;
2270 } 2285 }
2271 PyTuple_SET_ITEM(result, i, item); 2286 PyTuple_SET_ITEM(result, i, item);
2272 } 2287 }
2273 } 2288 }
2289 Py_LeaveRecursiveCall();
2274 return result; 2290 return result;
2275 } 2291 }
2276 2292
2277 static PyObject * 2293 static PyObject *
2278 zip_reduce(zipobject *lz) 2294 zip_reduce(zipobject *lz)
2279 { 2295 {
2280 /* Just recreate the zip with the internal iterator tuple */ 2296 /* Just recreate the zip with the internal iterator tuple */
2281 return Py_BuildValue("OO", Py_TYPE(lz), lz->ittuple); 2297 return Py_BuildValue("OO", Py_TYPE(lz), lz->ittuple);
2282 } 2298 }
2283 2299
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
2470 if (PyDict_SetItemString(dict, "__debug__", debug) < 0) { 2486 if (PyDict_SetItemString(dict, "__debug__", debug) < 0) {
2471 Py_XDECREF(debug); 2487 Py_XDECREF(debug);
2472 return NULL; 2488 return NULL;
2473 } 2489 }
2474 Py_XDECREF(debug); 2490 Py_XDECREF(debug);
2475 2491
2476 return mod; 2492 return mod;
2477 #undef ADD_TO_ALL 2493 #undef ADD_TO_ALL
2478 #undef SETBUILTIN 2494 #undef SETBUILTIN
2479 } 2495 }
OLDNEW
« no previous file with comments | « Objects/abstract.c ('k') | no next file » | no next file with comments »

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