summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-04-20 17:26:40 (GMT)
committerGitHub <noreply@github.com>2022-04-20 17:26:40 (GMT)
commit7cdaf87ec50f76c934ba651256484c4624b84ef2 (patch)
tree64ce3dcd176b6c0397f901f28e5406e3eca12588 /Modules
parentad3ca17ff5cd63f907430073b52be27695674148 (diff)
downloadcpython-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 'Modules')
-rw-r--r--Modules/_datetimemodule.c6
-rw-r--r--Modules/_pickle.c2
-rw-r--r--Modules/_testcapimodule.c3
-rw-r--r--Modules/posixmodule.c12
-rw-r--r--Modules/pyexpat.c4
5 files changed, 17 insertions, 10 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index fc766c3..a35c723 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -6637,19 +6637,19 @@ _datetime_exec(PyObject *module)
/* A 4-year cycle has an extra leap day over what we'd get from
* pasting together 4 single years.
*/
- Py_BUILD_ASSERT(DI4Y == 4 * 365 + 1);
+ static_assert(DI4Y == 4 * 365 + 1, "DI4Y");
assert(DI4Y == days_before_year(4+1));
/* Similarly, a 400-year cycle has an extra leap day over what we'd
* get from pasting together 4 100-year cycles.
*/
- Py_BUILD_ASSERT(DI400Y == 4 * DI100Y + 1);
+ static_assert(DI400Y == 4 * DI100Y + 1, "DI400Y");
assert(DI400Y == days_before_year(400+1));
/* OTOH, a 100-year cycle has one fewer leap day than we'd get from
* pasting together 25 4-year cycles.
*/
- Py_BUILD_ASSERT(DI100Y == 25 * DI4Y - 1);
+ static_assert(DI100Y == 25 * DI4Y - 1, "DI100Y");
assert(DI100Y == days_before_year(100+1));
us_per_ms = PyLong_FromLong(1000);
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index a5595eb..7a8c9ed 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -964,7 +964,7 @@ _write_size64(char *out, size_t value)
{
size_t i;
- Py_BUILD_ASSERT(sizeof(size_t) <= 8);
+ static_assert(sizeof(size_t) <= 8, "size_t is larger than 64-bit");
for (i = 0; i < sizeof(size_t); i++) {
out[i] = (unsigned char)((value >> (8 * i)) & 0xff);
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 23af0d3..6bd73e8 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -5157,7 +5157,8 @@ dict_get_version(PyObject *self, PyObject *args)
version = dict->ma_version_tag;
- Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(version));
+ static_assert(sizeof(unsigned long long) >= sizeof(version),
+ "version is larger than unsigned long long");
return PyLong_FromUnsignedLongLong((unsigned long long)version);
}
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 700cbd2..345ed71 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -2381,7 +2381,8 @@ _pystat_fromstructstat(PyObject *module, STRUCT_STAT *st)
return NULL;
PyStructSequence_SET_ITEM(v, 0, PyLong_FromLong((long)st->st_mode));
- Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(st->st_ino));
+ static_assert(sizeof(unsigned long long) >= sizeof(st->st_ino),
+ "stat.st_ino is larger than unsigned long long");
PyStructSequence_SET_ITEM(v, 1, PyLong_FromUnsignedLongLong(st->st_ino));
#ifdef MS_WINDOWS
PyStructSequence_SET_ITEM(v, 2, PyLong_FromUnsignedLong(st->st_dev));
@@ -2396,7 +2397,8 @@ _pystat_fromstructstat(PyObject *module, STRUCT_STAT *st)
PyStructSequence_SET_ITEM(v, 4, _PyLong_FromUid(st->st_uid));
PyStructSequence_SET_ITEM(v, 5, _PyLong_FromGid(st->st_gid));
#endif
- Py_BUILD_ASSERT(sizeof(long long) >= sizeof(st->st_size));
+ static_assert(sizeof(long long) >= sizeof(st->st_size),
+ "stat.st_size is larger than long long");
PyStructSequence_SET_ITEM(v, 6, PyLong_FromLongLong(st->st_size));
#if defined(HAVE_STAT_TV_NSEC)
@@ -13761,10 +13763,12 @@ _Py_COMP_DIAG_POP
self->win32_file_index = stat.st_ino;
self->got_file_index = 1;
}
- Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(self->win32_file_index));
+ static_assert(sizeof(unsigned long long) >= sizeof(self->win32_file_index),
+ "DirEntry.win32_file_index is larger than unsigned long long");
return PyLong_FromUnsignedLongLong(self->win32_file_index);
#else /* POSIX */
- Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(self->d_ino));
+ static_assert(sizeof(unsigned long long) >= sizeof(self->d_ino),
+ "DirEntry.d_ino is larger than unsigned long long");
return PyLong_FromUnsignedLongLong(self->d_ino);
#endif
}
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index 7a26fe2..ad8148a 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -745,6 +745,8 @@ pyexpat_xmlparser_Parse_impl(xmlparseobject *self, PyTypeObject *cls,
slen = view.len;
}
+ static_assert(MAX_CHUNK_SIZE <= INT_MAX,
+ "MAX_CHUNK_SIZE is larger than INT_MAX");
while (slen > MAX_CHUNK_SIZE) {
rc = XML_Parse(self->itself, s, MAX_CHUNK_SIZE, 0);
if (!rc)
@@ -752,7 +754,7 @@ pyexpat_xmlparser_Parse_impl(xmlparseobject *self, PyTypeObject *cls,
s += MAX_CHUNK_SIZE;
slen -= MAX_CHUNK_SIZE;
}
- Py_BUILD_ASSERT(MAX_CHUNK_SIZE <= INT_MAX);
+
assert(slen <= INT_MAX);
rc = XML_Parse(self->itself, s, (int)slen, isfinal);