|
10 | 10 | import errno
|
11 | 11 | from textwrap import dedent
|
12 | 12 |
|
| 13 | +from _testcapi import INT_MAX |
13 | 14 | from test.support import (captured_stderr, check_impl_detail,
|
14 | 15 | cpython_only, gc_collect,
|
15 | 16 | no_tracing, script_helper,
|
@@ -322,19 +323,18 @@ def baz():
|
322 | 323 | @unittest.skipIf(ctypes.sizeof(ctypes.c_int) >= ctypes.sizeof(ctypes.c_ssize_t),
|
323 | 324 | "Downcasting to int is safe for col_offset")
|
324 | 325 | @support.requires_resource('cpu')
|
325 |
| - @support.bigmemtest(2**(ctypes.sizeof(ctypes.c_int)*8-1)-1-len("pass"), memuse=1) |
| 326 | + @support.bigmemtest(INT_MAX, memuse=2, dry_run=False) |
326 | 327 | def testMemoryErrorBigSource(self, size):
|
327 |
| - if size < 2**(ctypes.sizeof(ctypes.c_int)*8-1)-1-len("pass"): |
| 328 | + padding_needed = INT_MAX-len("pass") |
| 329 | + if size < padding_needed: |
328 | 330 | self.skipTest('Not enough memory for overflow to occur')
|
329 | 331 |
|
330 | 332 | # Construct buffer to hold just enough characters so that the tokenizer offset overflows.
|
331 | 333 | # This makes sure that we don't overflow in the string creation itself
|
332 |
| - distance_to_prev_divisible_by_8 = size & 7 |
333 |
| - padding = ' ' * distance_to_prev_divisible_by_8 |
334 |
| - padding += ' ' * ((size - distance_to_prev_divisible_by_8) // 8) |
| 334 | + src = f"if True:\n{' ' * padding_needed}pass" |
335 | 335 |
|
336 | 336 | with self.assertRaisesRegex(OverflowError, "Parser column offset overflow"):
|
337 |
| - exec(f"if True:\n{padding}pass") |
| 337 | + compile(src, '<fragment>', 'exec') |
338 | 338 |
|
339 | 339 | @cpython_only
|
340 | 340 | def testSettingException(self):
|
|
0 commit comments