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

Side by Side Diff: Objects/abstract.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 | « Modules/itertoolsmodule.c ('k') | Python/bltinmodule.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 /* Abstract Object Interface (many thanks to Jim Fulton) */ 1 /* Abstract Object Interface (many thanks to Jim Fulton) */
2 2
3 #include "Python.h" 3 #include "Python.h"
4 #include <ctype.h> 4 #include <ctype.h>
5 #include "structmember.h" /* we need the offsetof() macro from there */ 5 #include "structmember.h" /* we need the offsetof() macro from there */
6 #include "longintrepr.h" 6 #include "longintrepr.h"
7 7
8 8
9 9
10 /* Shorthands to return certain errors */ 10 /* Shorthands to return certain errors */
(...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 Py_DECREF(value); 1231 Py_DECREF(value);
1232 return result; 1232 return result;
1233 } 1233 }
1234 1234
1235 1235
1236 /* 1236 /*
1237 Returns the Integral instance converted to an int. The instance is expected 1237 Returns the Integral instance converted to an int. The instance is expected
1238 to be an int or have an __int__ method. Steals integral's 1238 to be an int or have an __int__ method. Steals integral's
1239 reference. error_format will be used to create the TypeError if integral 1239 reference. error_format will be used to create the TypeError if integral
1240 isn't actually an Integral instance. error_format should be a format string 1240 isn't actually an Integral instance. error_format should be a format string
1241 that can accept a char* naming integral's type. 1241 that can accept a char* naming integral's type.
1242 */ 1242 */
1243 static PyObject * 1243 static PyObject *
1244 convert_integral_to_int(PyObject *integral, const char *error_format) 1244 convert_integral_to_int(PyObject *integral, const char *error_format)
1245 { 1245 {
1246 PyNumberMethods *nb; 1246 PyNumberMethods *nb;
1247 if (PyLong_Check(integral)) 1247 if (PyLong_Check(integral))
1248 return integral; 1248 return integral;
1249 nb = Py_TYPE(integral)->tp_as_number; 1249 nb = Py_TYPE(integral)->tp_as_number;
1250 if (nb->nb_int) { 1250 if (nb->nb_int) {
1251 PyObject *as_int = nb->nb_int(integral); 1251 PyObject *as_int = nb->nb_int(integral);
1252 if (!as_int || PyLong_Check(as_int)) { 1252 if (!as_int || PyLong_Check(as_int)) {
1253 Py_DECREF(integral); 1253 Py_DECREF(integral);
1254 return as_int; 1254 return as_int;
1255 } 1255 }
1256 Py_DECREF(as_int); 1256 Py_DECREF(as_int);
1257 } 1257 }
1258 PyErr_Format(PyExc_TypeError, error_format, Py_TYPE(integral)->tp_name); 1258 PyErr_Format(PyExc_TypeError, error_format, Py_TYPE(integral)->tp_name);
1259 Py_DECREF(integral); 1259 Py_DECREF(integral);
1260 return NULL; 1260 return NULL;
1261 } 1261 }
1262 1262
1263 1263
1264 /* Add a check for embedded NULL-bytes in the argument. */ 1264 /* Add a check for embedded NULL-bytes in the argument. */
1265 static PyObject * 1265 static PyObject *
1266 long_from_string(const char *s, Py_ssize_t len) 1266 long_from_string(const char *s, Py_ssize_t len)
1267 { 1267 {
1268 char *end; 1268 char *end;
1269 PyObject *x; 1269 PyObject *x;
1270 1270
(...skipping 1424 matching lines...) Expand 10 before | Expand all | Expand 10 after
2695 * If an error occurs, return NULL. PyErr_Occurred() will be true. 2695 * If an error occurs, return NULL. PyErr_Occurred() will be true.
2696 * If the iteration terminates normally, return NULL and clear the 2696 * If the iteration terminates normally, return NULL and clear the
2697 * PyExc_StopIteration exception (if it was set). PyErr_Occurred() 2697 * PyExc_StopIteration exception (if it was set). PyErr_Occurred()
2698 * will be false. 2698 * will be false.
2699 * Else return the next object. PyErr_Occurred() will be false. 2699 * Else return the next object. PyErr_Occurred() will be false.
2700 */ 2700 */
2701 PyObject * 2701 PyObject *
2702 PyIter_Next(PyObject *iter) 2702 PyIter_Next(PyObject *iter)
2703 { 2703 {
2704 PyObject *result; 2704 PyObject *result;
2705 if (Py_EnterRecursiveCall(" while iterating"))
2706 return NULL;
2705 result = (*iter->ob_type->tp_iternext)(iter); 2707 result = (*iter->ob_type->tp_iternext)(iter);
2708 Py_LeaveRecursiveCall();
2706 if (result == NULL && 2709 if (result == NULL &&
2707 PyErr_Occurred() && 2710 PyErr_Occurred() &&
2708 PyErr_ExceptionMatches(PyExc_StopIteration)) 2711 PyErr_ExceptionMatches(PyExc_StopIteration))
2709 PyErr_Clear(); 2712 PyErr_Clear();
2710 return result; 2713 return result;
2711 } 2714 }
2712 2715
2713 2716
2714 /* 2717 /*
2715 * Flatten a sequence of bytes() objects into a C array of 2718 * Flatten a sequence of bytes() objects into a C array of
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2777 /* Free's a NULL terminated char** array of C strings. */ 2780 /* Free's a NULL terminated char** array of C strings. */
2778 void 2781 void
2779 _Py_FreeCharPArray(char *const array[]) 2782 _Py_FreeCharPArray(char *const array[])
2780 { 2783 {
2781 Py_ssize_t i; 2784 Py_ssize_t i;
2782 for (i = 0; array[i] != NULL; ++i) { 2785 for (i = 0; array[i] != NULL; ++i) {
2783 free(array[i]); 2786 free(array[i]);
2784 } 2787 }
2785 free((void*)array); 2788 free((void*)array);
2786 } 2789 }
OLDNEW
« no previous file with comments | « Modules/itertoolsmodule.c ('k') | Python/bltinmodule.c » ('j') | no next file with comments »

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