2828import random
2929import signal
3030import sys
31+ import sysconfig
3132import textwrap
3233import threading
3334import time
4344from test .support import os_helper
4445from test .support import threading_helper
4546from test .support import warnings_helper
46- from test .support import skip_if_sanitizer
4747from test .support .os_helper import FakePath
4848
4949import codecs
@@ -66,6 +66,17 @@ def byteslike(*pos, **kw):
6666 class EmptyStruct (ctypes .Structure ):
6767 pass
6868
69+ _cflags = sysconfig .get_config_var ('CFLAGS' ) or ''
70+ _config_args = sysconfig .get_config_var ('CONFIG_ARGS' ) or ''
71+ MEMORY_SANITIZER = (
72+ '-fsanitize=memory' in _cflags or
73+ '--with-memory-sanitizer' in _config_args
74+ )
75+
76+ ADDRESS_SANITIZER = (
77+ '-fsanitize=address' in _cflags
78+ )
79+
6980# Does io.IOBase finalizer log the exception if the close() method fails?
7081# The exception is ignored silently by default in release build.
7182IOBASE_EMITS_UNRAISABLE = (hasattr (sys , "gettotalrefcount" ) or sys .flags .dev_mode )
@@ -1549,7 +1560,7 @@ class CBufferedReaderTest(BufferedReaderTest, SizeofTest):
15491560 tp = io .BufferedReader
15501561
15511562 @unittest .skip ("TODO: RUSTPYTHON, fallible allocation" )
1552- @skip_if_sanitizer ( memory = True , address = True , reason = "sanitizer defaults to crashing "
1563+ @unittest . skipIf ( MEMORY_SANITIZER or ADDRESS_SANITIZER , "sanitizer defaults to crashing "
15531564 "instead of returning NULL for malloc failure." )
15541565 def test_constructor (self ):
15551566 BufferedReaderTest .test_constructor (self )
@@ -1931,7 +1942,7 @@ class CBufferedWriterTest(BufferedWriterTest, SizeofTest):
19311942 tp = io .BufferedWriter
19321943
19331944 @unittest .skip ("TODO: RUSTPYTHON, fallible allocation" )
1934- @skip_if_sanitizer ( memory = True , address = True , reason = "sanitizer defaults to crashing "
1945+ @unittest . skipIf ( MEMORY_SANITIZER or ADDRESS_SANITIZER , "sanitizer defaults to crashing "
19351946 "instead of returning NULL for malloc failure." )
19361947 def test_constructor (self ):
19371948 BufferedWriterTest .test_constructor (self )
@@ -2438,7 +2449,7 @@ class CBufferedRandomTest(BufferedRandomTest, SizeofTest):
24382449 tp = io .BufferedRandom
24392450
24402451 @unittest .skip ("TODO: RUSTPYTHON, fallible allocation" )
2441- @skip_if_sanitizer ( memory = True , address = True , reason = "sanitizer defaults to crashing "
2452+ @unittest . skipIf ( MEMORY_SANITIZER or ADDRESS_SANITIZER , "sanitizer defaults to crashing "
24422453 "instead of returning NULL for malloc failure." )
24432454 def test_constructor (self ):
24442455 BufferedRandomTest .test_constructor (self )
0 commit comments