Skip to content

Commit a5d9963

Browse files
bpo-40928: notify users running test_decimal on macOS of malloc warnings (GH-26783)
* When trying to allocate very large regions on macOS, malloc does not fail silently. It sends a noisy error out to STDERR * This provides a helper function to warn the user, and provides the warning for test_decimal, which consistently generates these warnings on macOS. Co-authored-by: Łukasz Langa <[email protected]> (cherry picked from commit 15d3c14) Co-authored-by: Jack DeVries <[email protected]>
1 parent 36a2497 commit a5d9963

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

Lib/test/support/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,24 @@ def requires_lzma(reason='requires lzma'):
459459
TEST_DATA_DIR = os.path.join(TEST_HOME_DIR, "data")
460460

461461

462+
def darwin_malloc_err_warning(test_name):
463+
"""Assure user that loud errors generated by macOS libc's malloc are
464+
expected."""
465+
if sys.platform != 'darwin':
466+
return
467+
468+
import shutil
469+
msg = ' NOTICE '
470+
detail = (f'{test_name} may generate "malloc can\'t allocate region"\n'
471+
'warnings on macOS systems. This behavior is known. Do not\n'
472+
'report a bug unless tests are also failing. See bpo-40928.')
473+
474+
padding, _ = shutil.get_terminal_size()
475+
print(msg.center(padding, '-'))
476+
print(detail)
477+
print('-' * padding)
478+
479+
462480
def findfile(filename, subdir=None):
463481
"""Try to find a file on sys.path or in the test directory. If it is not
464482
found the argument passed to the function is returned (this does not

Lib/test/test_decimal.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,19 @@
3636
requires_IEEE_754, requires_docstrings,
3737
requires_legacy_unicode_capi)
3838
from test.support import (TestFailed,
39-
run_with_locale, cpython_only)
39+
run_with_locale, cpython_only,
40+
darwin_malloc_err_warning)
4041
from test.support.import_helper import import_fresh_module
4142
from test.support import warnings_helper
4243
import random
4344
import inspect
4445
import threading
4546

4647

48+
if sys.platform == 'darwin':
49+
darwin_malloc_err_warning('test_decimal')
50+
51+
4752
C = import_fresh_module('decimal', fresh=['_decimal'])
4853
P = import_fresh_module('decimal', blocked=['_decimal'])
4954
orig_sys_decimal = sys.modules['decimal']
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Notify users running test_decimal regression tests on macOS of potential
2+
harmless "malloc can't allocate region" messages spewed by test_decimal.

0 commit comments

Comments
 (0)