Skip to content

Commit d6583b7

Browse files
vstinnerngoldbaum
andcommitted
Test the memcpy() implementation in test_cext
Add the _Py_TESTCEXT_NO_TYPEOF macro to undefine the _Py_TYPEOF macro. Co-Authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
1 parent a02b2c3 commit d6583b7

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎Include/pyport.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,11 @@ extern "C" {
550550
# define _Py_TYPEOF(expr) __typeof__(expr)
551551
#endif
552552

553+
#ifdef _Py_TESTCEXT_NO_TYPEOF
554+
// Exercise fallback implementations in test_cext.
555+
# undef _Py_TYPEOF
556+
#endif
557+
553558

554559
/* A convenient way for code to know if sanitizers are enabled. */
555560
#if defined(__has_feature)

‎Lib/test/test_cext/__init__.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ class TestPublicC(BaseTests, unittest.TestCase):
113113
def test_build(self):
114114
self.check_build('_test_cext')
115115

116+
def test_build_no_typeof(self):
117+
# gh-161185: Exercise the Py_CLEAR/Py_SETREF() memcpy implementation
118+
# with strict aliasing enabled: undefine the _Py_TYPEOF macro.
119+
self.check_build(
120+
'_test_cext_no_typeof',
121+
extra_cflags='-D_Py_TESTCEXT_NO_TYPEOF -O2 -fstrict-aliasing')
122+
116123
@unittest.skipIf(MSVC, "MSVC doesn't support /std:c99")
117124
def test_build_c99(self):
118125
# In public docs, we say C API is compatible with C11. However,
@@ -146,6 +153,15 @@ def test_build_cpp03(self):
146153
# Please ask the C API WG before adding a new C++11-only feature.
147154
self.check_build('_test_cppext_cpp03', std='c++03')
148155

156+
@unittest.skipIf(MSVC, "MSVC doesn't support /std:c++03")
157+
def test_build_cpp03_no_typeof(self):
158+
# gh-161185: Exercise the Py_CLEAR/Py_SETREF() memcpy implementation
159+
# with strict aliasing enabled: undefine the _Py_TYPEOF macro.
160+
self.check_build(
161+
'_test_cppext_cpp03_no_typeof',
162+
std='c++03',
163+
extra_cflags='-D_Py_TESTCEXT_NO_TYPEOF -O2 -fstrict-aliasing')
164+
149165
@unittest.skipIf(MSVC, "MSVC doesn't support /std:c++11")
150166
def test_build_cpp11(self):
151167
self.check_build('_test_cppext_cpp11', std='c++11')

0 commit comments

Comments
 (0)