Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-41617: Add _Py__has_builtin() macro #23260

Merged
merged 1 commit into from
Nov 13, 2020
Merged
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
15 changes: 6 additions & 9 deletions Include/internal/pycore_bitutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

#if ((defined(__GNUC__) \
&& ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))) \
|| (defined(__clang__) \
&& (__clang_major__ >= 4 \
|| (__clang_major__ == 3 && __clang_minor__ >= 2))))
/* __builtin_bswap16() is available since GCC 4.8 and clang 3.2,
#if defined(__GNUC__) \
&& ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))
/* __builtin_bswap16() is available since GCC 4.8,
__builtin_bswap32() is available since GCC 4.3,
__builtin_bswap64() is available since GCC 4.3. */
# define _PY_HAVE_BUILTIN_BSWAP
Expand All @@ -36,7 +33,7 @@ extern "C" {
static inline uint16_t
_Py_bswap16(uint16_t word)
{
#ifdef _PY_HAVE_BUILTIN_BSWAP
#if defined(_PY_HAVE_BUILTIN_BSWAP) || _Py__has_builtin(__builtin_bswap16)
return __builtin_bswap16(word);
#elif defined(_MSC_VER)
Py_BUILD_ASSERT(sizeof(word) == sizeof(unsigned short));
Expand All @@ -51,7 +48,7 @@ _Py_bswap16(uint16_t word)
static inline uint32_t
_Py_bswap32(uint32_t word)
{
#ifdef _PY_HAVE_BUILTIN_BSWAP
#if defined(_PY_HAVE_BUILTIN_BSWAP) || _Py__has_builtin(__builtin_bswap32)
return __builtin_bswap32(word);
#elif defined(_MSC_VER)
Py_BUILD_ASSERT(sizeof(word) == sizeof(unsigned long));
Expand All @@ -68,7 +65,7 @@ _Py_bswap32(uint32_t word)
static inline uint64_t
_Py_bswap64(uint64_t word)
{
#ifdef _PY_HAVE_BUILTIN_BSWAP
#if defined(_PY_HAVE_BUILTIN_BSWAP) || _Py__has_builtin(__builtin_bswap64)
return __builtin_bswap64(word);
#elif defined(_MSC_VER)
return _byteswap_uint64(word);
Expand Down
12 changes: 12 additions & 0 deletions Include/pyport.h
Original file line number Diff line number Diff line change
Expand Up @@ -869,4 +869,16 @@ extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
# define _Py_NO_RETURN
#endif


// Preprocessor check for a builtin preprocessor function. Always return 0
// if __has_builtin() macro is not defined.
//
// __has_builtin() is available on clang and GCC 10.
#ifdef __has_builtin
# define _Py__has_builtin(x) __has_builtin(x)
#else
# define _Py__has_builtin(x) 0
#endif


#endif /* Py_PYPORT_H */
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix building ``pycore_bitutils.h`` internal header on old clang version
without ``__builtin_bswap16()`` (ex: Xcode 4.6.3 on Mac OS X 10.7). Patch by
Joshua Root and Victor Stinner.