Author: Armin Rigo <[email protected]>
Branch:
Changeset: r68134:203930ef1f4f
Date: 2013-11-15 09:41 +0100
http://bitbucket.org/pypy/pypy/changeset/203930ef1f4f/
Log: Windows: attempt to fix stat() for long ints.
diff --git a/rpython/rtyper/module/ll_os_stat.py
b/rpython/rtyper/module/ll_os_stat.py
--- a/rpython/rtyper/module/ll_os_stat.py
+++ b/rpython/rtyper/module/ll_os_stat.py
@@ -466,16 +466,14 @@
def attribute_data_to_stat(info):
st_mode = attributes_to_mode(info.c_dwFileAttributes)
st_size = make_longlong(info.c_nFileSizeHigh, info.c_nFileSizeLow)
- ctime, ctime_ns = FILE_TIME_to_time_t_nsec(info.c_ftCreationTime)
- mtime, mtime_ns = FILE_TIME_to_time_t_nsec(info.c_ftLastWriteTime)
- atime, atime_ns = FILE_TIME_to_time_t_nsec(info.c_ftLastAccessTime)
+ ctime = FILE_TIME_to_time_t_float(info.c_ftCreationTime)
+ mtime = FILE_TIME_to_time_t_float(info.c_ftLastWriteTime)
+ atime = FILE_TIME_to_time_t_float(info.c_ftLastAccessTime)
result = (st_mode,
0, 0, 0, 0, 0,
st_size,
- float(atime) + atime_ns * 1e-9,
- float(mtime) + mtime_ns * 1e-9,
- float(ctime) + ctime_ns * 1e-9)
+ atime, mtime, ctime)
return make_stat_result(result)
@@ -483,9 +481,9 @@
# similar to the one above
st_mode = attributes_to_mode(info.c_dwFileAttributes)
st_size = make_longlong(info.c_nFileSizeHigh, info.c_nFileSizeLow)
- ctime, ctime_ns = FILE_TIME_to_time_t_nsec(info.c_ftCreationTime)
- mtime, mtime_ns = FILE_TIME_to_time_t_nsec(info.c_ftLastWriteTime)
- atime, atime_ns = FILE_TIME_to_time_t_nsec(info.c_ftLastAccessTime)
+ ctime = FILE_TIME_to_time_t_float(info.c_ftCreationTime)
+ mtime = FILE_TIME_to_time_t_float(info.c_ftLastWriteTime)
+ atime = FILE_TIME_to_time_t_float(info.c_ftLastAccessTime)
# specific to fstat()
st_ino = make_longlong(info.c_nFileIndexHigh, info.c_nFileIndexLow)
@@ -494,9 +492,7 @@
result = (st_mode,
st_ino, 0, st_nlink, 0, 0,
st_size,
- atime + atime_ns * 1e-9,
- mtime + mtime_ns * 1e-9,
- ctime + ctime_ns * 1e-9)
+ atime, mtime, ctime)
return make_stat_result(result)
@@ -579,12 +575,10 @@
# Seconds between 1.1.1601 and 1.1.1970
secs_between_epochs = rffi.r_longlong(11644473600)
-def FILE_TIME_to_time_t_nsec(filetime):
+def FILE_TIME_to_time_t_float(filetime):
ft = make_longlong(filetime.c_dwHighDateTime, filetime.c_dwLowDateTime)
# FILETIME is in units of 100 nsec
- nsec = (ft % 10000000) * 100
- time = (ft / 10000000) - secs_between_epochs
- return intmask(time), intmask(nsec)
+ return float(ft) * (1.0 / 10000000.0) - secs_between_epochs
def time_t_to_FILE_TIME(time, filetime):
ft = rffi.r_longlong((time + secs_between_epochs) * 10000000)
diff --git a/rpython/rtyper/module/test/test_ll_os.py
b/rpython/rtyper/module/test/test_ll_os.py
--- a/rpython/rtyper/module/test/test_ll_os.py
+++ b/rpython/rtyper/module/test/test_ll_os.py
@@ -76,6 +76,11 @@
t1 = 1159195039.25
compile(f, (str, float))(str(fname), t1)
assert t1 == os.stat(str(fname)).st_mtime
+ if sys.version_info < (2, 7):
+ py.test.skip('requires Python 2.7')
+ t1 = 5000000000.0
+ compile(f, (str, float))(str(fname), t1)
+ assert t1 == os.stat(str(fname)).st_mtime
def test__getfullpathname():
if os.name != 'nt':
diff --git a/rpython/rtyper/module/test/test_ll_os_stat.py
b/rpython/rtyper/module/test/test_ll_os_stat.py
--- a/rpython/rtyper/module/test/test_ll_os_stat.py
+++ b/rpython/rtyper/module/test/test_ll_os_stat.py
@@ -1,4 +1,5 @@
from rpython.rtyper.module import ll_os_stat, ll_os
+from rpython.tool.udir import udir
import sys, os
import py
@@ -33,3 +34,13 @@
fstat = ll_os_stat.make_win32_stat_impl('fstat', ll_os.StringTraits())
stat = fstat(0) # stdout
assert stat.st_mode != 0
+
+ def test_stat_large_number(self):
+ if sys.version_info < (2, 7):
+ py.test.skip('requires Python 2.7')
+ fname = udir.join('test_stat_large_number.txt')
+ fname.ensure()
+ t1 = 5000000000.0
+ os.utime(str(fname), (t1, t1))
+ stat = ll_os_stat.make_win32_stat_impl('stat', ll_os.StringTraits())
+ assert stat(str(fname)).st_mtime == t1
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit