diff options
author | Victor Stinner <vstinner@python.org> | 2022-04-20 17:26:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-20 17:26:40 (GMT) |
commit | 7cdaf87ec50f76c934ba651256484c4624b84ef2 (patch) | |
tree | 64ce3dcd176b6c0397f901f28e5406e3eca12588 /Objects | |
parent | ad3ca17ff5cd63f907430073b52be27695674148 (diff) | |
download | cpython-7cdaf87ec50f76c934ba651256484c4624b84ef2.zip cpython-7cdaf87ec50f76c934ba651256484c4624b84ef2.tar.gz cpython-7cdaf87ec50f76c934ba651256484c4624b84ef2.tar.bz2 |
gh-91731: Replace Py_BUILD_ASSERT() with static_assert() (#91730)
Python 3.11 now uses C11 standard which adds static_assert()
to <assert.h>.
* In pytime.c, replace Py_BUILD_ASSERT() with preprocessor checks on
SIZEOF_TIME_T with #error.
* On macOS, py_mach_timebase_info() now accepts timebase members with
the same size than _PyTime_t.
* py_get_monotonic_clock() now saturates GetTickCount64() to
_PyTime_MAX: GetTickCount64() is unsigned, whereas _PyTime_t is
signed.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/longobject.c | 7 | ||||
-rw-r--r-- | Objects/sliceobject.c | 3 |
2 files changed, 7 insertions, 3 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c index 660824f..e805dac 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -771,7 +771,10 @@ _PyLong_Sign(PyObject *vv) static int bit_length_digit(digit x) { - Py_BUILD_ASSERT(PyLong_SHIFT <= sizeof(unsigned long) * 8); + // digit can be larger than unsigned long, but only PyLong_SHIFT bits + // of it will be ever used. + static_assert(PyLong_SHIFT <= sizeof(unsigned long) * 8, + "digit is larger than unsigned long"); return _Py_bit_length((unsigned long)x); } @@ -5647,7 +5650,7 @@ popcount_digit(digit d) { // digit can be larger than uint32_t, but only PyLong_SHIFT bits // of it will be ever used. - Py_BUILD_ASSERT(PyLong_SHIFT <= 32); + static_assert(PyLong_SHIFT <= 32, "digit is larger than uint32_t"); return _Py_popcount32((uint32_t)d); } diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c index 22fb7c6..713829d 100644 --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -206,7 +206,8 @@ PySlice_Unpack(PyObject *_r, PySliceObject *r = (PySliceObject*)_r; /* this is harder to get right than you might think */ - Py_BUILD_ASSERT(PY_SSIZE_T_MIN + 1 <= -PY_SSIZE_T_MAX); + static_assert(PY_SSIZE_T_MIN + 1 <= -PY_SSIZE_T_MAX, + "-PY_SSIZE_T_MAX < PY_SSIZE_T_MIN + 1"); if (r->step == Py_None) { *step = 1; |