| 1 | import pytest |
| 2 | from rpython.tool.udir import udir |
| 3 | |
| 4 | |
| 5 | def test_recursion_error_in_subprocess(space): |
| 6 | import py |
| 7 | import sys |
| 8 | if sys.platform == "win32": |
| 9 | pytest.skip("no ForkedProcess on windows") |
| 10 | |
| 11 | def f(): |
| 12 | space.appexec([], """(): |
| 13 | # test from CPython |
| 14 | |
| 15 | import marshal |
| 16 | def run_tests(N, check): |
| 17 | # (((...None...),),) |
| 18 | check(b')\x01' * N + b'N') |
| 19 | # PyPy fix: use bytes(3) instead of literal null bytes to avoid |
| 20 | # null bytes in the source string passed to the compiler |
| 21 | check((b'(\x01' + bytes(3)) * N + b'N') |
| 22 | # [[[...None...]]] |
| 23 | check((b'[\x01' + bytes(3)) * N + b'N') |
| 24 | # {None: {None: {None: ...None...}}} |
| 25 | check(b'{N' * N + b'N' + b'0' * N) |
| 26 | # frozenset([frozenset([frozenset([...None...])])]) |
| 27 | check((b'>\x01' + bytes(3)) * N + b'N') |
| 28 | # Check that the generated marshal data is valid and marshal.loads() |
| 29 | # works for moderately deep nesting |
| 30 | run_tests(100, marshal.loads) |
| 31 | # Very deeply nested structure shouldn't blow the stack |
| 32 | def check(s): |
| 33 | raises(ValueError, marshal.loads, s) |
| 34 | run_tests(2**20, check)""") |
| 35 | |
| 36 | ff = py.process.ForkedFunc(f) |
| 37 | res = ff.waitfinish() |
| 38 | assert res.exitstatus == 0, res.err |