]> granicus.if.org Git - python/commitdiff
bpo-29619: Convert st_ino using unsigned integer (#557)
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 9 Mar 2017 16:34:28 +0000 (17:34 +0100)
committerGitHub <noreply@github.com>
Thu, 9 Mar 2017 16:34:28 +0000 (17:34 +0100)
bpo-29619: os.stat() and os.DirEntry.inodeo() now convert inode
(st_ino) using unsigned integers.

Include/fileutils.h
Misc/NEWS
Modules/posixmodule.c
Python/fileutils.c

index b933e985392e73b4785873d3c69de174482e04cc..900c70faad719f2d5a619d53122f18f5bf4d8592 100644 (file)
@@ -22,7 +22,7 @@ PyAPI_FUNC(PyObject *) _Py_device_encoding(int);
 #ifdef MS_WINDOWS
 struct _Py_stat_struct {
     unsigned long st_dev;
-    __int64 st_ino;
+    uint64_t st_ino;
     unsigned short st_mode;
     int st_nlink;
     int st_uid;
index 03ac99b14b70275f62d2287974287ab97897da47..c4bdbefaa7bd33a50d30bd68b9bc395dd1556dfe 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -270,6 +270,9 @@ Extension Modules
 Library
 -------
 
+- bpo-29619: os.stat() and os.DirEntry.inode() now convert inode (st_ino) using
+  unsigned integers.
+
 - bpo-28298: Fix a bug that prevented array 'Q', 'L' and 'I' from accepting big
   intables (objects that have __int__) as elements.
 
@@ -289,7 +292,7 @@ Library
 
 - bpo-9303: Migrate sqlite3 module to _v2 API.  Patch by Aviv Palivoda.
 
-- bpo-28963: Fix out of bound iteration in asyncio.Future.remove_done_callback 
+- bpo-28963: Fix out of bound iteration in asyncio.Future.remove_done_callback
   implemented in C.
 
 - bpo-29704: asyncio.subprocess.SubprocessStreamProtocol no longer closes before
index ae03d06fe10d072c76a1d43bd0a0a647a01d02cc..0ae06eb53eaef9d86dab7bc33413c29b78f40591 100644 (file)
@@ -1927,11 +1927,13 @@ _pystat_fromstructstat(STRUCT_STAT *st)
         return NULL;
 
     PyStructSequence_SET_ITEM(v, 0, PyLong_FromLong((long)st->st_mode));
-#ifdef HAVE_LARGEFILE_SUPPORT
+#if defined(HAVE_LARGEFILE_SUPPORT) || defined(MS_WINDOWS)
+    Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(st->st_ino));
     PyStructSequence_SET_ITEM(v, 1,
-                              PyLong_FromLongLong((long long)st->st_ino));
+                              PyLong_FromUnsignedLongLong(st->st_ino));
 #else
-    PyStructSequence_SET_ITEM(v, 1, PyLong_FromLong((long)st->st_ino));
+    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));
@@ -11152,7 +11154,7 @@ typedef struct {
     PyObject *lstat;
 #ifdef MS_WINDOWS
     struct _Py_stat_struct win32_lstat;
-    __int64 win32_file_index;
+    uint64_t win32_file_index;
     int got_file_index;
 #else /* POSIX */
 #ifdef HAVE_DIRENT_D_TYPE
@@ -11409,7 +11411,8 @@ os_DirEntry_inode_impl(DirEntry *self)
         self->win32_file_index = stat.st_ino;
         self->got_file_index = 1;
     }
-    return PyLong_FromLongLong((long long)self->win32_file_index);
+    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);
index e84d66e99a473d5803e19a20bf3a64ae9c318aa5..f3764e4b3c5a2d09b8d277c30d4ef75d7670a605 100644 (file)
@@ -583,7 +583,7 @@ _Py_attribute_data_to_stat(BY_HANDLE_FILE_INFORMATION *info, ULONG reparse_tag,
     FILE_TIME_to_time_t_nsec(&info->ftLastWriteTime, &result->st_mtime, &result->st_mtime_nsec);
     FILE_TIME_to_time_t_nsec(&info->ftLastAccessTime, &result->st_atime, &result->st_atime_nsec);
     result->st_nlink = info->nNumberOfLinks;
-    result->st_ino = (((__int64)info->nFileIndexHigh)<<32) + info->nFileIndexLow;
+    result->st_ino = (((uint64_t)info->nFileIndexHigh) << 32) + info->nFileIndexLow;
     if (reparse_tag == IO_REPARSE_TAG_SYMLINK) {
         /* first clear the S_IFMT bits */
         result->st_mode ^= (result->st_mode & S_IFMT);
@@ -653,7 +653,7 @@ _Py_fstat_noraise(int fd, struct _Py_stat_struct *status)
 
     _Py_attribute_data_to_stat(&info, 0, status);
     /* specific to fstat() */
-    status->st_ino = (((__int64)info.nFileIndexHigh)<<32) + info.nFileIndexLow;
+    status->st_ino = (((uint64_t)info.nFileIndexHigh) << 32) + info.nFileIndexLow;
     return 0;
 #else
     return fstat(fd, status);