Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Include/pymacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_cext/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion Lib/test/test_cext/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_cext/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading