Skip to content

Commit 68d2980

Browse files
authored
bpo-29619: Convert st_ino using unsigned integer (#557) (#584)
bpo-29619: os.stat() and os.DirEntry.inodeo() now convert inode (st_ino) using unsigned integers. (cherry picked from commit 0f6d733) (Misc/NEWS conflict handled manually.)
1 parent 26d013e commit 68d2980

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

Include/fileutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ PyAPI_FUNC(PyObject *) _Py_device_encoding(int);
2222
#ifdef MS_WINDOWS
2323
struct _Py_stat_struct {
2424
unsigned long st_dev;
25-
__int64 st_ino;
25+
uint64_t st_ino;
2626
unsigned short st_mode;
2727
int st_nlink;
2828
int st_uid;

Modules/posixmodule.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,11 +1932,13 @@ _pystat_fromstructstat(STRUCT_STAT *st)
19321932
return NULL;
19331933

19341934
PyStructSequence_SET_ITEM(v, 0, PyLong_FromLong((long)st->st_mode));
1935-
#ifdef HAVE_LARGEFILE_SUPPORT
1935+
#if defined(HAVE_LARGEFILE_SUPPORT) || defined(MS_WINDOWS)
1936+
Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(st->st_ino));
19361937
PyStructSequence_SET_ITEM(v, 1,
1937-
PyLong_FromLongLong((long long)st->st_ino));
1938+
PyLong_FromUnsignedLongLong(st->st_ino));
19381939
#else
1939-
PyStructSequence_SET_ITEM(v, 1, PyLong_FromLong((long)st->st_ino));
1940+
Py_BUILD_ASSERT(sizeof(unsigned long) >= sizeof(st->st_ino));
1941+
PyStructSequence_SET_ITEM(v, 1, PyLong_FromUnsignedLong(st->st_ino));
19401942
#endif
19411943
#ifdef MS_WINDOWS
19421944
PyStructSequence_SET_ITEM(v, 2, PyLong_FromUnsignedLong(st->st_dev));
@@ -11156,7 +11158,7 @@ typedef struct {
1115611158
PyObject *lstat;
1115711159
#ifdef MS_WINDOWS
1115811160
struct _Py_stat_struct win32_lstat;
11159-
__int64 win32_file_index;
11161+
uint64_t win32_file_index;
1116011162
int got_file_index;
1116111163
#else /* POSIX */
1116211164
#ifdef HAVE_DIRENT_D_TYPE
@@ -11419,7 +11421,8 @@ DirEntry_inode(DirEntry *self)
1141911421
self->win32_file_index = stat.st_ino;
1142011422
self->got_file_index = 1;
1142111423
}
11422-
return PyLong_FromLongLong((long long)self->win32_file_index);
11424+
Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(self->win32_file_index));
11425+
return PyLong_FromUnsignedLongLong(self->win32_file_index);
1142311426
#else /* POSIX */
1142411427
#ifdef HAVE_LARGEFILE_SUPPORT
1142511428
return PyLong_FromLongLong((long long)self->d_ino);

Python/fileutils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ _Py_attribute_data_to_stat(BY_HANDLE_FILE_INFORMATION *info, ULONG reparse_tag,
583583
FILE_TIME_to_time_t_nsec(&info->ftLastWriteTime, &result->st_mtime, &result->st_mtime_nsec);
584584
FILE_TIME_to_time_t_nsec(&info->ftLastAccessTime, &result->st_atime, &result->st_atime_nsec);
585585
result->st_nlink = info->nNumberOfLinks;
586-
result->st_ino = (((__int64)info->nFileIndexHigh)<<32) + info->nFileIndexLow;
586+
result->st_ino = (((uint64_t)info->nFileIndexHigh) << 32) + info->nFileIndexLow;
587587
if (reparse_tag == IO_REPARSE_TAG_SYMLINK) {
588588
/* first clear the S_IFMT bits */
589589
result->st_mode ^= (result->st_mode & S_IFMT);
@@ -653,7 +653,7 @@ _Py_fstat_noraise(int fd, struct _Py_stat_struct *status)
653653

654654
_Py_attribute_data_to_stat(&info, 0, status);
655655
/* specific to fstat() */
656-
status->st_ino = (((__int64)info.nFileIndexHigh)<<32) + info.nFileIndexLow;
656+
status->st_ino = (((uint64_t)info.nFileIndexHigh) << 32) + info.nFileIndexLow;
657657
return 0;
658658
#else
659659
return fstat(fd, status);

0 commit comments

Comments
 (0)