Author xdegaye
Recipients eryksun, haypo, mba, serhiy.storchaka, steve.dower, xdegaye, xiang.zhang
Date 2017-05-18.11:39:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1495107591.86.0.177420444358.issue29619@psf.upfronthosting.co.za>
In-reply-to
Content
With the patch proposed by Victor in msg293873 the cross-compilation of posixmodule.c succeeds on android-21-x86 and android-21-x86_64.

Following my suggestion in msg292174, I propose the following patch instead:

diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index e8c15a9473..d7ff3c78bd 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

This patch removes the conditional on HAVE_LARGEFILE_SUPPORT (explicit is better than implicit) and fixes the problem for any operating system where the size of off_t and the size of st_ino are different.
The compiler removes the dead branch of the <if (sizeof(unsigned long)...> conditional, so actually it compiles to the same binary as the other patch (gcc does this without any optimization configured on the command line, I didn't check this for clang).

The same kind of fix could also be applied elsewhere in posixmodule.c where behind the use of HAVE_LARGEFILE_SUPPORT there is an incorrect assumption that the size of off_t is the same as the size of another type:
  * In _pystat_fromstructstat() - a little bit further down this patch - where the other type is st_size.
  * In os_DirEntry_inode_impl() where the other type is ino_t.
Maybe this should be done in a new issue then ?
History
Date User Action Args
2017-05-18 11:39:51xdegayesetrecipients: + xdegaye, haypo, serhiy.storchaka, eryksun, steve.dower, xiang.zhang, mba
2017-05-18 11:39:51xdegayesetmessageid: <1495107591.86.0.177420444358.issue29619@psf.upfronthosting.co.za>
2017-05-18 11:39:51xdegayelinkissue29619 messages
2017-05-18 11:39:51xdegayecreate