2828import random
2929import signal
3030import sys
31- import sysconfig
3231import textwrap
3332import threading
3433import time
4039from test import support
4140from test .support .script_helper import (
4241 assert_python_ok , assert_python_failure , run_python_until_end )
43- from test .support import FakePath
42+ from test .support import FakePath , skip_if_sanitizer
4443
4544import codecs
4645import io # C implementation of io
@@ -62,17 +61,6 @@ def byteslike(*pos, **kw):
6261 class EmptyStruct (ctypes .Structure ):
6362 pass
6463
65- _cflags = sysconfig .get_config_var ('CFLAGS' ) or ''
66- _config_args = sysconfig .get_config_var ('CONFIG_ARGS' ) or ''
67- MEMORY_SANITIZER = (
68- '-fsanitize=memory' in _cflags or
69- '--with-memory-sanitizer' in _config_args
70- )
71-
72- ADDRESS_SANITIZER = (
73- '-fsanitize=address' in _cflags
74- )
75-
7664# Does io.IOBase finalizer log the exception if the close() method fails?
7765# The exception is ignored silently by default in release build.
7866IOBASE_EMITS_UNRAISABLE = (hasattr (sys , "gettotalrefcount" ) or sys .flags .dev_mode )
@@ -1543,8 +1531,8 @@ def test_truncate_on_read_only(self):
15431531class CBufferedReaderTest (BufferedReaderTest , SizeofTest ):
15441532 tp = io .BufferedReader
15451533
1546- @unittest . skipIf ( MEMORY_SANITIZER or ADDRESS_SANITIZER , "sanitizer defaults to crashing "
1547- "instead of returning NULL for malloc failure." )
1534+ @skip_if_sanitizer ( memory = True , address = True , reason = "sanitizer defaults to crashing "
1535+ "instead of returning NULL for malloc failure." )
15481536 def test_constructor (self ):
15491537 BufferedReaderTest .test_constructor (self )
15501538 # The allocation can succeed on 32-bit builds, e.g. with more
@@ -1892,8 +1880,8 @@ def test_slow_close_from_thread(self):
18921880class CBufferedWriterTest (BufferedWriterTest , SizeofTest ):
18931881 tp = io .BufferedWriter
18941882
1895- @unittest . skipIf ( MEMORY_SANITIZER or ADDRESS_SANITIZER , "sanitizer defaults to crashing "
1896- "instead of returning NULL for malloc failure." )
1883+ @skip_if_sanitizer ( memory = True , address = True , reason = "sanitizer defaults to crashing "
1884+ "instead of returning NULL for malloc failure." )
18971885 def test_constructor (self ):
18981886 BufferedWriterTest .test_constructor (self )
18991887 # The allocation can succeed on 32-bit builds, e.g. with more
@@ -2391,8 +2379,8 @@ def test_interleaved_readline_write(self):
23912379class CBufferedRandomTest (BufferedRandomTest , SizeofTest ):
23922380 tp = io .BufferedRandom
23932381
2394- @unittest . skipIf ( MEMORY_SANITIZER or ADDRESS_SANITIZER , "sanitizer defaults to crashing "
2395- "instead of returning NULL for malloc failure." )
2382+ @skip_if_sanitizer ( memory = True , address = True , reason = "sanitizer defaults to crashing "
2383+ "instead of returning NULL for malloc failure." )
23962384 def test_constructor (self ):
23972385 BufferedRandomTest .test_constructor (self )
23982386 # The allocation can succeed on 32-bit builds, e.g. with more
0 commit comments