gh-123747: Avoid static_assert() in internal header files (#123779)

This commit is contained in:
Victor Stinner 2024-09-06 15:52:07 +02:00 committed by GitHub
parent e95984826e
commit ef4b69d2be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 4 deletions

View File

@ -543,8 +543,9 @@ write_location_entry_start(uint8_t *ptr, int code, int length)
#define ADAPTIVE_COOLDOWN_BACKOFF 0 #define ADAPTIVE_COOLDOWN_BACKOFF 0
// Can't assert this in pycore_backoff.h because of header order dependencies // Can't assert this in pycore_backoff.h because of header order dependencies
static_assert(SIDE_EXIT_INITIAL_VALUE > ADAPTIVE_COOLDOWN_VALUE, #if SIDE_EXIT_INITIAL_VALUE <= ADAPTIVE_COOLDOWN_VALUE
"Cold exit value should be larger than adaptive cooldown value"); # error "Cold exit value should be larger than adaptive cooldown value"
#endif
static inline _Py_BackoffCounter static inline _Py_BackoffCounter
adaptive_counter_bits(uint16_t value, uint16_t backoff) { adaptive_counter_bits(uint16_t value, uint16_t backoff) {

View File

@ -178,8 +178,12 @@ PyAPI_FUNC(int) _PyLong_Size_t_Converter(PyObject *, void *);
* we define them to the numbers in both places and then assert that * we define them to the numbers in both places and then assert that
* they're the same. * they're the same.
*/ */
static_assert(SIGN_MASK == _PyLong_SIGN_MASK, "SIGN_MASK does not match _PyLong_SIGN_MASK"); #if SIGN_MASK != _PyLong_SIGN_MASK
static_assert(NON_SIZE_BITS == _PyLong_NON_SIZE_BITS, "NON_SIZE_BITS does not match _PyLong_NON_SIZE_BITS"); # error "SIGN_MASK does not match _PyLong_SIGN_MASK"
#endif
#if NON_SIZE_BITS != _PyLong_NON_SIZE_BITS
# error "NON_SIZE_BITS does not match _PyLong_NON_SIZE_BITS"
#endif
/* All *compact" values are guaranteed to fit into /* All *compact" values are guaranteed to fit into
* a Py_ssize_t with at least one bit to spare. * a Py_ssize_t with at least one bit to spare.