Skip to content

Commit c1f05e9

Browse files
committed
pythongh-123747: Avoid static_assert() in internal header files
1 parent 782a076 commit c1f05e9

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Include/internal/pycore_code.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,9 @@ write_location_entry_start(uint8_t *ptr, int code, int length)
543543
#define ADAPTIVE_COOLDOWN_BACKOFF 0
544544

545545
// Can't assert this in pycore_backoff.h because of header order dependencies
546-
static_assert(SIDE_EXIT_INITIAL_VALUE > ADAPTIVE_COOLDOWN_VALUE,
547-
"Cold exit value should be larger than adaptive cooldown value");
546+
#if SIDE_EXIT_INITIAL_VALUE <= ADAPTIVE_COOLDOWN_VALUE
547+
# error "Cold exit value should be larger than adaptive cooldown value"
548+
#endif
548549

549550
static inline _Py_BackoffCounter
550551
adaptive_counter_bits(uint16_t value, uint16_t backoff) {

Include/internal/pycore_long.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,12 @@ PyAPI_FUNC(int) _PyLong_Size_t_Converter(PyObject *, void *);
178178
* we define them to the numbers in both places and then assert that
179179
* they're the same.
180180
*/
181-
static_assert(SIGN_MASK == _PyLong_SIGN_MASK, "SIGN_MASK does not match _PyLong_SIGN_MASK");
182-
static_assert(NON_SIZE_BITS == _PyLong_NON_SIZE_BITS, "NON_SIZE_BITS does not match _PyLong_NON_SIZE_BITS");
181+
#if SIGN_MASK != _PyLong_SIGN_MASK
182+
# error "SIGN_MASK does not match _PyLong_SIGN_MASK"
183+
#endif
184+
#if NON_SIZE_BITS != _PyLong_NON_SIZE_BITS
185+
# error "NON_SIZE_BITS does not match _PyLong_NON_SIZE_BITS"
186+
#endif
183187

184188
/* All *compact" values are guaranteed to fit into
185189
* a Py_ssize_t with at least one bit to spare.

0 commit comments

Comments
 (0)