[pypy-svn] r56185 - in pypy/dist/pypy: module/rctime module/rctime/test rpython/lltypesystem rpython/module

afa at codespeak.net afa at codespeak.net
Mon Jun 30 19:20:00 CEST 2008


Author: afa
Date: Mon Jun 30 19:19:59 2008
New Revision: 56185

Modified:
   pypy/dist/pypy/module/rctime/interp_time.py
   pypy/dist/pypy/module/rctime/test/test_rctime.py
   pypy/dist/pypy/rpython/lltypesystem/rffi.py
   pypy/dist/pypy/rpython/module/ll_os.py
   pypy/dist/pypy/rpython/module/ll_time.py
Log:
Export rffi.TIME_T, and use it consistently in all time modules.
This is needed by some platforms (win32 with VS8.0) which define long as 32bit,
but time_t as 64bit.


Modified: pypy/dist/pypy/module/rctime/interp_time.py
==============================================================================
--- pypy/dist/pypy/module/rctime/interp_time.py	(original)
+++ pypy/dist/pypy/module/rctime/interp_time.py	Mon Jun 30 19:19:59 2008
@@ -24,8 +24,6 @@
     )
     CLOCKS_PER_SEC = platform.ConstantInteger("CLOCKS_PER_SEC")
     clock_t = platform.SimpleType("clock_t", rffi.ULONG)
-    time_t = platform.SimpleType("time_t", rffi.LONG)
-    size_t = platform.SimpleType("size_t", rffi.LONG)
     has_gettimeofday = platform.Has('gettimeofday')
     
 if _POSIX:
@@ -64,26 +62,23 @@
 
 CLOCKS_PER_SEC = cConfig.CLOCKS_PER_SEC
 clock_t = cConfig.clock_t
-time_t = cConfig.time_t
-size_t = cConfig.size_t
 tm = cConfig.tm
 glob_buf = lltype.malloc(tm, flavor='raw', zero=True)
 
 if cConfig.has_gettimeofday:
     c_gettimeofday = external('gettimeofday', [rffi.VOIDP, rffi.VOIDP], rffi.INT)
-TIME_TP = rffi.CArrayPtr(time_t)
 TM_P = lltype.Ptr(tm)
-c_clock = external('clock', [TIME_TP], clock_t)
-c_time = external('time', [TIME_TP], time_t)
-c_ctime = external('ctime', [TIME_TP], rffi.CCHARP)
-c_gmtime = external('gmtime', [TIME_TP], TM_P)
-c_mktime = external('mktime', [TM_P], time_t)
+c_clock = external('clock', [rffi.TIME_TP], clock_t)
+c_time = external('time', [rffi.TIME_TP], rffi.TIME_T)
+c_ctime = external('ctime', [rffi.TIME_TP], rffi.CCHARP)
+c_gmtime = external('gmtime', [rffi.TIME_TP], TM_P)
+c_mktime = external('mktime', [TM_P], rffi.TIME_T)
 c_asctime = external('asctime', [TM_P], rffi.CCHARP)
-c_localtime = external('localtime', [TIME_TP], TM_P)
+c_localtime = external('localtime', [rffi.TIME_TP], TM_P)
 if _POSIX:
     c_tzset = external('tzset', [], lltype.Void)
-c_strftime = external('strftime', [rffi.CCHARP, size_t, rffi.CCHARP, TM_P],
-                      size_t)
+c_strftime = external('strftime', [rffi.CCHARP, rffi.SIZE_T, rffi.CCHARP, TM_P],
+                      rffi.SIZE_T)
 
 def _init_accept2dyear():
     return (1, 0)[bool(os.getenv("PYTHONY2K"))]
@@ -109,9 +104,9 @@
     if _POSIX:
         YEAR = (365 * 24 + 6) * 3600
 
-        t = (((c_time(lltype.nullptr(TIME_TP.TO))) / YEAR) * YEAR)
+        t = (((c_time(lltype.nullptr(rffi.TIME_TP.TO))) / YEAR) * YEAR)
         # we cannot have reference to stack variable, put it on the heap
-        t_ref = lltype.malloc(TIME_TP.TO, 1, flavor='raw')
+        t_ref = lltype.malloc(rffi.TIME_TP.TO, 1, flavor='raw')
         t_ref[0] = t
         p = c_localtime(t_ref)
         janzone = -p.c_tm_gmtoff
@@ -164,10 +159,11 @@
     else:
         seconds = space.float_w(w_seconds)
     try:
-        return ovfcheck_float_to_int(seconds)
+        ovfcheck_float_to_int(seconds)
     except OverflowError:
         raise OperationError(space.w_ValueError,
                              space.wrap("time argument too large"))
+    return rffi.r_time_t(seconds)
 
 def _tm_to_tuple(space, t):
     time_tuple = []
@@ -189,8 +185,8 @@
 def _gettmarg(space, w_tup, allowNone=True):
     if allowNone and space.is_w(w_tup, space.w_None):
         # default to the current local time
-        tt = int(pytime.time())
-        t_ref = lltype.malloc(TIME_TP.TO, 1, flavor='raw')
+        tt = rffi.r_time_t(pytime.time())
+        t_ref = lltype.malloc(rffi.TIME_TP.TO, 1, flavor='raw')
         t_ref[0] = tt
         pbuf = c_localtime(t_ref)
         lltype.free(t_ref, flavor='raw')
