https://github.com/python/cpython/commit/85c03d47a240247d41799c2075f85f690558534c
commit: 85c03d47a240247d41799c2075f85f690558534c
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-10-06T00:06:09Z
summary:
gh-158810: Use _Py_TYPEOF in Py_ARRAY_LENGTH() (#158838)
Fix the compiler warning "extension used" when building test_cext
with clang.
* test_cext no longer overrides the CC environment variable if it's
already defined.
* test_cext now also logs __STRICT_ANSI__ macro.
files:
M Include/pymacro.h
M Lib/test/test_cext/extension.c
M Lib/test/test_cext/runtests.py
M Lib/test/test_cext/setup.py
diff --git a/Include/pymacro.h b/Include/pymacro.h
index 979e6563742b98..122d26315b51b9 100644
--- a/Include/pymacro.h
+++ b/Include/pymacro.h
@@ -214,12 +214,12 @@
//
// gh-158810: Do not use __builtin_types_compatible_p() in strict C ANSI mode
// and on C++.
-#if (defined(__GNUC__) && __GNUC__ >= 4 \
+#if (defined(__GNUC__) && __GNUC__ >= 4 && defined(_Py_TYPEOF) \
&& !defined(__STRICT_ANSI__) && !defined(__cplusplus))
#define Py_ARRAY_LENGTH(array) \
(sizeof(array) / sizeof((array)[0]) \
- + Py_BUILD_ASSERT_EXPR(!__builtin_types_compatible_p(typeof(array), \
-
typeof(&(array)[0]))))
+ + Py_BUILD_ASSERT_EXPR(!__builtin_types_compatible_p(_Py_TYPEOF(array), \
+
_Py_TYPEOF(&(array)[0]))))
#else
#define Py_ARRAY_LENGTH(array) \
(sizeof(array) / sizeof((array)[0]))
diff --git a/Lib/test/test_cext/extension.c b/Lib/test/test_cext/extension.c
index e392b66f19cc4a..f1528b4df7776f 100644
--- a/Lib/test/test_cext/extension.c
+++ b/Lib/test/test_cext/extension.c
@@ -388,6 +388,11 @@ module_exec(PyObject *module)
return -1;
}
#endif
+#ifdef __STRICT_ANSI__
+ if (PyModule_AddIntConstant(module, "__STRICT_ANSI__", 1) < 0) {
+ return -1;
+ }
+#endif
#ifdef __cplusplus
if (PyModule_AddIntMacro(module, __cplusplus) < 0) {
return -1;
diff --git a/Lib/test/test_cext/runtests.py b/Lib/test/test_cext/runtests.py
index 86aab671200493..e8288ee5e11e44 100644
--- a/Lib/test/test_cext/runtests.py
+++ b/Lib/test/test_cext/runtests.py
@@ -28,7 +28,12 @@ def main():
testmod = importlib.import_module(module_name)
newline = False
- for name in ('__STDC_VERSION__', '__cplusplus', '_MSVC_LANG'):
+ for name in (
+ '__STDC_VERSION__',
+ '__STRICT_ANSI__',
+ '__cplusplus',
+ '_MSVC_LANG',
+ ):
try:
value = getattr(testmod, name)
except AttributeError:
diff --git a/Lib/test/test_cext/setup.py b/Lib/test/test_cext/setup.py
index 58bee3e255a4b3..c5706d23748e53 100644
--- a/Lib/test/test_cext/setup.py
+++ b/Lib/test/test_cext/setup.py
@@ -135,7 +135,7 @@ def main():
# option emits a C++ compiler warning. Remove "-std11" option from the
# CC command.
cmd = (sysconfig.get_config_var('CC') or '')
- if cmd is not None:
+ if cmd is not None and 'CC' not in os.environ:
if support.MS_WINDOWS:
std_prefix = '/std'
else:
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]