diff options
author | Victor Stinner <vstinner@python.org> | 2020-11-13 14:38:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-13 14:38:17 (GMT) |
commit | b3b98082c5431e77c64cab2c85525a804436b505 (patch) | |
tree | 5ef06418d69d6515b65e049e96e92ea5aadee0ea /Include/internal | |
parent | d96a7a83133250377219227b5cfab4dbdddc5d3a (diff) | |
download | cpython-b3b98082c5431e77c64cab2c85525a804436b505.zip cpython-b3b98082c5431e77c64cab2c85525a804436b505.tar.gz cpython-b3b98082c5431e77c64cab2c85525a804436b505.tar.bz2 |
bpo-41617: Add _Py__has_builtin() macro (GH-23260)
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).
Add a new private _Py__has_builtin() macro to check for availability
of a preprocessor builtin function.
Co-Authored-By: Joshua Root <jmr@macports.org>
Co-authored-by: Joshua Root <jmr@macports.org>
Diffstat (limited to 'Include/internal')
-rw-r--r-- | Include/internal/pycore_bitutils.h | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/Include/internal/pycore_bitutils.h b/Include/internal/pycore_bitutils.h index 1602fc6..e4aa7a3 100644 --- a/Include/internal/pycore_bitutils.h +++ b/Include/internal/pycore_bitutils.h @@ -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 @@ -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)); @@ -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)); @@ -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); |