@@ -283,7 +279,7 @@
 
     seconds = _get_inttime(space, w_seconds)
     
-    t_ref = lltype.malloc(TIME_TP.TO, 1, flavor='raw')
+    t_ref = lltype.malloc(rffi.TIME_TP.TO, 1, flavor='raw')
     t_ref[0] = seconds
     p = c_ctime(t_ref)
     lltype.free(t_ref, flavor='raw')
@@ -322,7 +318,7 @@
     # rpython does not support that a variable has two incompatible builtins
     # as value so we have to duplicate the code. NOT GOOD! see localtime() too
     seconds = _get_inttime(space, w_seconds)
-    t_ref = lltype.malloc(TIME_TP.TO, 1, flavor='raw')
+    t_ref = lltype.malloc(rffi.TIME_TP.TO, 1, flavor='raw')
     t_ref[0] = seconds
     p = c_gmtime(t_ref)
     lltype.free(t_ref, flavor='raw')
@@ -340,7 +336,7 @@
     When 'seconds' is not passed in, convert the current time instead."""
 
     seconds = _get_inttime(space, w_seconds)
-    t_ref = lltype.malloc(TIME_TP.TO, 1, flavor='raw')
+    t_ref = lltype.malloc(rffi.TIME_TP.TO, 1, flavor='raw')
     t_ref[0] = seconds
     p = c_localtime(t_ref)
     lltype.free(t_ref, flavor='raw')

Modified: pypy/dist/pypy/module/rctime/test/test_rctime.py
==============================================================================
--- pypy/dist/pypy/module/rctime/test/test_rctime.py	(original)
+++ pypy/dist/pypy/module/rctime/test/test_rctime.py	Mon Jun 30 19:19:59 2008
@@ -76,6 +76,7 @@
     
     def test_mktime(self):
         import time as rctime
+        import os, sys
         raises(TypeError, rctime.mktime, "foo")
         raises(TypeError, rctime.mktime, None)
         raises(TypeError, rctime.mktime, (1, 2))
@@ -93,7 +94,8 @@
         ltime = list(ltime)
         ltime[0] = 67
         ltime = tuple(ltime)
-        raises(OverflowError, rctime.mktime, ltime)
+        if os.name != "nt" and sys.maxint < 1<<32:   # time_t may be 64bit
+            raises(OverflowError, rctime.mktime, ltime)
     
         ltime = list(ltime)
         ltime[0] = 100

Modified: pypy/dist/pypy/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rffi.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/rffi.py	Mon Jun 30 19:19:59 2008
@@ -286,7 +286,8 @@
     for name in (_name, 'unsigned ' + _name):
         TYPES.append(name)
 TYPES += ['signed char', 'unsigned char',
-          'long long', 'unsigned long long', 'size_t']
+          'long long', 'unsigned long long',
+          'size_t', 'time_t']
 if os.name != 'nt':
     TYPES.append('mode_t')
     TYPES.append('pid_t')
@@ -331,6 +332,7 @@
 #        LONGLONG       r_longlong
 #        ULONGLONG      r_ulonglong
 #        SIZE_T         r_size_t
+#        TIME_T         r_time_t
 # --------------------------------------------------------------------
 # Note that rffi.r_int is not necessarily the same as
 # rarithmetic.r_int, etc!  rffi.INT/r_int correspond to the C-level

Modified: pypy/dist/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/dist/pypy/rpython/module/ll_os.py	(original)
+++ pypy/dist/pypy/rpython/module/ll_os.py	Mon Jun 30 19:19:59 2008
@@ -261,8 +261,8 @@
             # we only have utime(), which does not allow sub-second resolution
             def os_utime_platform(path, actime, modtime):
                 l_utimbuf = lltype.malloc(UTIMBUFP.TO, flavor='raw')
-                l_utimbuf.c_actime  = int(actime)
-                l_utimbuf.c_modtime = int(modtime)
+                l_utimbuf.c_actime  = rffi.r_time_t(actime)
+                l_utimbuf.c_modtime = rffi.r_time_t(modtime)
                 error = os_utime(path, l_utimbuf)
                 lltype.free(l_utimbuf, flavor='raw')
                 return error

Modified: pypy/dist/pypy/rpython/module/ll_time.py
==============================================================================
--- pypy/dist/pypy/rpython/module/ll_time.py	(original)
+++ pypy/dist/pypy/rpython/module/ll_time.py	Mon Jun 30 19:19:59 2008
@@ -25,7 +25,6 @@
     CLOCK_T = platform.SimpleType('clock_t', rffi.INT)
     TIMEVAL = platform.Struct('struct timeval', [('tv_sec', rffi.INT),
                                                  ('tv_usec', rffi.INT)])
-    TIME_T = platform.SimpleType('time_t', rffi.INT)
     HAVE_GETTIMEOFDAY = platform.Has('gettimeofday')
     HAVE_FTIME = platform.Has('ftime')
 
@@ -78,7 +77,7 @@
         else:
             c_ftime = None    # to not confuse the flow space
 
-        c_time = self.llexternal('time', [rffi.VOIDP], self.TIME_T,
+        c_time = self.llexternal('time', [rffi.VOIDP], rffi.TIME_T,
                                  _nowrapper=True, threadsafe=False)
 
         def time_time_llimpl():



More information about the Pypy-commit mailing list