FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-158810: Use _Py_TYPEOF in Py_ARRAY_LENGTH() by vstinner · Pull Request #158838 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .h  (1) .py  (2) All 3 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 3 additions & 3 deletions Include/pymacro.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL