[pypy-commit] pypy win32-cleanup2: fix for clock_gettime
mattip
noreply at buildbot.pypy.org
Fri Apr 6 09:02:44 CEST 2012
Author: Matti Picus <matti.picus at gmail.com>
Branch: win32-cleanup2
Changeset: r54214:3b96efd18ff6
Date: 2012-04-06 10:00 +0300
http://bitbucket.org/pypy/pypy/changeset/3b96efd18ff6/
Log: fix for clock_gettime
diff --git a/pypy/module/__pypy__/interp_time.py b/pypy/module/__pypy__/interp_time.py
--- a/pypy/module/__pypy__/interp_time.py
+++ b/pypy/module/__pypy__/interp_time.py
@@ -1,5 +1,5 @@
from __future__ import with_statement
-import sys
+import os
from pypy.interpreter.error import exception_from_errno
from pypy.interpreter.gateway import unwrap_spec
@@ -7,11 +7,15 @@
from pypy.rpython.tool import rffi_platform
from pypy.translator.tool.cbuild import ExternalCompilationInfo
+if os.name == 'nt':
+ libraries = []
+else:
+ libraries = ["rt"]
class CConfig:
_compilation_info_ = ExternalCompilationInfo(
includes=["time.h"],
- libraries=["rt"],
+ libraries=libraries,
)
HAS_CLOCK_GETTIME = rffi_platform.Has('clock_gettime')
@@ -22,11 +26,6 @@
CLOCK_PROCESS_CPUTIME_ID = rffi_platform.DefinedConstantInteger("CLOCK_PROCESS_CPUTIME_ID")
CLOCK_THREAD_CPUTIME_ID = rffi_platform.DefinedConstantInteger("CLOCK_THREAD_CPUTIME_ID")
- TIMESPEC = rffi_platform.Struct("struct timespec", [
- ("tv_sec", rffi.TIME_T),
- ("tv_nsec", rffi.LONG),
- ])
-
cconfig = rffi_platform.configure(CConfig)
HAS_CLOCK_GETTIME = cconfig["HAS_CLOCK_GETTIME"]
@@ -37,29 +36,33 @@
CLOCK_PROCESS_CPUTIME_ID = cconfig["CLOCK_PROCESS_CPUTIME_ID"]
CLOCK_THREAD_CPUTIME_ID = cconfig["CLOCK_THREAD_CPUTIME_ID"]
-TIMESPEC = cconfig["TIMESPEC"]
+if HAS_CLOCK_GETTIME:
+ TIMESPEC = lltype.Struct("struct timespec",
+ ("tv_sec", rffi.TIME_T),
+ ("tv_nsec", rffi.LONG),
+ )
-c_clock_gettime = rffi.llexternal("clock_gettime",
- [lltype.Signed, lltype.Ptr(TIMESPEC)], rffi.INT,
- compilation_info=CConfig._compilation_info_, threadsafe=False
-)
-c_clock_getres = rffi.llexternal("clock_getres",
- [lltype.Signed, lltype.Ptr(TIMESPEC)], rffi.INT,
- compilation_info=CConfig._compilation_info_, threadsafe=False
-)
+ c_clock_gettime = rffi.llexternal("clock_gettime",
+ [lltype.Signed, lltype.Ptr(TIMESPEC)], rffi.INT,
+ compilation_info=CConfig._compilation_info_, threadsafe=False
+ )
+ c_clock_getres = rffi.llexternal("clock_getres",
+ [lltype.Signed, lltype.Ptr(TIMESPEC)], rffi.INT,
+ compilation_info=CConfig._compilation_info_, threadsafe=False
+ )
- at unwrap_spec(clk_id="c_int")
-def clock_gettime(space, clk_id):
- with lltype.scoped_alloc(TIMESPEC) as tp:
- ret = c_clock_gettime(clk_id, tp)
- if ret != 0:
- raise exception_from_errno(space, space.w_IOError)
- return space.wrap(tp.c_tv_sec + tp.c_tv_nsec * 1e-9)
+ @unwrap_spec(clk_id="c_int")
+ def clock_gettime(space, clk_id):
+ with lltype.scoped_alloc(TIMESPEC) as tp:
+ ret = c_clock_gettime(clk_id, tp)
+ if ret != 0:
+ raise exception_from_errno(space, space.w_IOError)
+ return space.wrap(tp.c_tv_sec + tp.c_tv_nsec * 1e-9)
- at unwrap_spec(clk_id="c_int")
-def clock_getres(space, clk_id):
- with lltype.scoped_alloc(TIMESPEC) as tp:
- ret = c_clock_getres(clk_id, tp)
- if ret != 0:
- raise exception_from_errno(space, space.w_IOError)
- return space.wrap(tp.c_tv_sec + tp.c_tv_nsec * 1e-9)
+ @unwrap_spec(clk_id="c_int")
+ def clock_getres(space, clk_id):
+ with lltype.scoped_alloc(TIMESPEC) as tp:
+ ret = c_clock_getres(clk_id, tp)
+ if ret != 0:
+ raise exception_from_errno(space, space.w_IOError)
+ return space.wrap(tp.c_tv_sec + tp.c_tv_nsec * 1e-9)
More information about the pypy-commit
mailing list