Skip to content

Commit 8bc2c01

Browse files
Do not limit the address space where it cannot work
AddressSanitizer reserves terabytes of address space for its shadow memory, so any limit stops the interpreter from starting. macOS reserves much more address space than Linux does, so 512 MiB is not enough of a margin there.
1 parent 9043fa5 commit 8bc2c01

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

Lib/test/support/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,14 +1276,19 @@ def _limit_address_space(nbytes):
12761276
A test which uses much more memory than it declares then fails with a
12771277
MemoryError instead of making the machine swap.
12781278
"""
1279+
if check_sanitizer(address=True):
1280+
# AddressSanitizer reserves terabytes of address space for its shadow
1281+
# memory, so any limit stops the interpreter from starting.
1282+
return
12791283
try:
12801284
import resource
12811285
rlimit = resource.RLIMIT_AS
12821286
except (ImportError, AttributeError):
12831287
return
12841288
# The margin does not grow with the declared size: the interpreter itself
1285-
# reserves about 250 MiB, whatever the test asks for.
1286-
limit = int(nbytes) + 512 * _1M
1289+
# reserves about 250 MiB, whatever the test asks for. macOS reserves more.
1290+
margin = _1G if sys.platform == 'darwin' else 512 * _1M
1291+
limit = int(nbytes) + margin
12871292
soft, hard = resource.getrlimit(rlimit)
12881293
for current in soft, hard:
12891294
if current != resource.RLIM_INFINITY:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
A test decorated with :func:`~test.support.bigmemtest` now runs with the
2-
address space limited to what it declares plus 512 MiB, so that a test which
2+
address space limited to what it declares plus a margin, so that a test which
33
uses much more memory than it declares fails instead of making the machine
44
swap. Pass ``limit_address_space=False`` for a test which reserves much more
55
address space than it uses.

0 commit comments

Comments
 (0)