[pypy-svn] r29694 - pypy/dist/pypy/module/rctime
rhymes at codespeak.net
rhymes at codespeak.net
Thu Jul 6 18:38:23 CEST 2006
Author: rhymes
Date: Thu Jul 6 18:38:21 2006
New Revision: 29694
Added:
pypy/dist/pypy/module/rctime/
pypy/dist/pypy/module/rctime/__init__.py
pypy/dist/pypy/module/rctime/__init__.pyc (contents, props changed)
pypy/dist/pypy/module/rctime/app_time.py
pypy/dist/pypy/module/rctime/app_time.pyc (contents, props changed)
pypy/dist/pypy/module/rctime/interp_time.py
pypy/dist/pypy/module/rctime/interp_time.pyc (contents, props changed)
Log:
(rhymes, arre, brian): initial implementation of time module on rctypes. accept2dyear and time.time()
Added: pypy/dist/pypy/module/rctime/__init__.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/rctime/__init__.py Thu Jul 6 18:38:21 2006
@@ -0,0 +1,22 @@
+
+from pypy.interpreter.mixedmodule import MixedModule
+
+class Module(MixedModule):
+ interpleveldefs = {
+ 'accept2dyear' : 'interp_time.accept2dyear',
+ 'time': 'interp_time.time',
+ }
+
+ # def init(self, space):
+# from pypy.module.rctime import interp_time
+# interp_time.init_module(space)
+#
+ def buildloaders(cls):
+ from pypy.module.rctime import interp_time
+ Module.interpleveldefs["accept2dyear"] = 'space.wrap(%r)' % interp_time._init_accept2dyear()
+ super(Module, cls).buildloaders()
+ buildloaders = classmethod(buildloaders)
+
+ appleveldefs = {
+ # 'floattime' : 'app_time._floattime'
+ }
Added: pypy/dist/pypy/module/rctime/__init__.pyc
==============================================================================
Binary file. No diff available.
Added: pypy/dist/pypy/module/rctime/app_time.py
==============================================================================
Added: pypy/dist/pypy/module/rctime/app_time.pyc
==============================================================================
Binary file. No diff available.
Added: pypy/dist/pypy/module/rctime/interp_time.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/rctime/interp_time.py Thu Jul 6 18:38:21 2006
@@ -0,0 +1,73 @@
+from pypy.rpython.rctypes.tool import ctypes_platform
+from pypy.rpython.rctypes.tool.libc import libc
+import pypy.rpython.rctypes.implementation # this defines rctypes magic
+from pypy.rpython.rctypes.aerrno import geterrno
+from pypy.interpreter.error import OperationError
+from ctypes import *
+import os
+
+class CConfig:
+ _header_ = "#include <sys/time.h>"
+ timeval = ctypes_platform.Struct("struct timeval", [("tv_sec", c_int), ("tv_usec", c_int)])
+
+class cConfig:
+ pass
+cConfig.__dict__.update(ctypes_platform.configure(CConfig))
+cConfig.timeval.__name__ = "ctimeval"
+
+libc.strerror.restype = c_char_p
+
+has_gettimeofday = False
+if hasattr(libc, "gettimeofday"):
+ libc.gettimeofday.argtypes = [c_void_p, c_void_p]
+ libc.gettimeofday.restype = c_int
+ has_gettimeofday = True
+
+
+# class _timeval(Structure):
+# _fields_ = [("tv_sec", c_long),
+# ("tv_usec", c_long)]
+
+def _init_accept2dyear():
+ return (1, 0)[bool(os.getenv("PYTHONY2K"))]
+
+
+def _get_error_msg():
+ errno = geterrno()
+ return libc.strerror(errno)
+
+def _floattime():
+ """ _floattime() -> computes time since the Epoch for various platforms.
+
+ Since on some system gettimeofday may fail we fall back on ftime
+ or time.
+
+ gettimeofday() has a resolution in microseconds
+ ftime() has a resolution in milliseconds and it never fails
+ time() has a resolution in seconds
+ """
+
+ # if _MS_WINDOWS:
+ # return libc.time(None)
+ #
+ if has_gettimeofday:
+ t = cConfig.timeval()
+ if libc.gettimeofday(byref(t), c_void_p(None)) == 0:
+ return float(t.tv_sec) + t.tv_usec * 0.000001
+ return 0.0
+
+
+ # elif hasattr(_libc, "ftime"):
+ # t = _timeb()
+ # _libc.ftime.argtypes = [c_void_p]
+ # _libc.ftime(byref(t))
+ # return float(t.time) + float(t.millitm) * 0.001
+ # elif hasattr(_libc, "time"):
+ # t = c_long()
+ # _libc.time.argtypes = [c_void_p]
+ # _libc.time(byref(t))
+ # return t.value
+
+def time(space):
+ secs = _floattime()
+ return space.wrap(secs)
Added: pypy/dist/pypy/module/rctime/interp_time.pyc
==============================================================================
Binary file. No diff available.
More information about the Pypy-commit
mailing list