From 6085f485147dafbeeec18d22c06235b103b6a8ca Mon Sep 17 00:00:00 2001 From: Xavier de Gaye Date: Fri, 19 May 2017 17:13:06 +0200 Subject: [PATCH 1/3] bpo-29619: Do not rely on HAVE_LARGEFILE_SUPPORT for the size of types not off_t. --- Modules/posixmodule.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index e8c15a9473cfb1a..673e48230c590a2 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1927,14 +1927,12 @@ _pystat_fromstructstat(STRUCT_STAT *st) return NULL; PyStructSequence_SET_ITEM(v, 0, PyLong_FromLong((long)st->st_mode)); -#if defined(HAVE_LARGEFILE_SUPPORT) || defined(MS_WINDOWS) Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(st->st_ino)); - PyStructSequence_SET_ITEM(v, 1, + if (sizeof(unsigned long) >= sizeof(st->st_ino)) + PyStructSequence_SET_ITEM(v, 1, PyLong_FromUnsignedLong(st->st_ino)); + else + PyStructSequence_SET_ITEM(v, 1, PyLong_FromUnsignedLongLong(st->st_ino)); -#else - Py_BUILD_ASSERT(sizeof(unsigned long) >= sizeof(st->st_ino)); - PyStructSequence_SET_ITEM(v, 1, PyLong_FromUnsignedLong(st->st_ino)); -#endif #ifdef MS_WINDOWS PyStructSequence_SET_ITEM(v, 2, PyLong_FromUnsignedLong(st->st_dev)); #else @@ -1948,12 +1946,12 @@ _pystat_fromstructstat(STRUCT_STAT *st) PyStructSequence_SET_ITEM(v, 4, _PyLong_FromUid(st->st_uid)); PyStructSequence_SET_ITEM(v, 5, _PyLong_FromGid(st->st_gid)); #endif -#ifdef HAVE_LARGEFILE_SUPPORT - PyStructSequence_SET_ITEM(v, 6, + Py_BUILD_ASSERT(sizeof(long long) >= sizeof(st->st_size)); + if (sizeof(long) >= sizeof(st->st_size)) + PyStructSequence_SET_ITEM(v, 6, PyLong_FromLong(st->st_size)); + else + PyStructSequence_SET_ITEM(v, 6, PyLong_FromLongLong((long long)st->st_size)); -#else - PyStructSequence_SET_ITEM(v, 6, PyLong_FromLong(st->st_size)); -#endif #if defined(HAVE_STAT_TV_NSEC) ansec = st->st_atim.tv_nsec; @@ -11451,11 +11449,11 @@ os_DirEntry_inode_impl(DirEntry *self) Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(self->win32_file_index)); return PyLong_FromUnsignedLongLong(self->win32_file_index); #else /* POSIX */ -#ifdef HAVE_LARGEFILE_SUPPORT - return PyLong_FromLongLong((long long)self->d_ino); -#else - return PyLong_FromLong((long)self->d_ino); -#endif + Py_BUILD_ASSERT(sizeof(long long) >= sizeof(self->d_ino)); + if (sizeof(long) >= sizeof(self->d_ino)) + return PyLong_FromLong((long)self->d_ino); + else + return PyLong_FromLongLong((long long)self->d_ino); #endif } From 279542d5dd6d173346eb157b32ad23a248058770 Mon Sep 17 00:00:00 2001 From: Xavier de Gaye Date: Fri, 19 May 2017 20:43:11 +0200 Subject: [PATCH 2/3] bpo-29619: PEP 7 braces strongly preferred in conditionals --- Modules/posixmodule.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 673e48230c590a2..f6cf9ad078c430b 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1927,12 +1927,14 @@ _pystat_fromstructstat(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)); - if (sizeof(unsigned long) >= sizeof(st->st_ino)) + if (sizeof(unsigned long) >= sizeof(st->st_ino)) { PyStructSequence_SET_ITEM(v, 1, PyLong_FromUnsignedLong(st->st_ino)); - else + } + else { + Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(st->st_ino)); PyStructSequence_SET_ITEM(v, 1, PyLong_FromUnsignedLongLong(st->st_ino)); + } #ifdef MS_WINDOWS PyStructSequence_SET_ITEM(v, 2, PyLong_FromUnsignedLong(st->st_dev)); #else @@ -1946,12 +1948,14 @@ _pystat_fromstructstat(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)); - if (sizeof(long) >= sizeof(st->st_size)) + if (sizeof(long) >= sizeof(st->st_size)) { PyStructSequence_SET_ITEM(v, 6, PyLong_FromLong(st->st_size)); - else + } + else { + Py_BUILD_ASSERT(sizeof(long long) >= sizeof(st->st_size)); PyStructSequence_SET_ITEM(v, 6, PyLong_FromLongLong((long long)st->st_size)); + } #if defined(HAVE_STAT_TV_NSEC) ansec = st->st_atim.tv_nsec; @@ -11449,11 +11453,13 @@ os_DirEntry_inode_impl(DirEntry *self) Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(self->win32_file_index)); return PyLong_FromUnsignedLongLong(self->win32_file_index); #else /* POSIX */ - Py_BUILD_ASSERT(sizeof(long long) >= sizeof(self->d_ino)); - if (sizeof(long) >= sizeof(self->d_ino)) + if (sizeof(long) >= sizeof(self->d_ino)) { return PyLong_FromLong((long)self->d_ino); - else + } + else { + Py_BUILD_ASSERT(sizeof(long long) >= sizeof(self->d_ino)); return PyLong_FromLongLong((long long)self->d_ino); + } #endif } From 10c7987b1ec9713ac32f8794446867c85ad88e13 Mon Sep 17 00:00:00 2001 From: Xavier de Gaye Date: Sun, 21 May 2017 12:08:34 +0200 Subject: [PATCH 3/3] bpo-29619: Use the LongLong form for all the convertions. --- Modules/posixmodule.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index f6cf9ad078c430b..5c739180ea6f22f 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1927,14 +1927,8 @@ _pystat_fromstructstat(STRUCT_STAT *st) return NULL; PyStructSequence_SET_ITEM(v, 0, PyLong_FromLong((long)st->st_mode)); - if (sizeof(unsigned long) >= sizeof(st->st_ino)) { - PyStructSequence_SET_ITEM(v, 1, PyLong_FromUnsignedLong(st->st_ino)); - } - else { - Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(st->st_ino)); - PyStructSequence_SET_ITEM(v, 1, - PyLong_FromUnsignedLongLong(st->st_ino)); - } + Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(st->st_ino)); + PyStructSequence_SET_ITEM(v, 1, PyLong_FromUnsignedLongLong(st->st_ino)); #ifdef MS_WINDOWS PyStructSequence_SET_ITEM(v, 2, PyLong_FromUnsignedLong(st->st_dev)); #else @@ -1948,14 +1942,8 @@ _pystat_fromstructstat(STRUCT_STAT *st) PyStructSequence_SET_ITEM(v, 4, _PyLong_FromUid(st->st_uid)); PyStructSequence_SET_ITEM(v, 5, _PyLong_FromGid(st->st_gid)); #endif - if (sizeof(long) >= sizeof(st->st_size)) { - PyStructSequence_SET_ITEM(v, 6, PyLong_FromLong(st->st_size)); - } - else { - Py_BUILD_ASSERT(sizeof(long long) >= sizeof(st->st_size)); - PyStructSequence_SET_ITEM(v, 6, - PyLong_FromLongLong((long long)st->st_size)); - } + Py_BUILD_ASSERT(sizeof(long long) >= sizeof(st->st_size)); + PyStructSequence_SET_ITEM(v, 6, PyLong_FromLongLong(st->st_size)); #if defined(HAVE_STAT_TV_NSEC) ansec = st->st_atim.tv_nsec; @@ -11453,13 +11441,8 @@ os_DirEntry_inode_impl(DirEntry *self) Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(self->win32_file_index)); return PyLong_FromUnsignedLongLong(self->win32_file_index); #else /* POSIX */ - if (sizeof(long) >= sizeof(self->d_ino)) { - return PyLong_FromLong((long)self->d_ino); - } - else { - Py_BUILD_ASSERT(sizeof(long long) >= sizeof(self->d_ino)); - return PyLong_FromLongLong((long long)self->d_ino); - } + Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(self->d_ino)); + return PyLong_FromUnsignedLongLong(self->d_ino); #endif }