cpython: e289b64f355d (original) (raw)
Mercurial > cpython
changeset 69075:e289b64f355d
Issue #11393: limit stack overflow test to 100 MB Stop if the stack overflow doesn't occur after allocating 100 MB on the stack. [#11393]
Victor Stinner victor.stinner@haypocalc.com | |
---|---|
date | Thu, 31 Mar 2011 11:34:08 +0200 |
parents | a6d2c703586a |
children | aa2ac1581d23 |
files | Lib/test/test_faulthandler.py Modules/faulthandler.c |
diffstat | 2 files changed, 37 insertions(+), 8 deletions(-)[+] [-] Lib/test/test_faulthandler.py 8 Modules/faulthandler.c 37 |
line wrap: on
line diff
--- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -69,7 +69,7 @@ class FaultHandlerTests(unittest.TestCas return output.splitlines() def check_fatal_error(self, code, line_number, name_regex,
filename=None, all_threads=False):[](#l1.7)
filename=None, all_threads=False, other_regex=None):[](#l1.8) """[](#l1.9) Check that the fault handler for fatal errors is enabled and check the[](#l1.10) traceback from the child process output.[](#l1.11)
@@ -90,6 +90,8 @@ class FaultHandlerTests(unittest.TestCas lineno=line_number, name=name_regex, header=re.escape(header))
if other_regex:[](#l1.16)
regex += '|' + other_regex[](#l1.17) output = self.get_output(code, False, filename)[](#l1.18) output = '\n'.join(output)[](#l1.19) self.assertRegex(output, regex)[](#l1.20)
@@ -153,7 +155,6 @@ faulthandler._fatal_error(b'xyz') 2, 'xyz')
- @unittest.skipIf(True, 'test disabled, see #11393') @unittest.skipIf(not hasattr(faulthandler, '_stack_overflow'), 'need faulthandler._stack_overflow()') def test_stack_overflow(self): @@ -163,7 +164,8 @@ faulthandler.enable() faulthandler._stack_overflow() """.strip(), 3,
'(?:Segmentation fault|Bus error)')[](#l1.33)
'(?:Segmentation fault|Bus error)',[](#l1.34)
other_regex='unable to raise a stack overflow')[](#l1.35)
def test_gil_released(self): self.check_fatal_error("""
--- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -16,6 +16,9 @@
define FAULTHANDLER_USER
#endif +/* Allocate at maximum 100 MB of the stack to raise the stack overflow / +#define STACK_OVERFLOW_MAX_SIZE (1001024*1024) + #define PUTS(fd, str) write(fd, str, strlen(str)) #ifdef HAVE_SIGACTION @@ -742,15 +745,39 @@ faulthandler_fatal_error_py(PyObject *se } #if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION) -static PyObject * -faulthandler_stack_overflow(PyObject self) +void +stack_overflow(void *min_sp, void *max_sp, size_t depth) { / allocate 4096 bytes on the stack at each call */ unsigned char buffer[4096];
- void *sp = &buffer;
- *depth += 1;
- if (sp < min_sp || max_sp < sp)
buffer[0] = 1;return sp;[](#l2.27)
- buffer[4095] = 2;
- faulthandler_stack_overflow(self);
- return PyLong_FromLong(buffer[0] + buffer[4095]);
+} + +static PyObject * +faulthandler_stack_overflow(PyObject *self) +{
- depth = 0;
- stop = stack_overflow(sp - STACK_OVERFLOW_MAX_SIZE,
sp + STACK_OVERFLOW_MAX_SIZE,[](#l2.44)
&depth);[](#l2.45)
- if (sp < stop)
size = stop - sp;[](#l2.47)
- else
size = sp - stop;[](#l2.49)
- PyErr_Format(PyExc_RuntimeError,
"unable to raise a stack overflow (allocated %zu bytes "[](#l2.51)
"on the stack, %zu recursive calls)",[](#l2.52)
size, depth);[](#l2.53)
- return NULL;