[pypy-svn] r46258 - in pypy/branch/pypy-more-rtti-inprogress: objspace/flow rpython/module
arigo at codespeak.net
arigo at codespeak.net
Mon Sep 3 11:13:19 CEST 2007
Author: arigo
Date: Mon Sep 3 11:13:18 2007
New Revision: 46258
Modified:
pypy/branch/pypy-more-rtti-inprogress/objspace/flow/objspace.py
pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_time.py
Log:
time.time() -> win
Modified: pypy/branch/pypy-more-rtti-inprogress/objspace/flow/objspace.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/objspace/flow/objspace.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/objspace/flow/objspace.py Mon Sep 3 11:13:18 2007
@@ -241,7 +241,9 @@
if func.func_closure is None:
closure = None
else:
- closure = [extract_cell_content(c) for c in func.func_closure]
+ closure = [extract_cell_content(c, name, func)
+ for c, name in zip(func.func_closure,
+ func.func_code.co_freevars)]
# CallableFactory.pycall may add class_ to functions that are methods
name = func.func_name
class_ = getattr(func, 'class_', None)
@@ -558,7 +560,7 @@
OverflowError) # for the float case
del _add_exceptions, _add_except_ovf
-def extract_cell_content(c):
+def extract_cell_content(c, varname, func):
"""Get the value contained in a CPython 'cell', as read through
the func_closure of a function object."""
# yuk! this is all I could come up with that works in Python 2.2 too
@@ -572,7 +574,11 @@
x = X()
x_cell, = (lambda: x).func_closure
x_cell == c
- return x.other # crashes if the cell is actually empty
+ try:
+ return x.other # crashes if the cell is actually empty
+ except AttributeError:
+ raise Exception("in %r, the free variable %r has no value" % (
+ func, varname))
def make_op(name, symbol, arity, specialnames):
if hasattr(FlowObjSpace, name):
Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_time.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_time.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_time.py Mon Sep 3 11:13:18 2007
@@ -46,51 +46,50 @@
@registering(time.time)
def register_time_time(self):
- if sys.platform == 'win32':
- xxx
+ # AWFUL
+ if self.HAVE_GETTIMEOFDAY:
+ if self.GETTIMEOFDAY_NO_TZ:
+ c_gettimeofday = self.llexternal('gettimeofday',
+ [self.TIMEVALP], rffi.INT)
+ else:
+ c_gettimeofday = self.llexternal('gettimeofday',
+ [self.TIMEVALP, rffi.VOIDP], rffi.INT)
+ else:
+ c_gettimeofday = None
+
+ if self.HAVE_FTIME:
+ self.configure(CConfigForFTime)
+ c_ftime = self.llexternal('ftime', [lltype.Ptr(self.TIMEB)],
+ lltype.Void)
else:
- # AWFUL
+ c_ftime = None # to not confuse the flow space
+
+ c_time = self.llexternal('time', [rffi.VOIDP], self.TIME_T)
+
+ def time_time_llimpl():
+ void = lltype.nullptr(rffi.VOIDP.TO)
+ result = -1.0
if self.HAVE_GETTIMEOFDAY:
+ t = lltype.malloc(self.TIMEVAL, flavor='raw')
+
if self.GETTIMEOFDAY_NO_TZ:
- c_gettimeofday = self.llexternal('gettimeofday',
- [self.TIMEVALP], rffi.INT)
+ if c_gettimeofday(t) == 0:
+ result = float(t.c_tv_sec) + \
+ float(t.c_tv_usec) * 0.000001
else:
- c_gettimeofday = self.llexternal('gettimeofday',
- [self.TIMEVALP, rffi.VOIDP], rffi.INT)
- else:
- c_gettimeofday = None
-
+ if c_gettimeofday(t, void) == 0:
+ result = float(t.c_tv_sec) + \
+ float(t.c_tv_usec) * 0.000001
+ lltype.free(t, flavor='raw')
+ if result != -1:
+ return result
if self.HAVE_FTIME:
- self.configure(CConfigForFTime)
- c_ftime = self.llexternal('ftime', [lltype.Ptr(self.TIMEB)],
- lltype.Void)
-
- c_time = self.llexternal('time', [rffi.VOIDP], self.TIME_T)
-
- def time_time_llimpl():
- void = lltype.nullptr(rffi.VOIDP.TO)
- result = -1.0
- if self.HAVE_GETTIMEOFDAY:
- t = lltype.malloc(self.TIMEVAL, flavor='raw')
-
- if self.GETTIMEOFDAY_NO_TZ:
- if c_gettimeofday(t) == 0:
- result = float(t.c_tv_sec) + \
- float(t.c_tv_usec) * 0.000001
- else:
- if c_gettimeofday(t, void) == 0:
- result = float(t.c_tv_sec) + \
- float(t.c_tv_usec) * 0.000001
- lltype.free(t, flavor='raw')
- if result != -1:
- return result
- if self.HAVE_FTIME:
- t = lltype.malloc(self.TIMEB, flavor='raw')
- c_ftime(t)
- result = float(int(t.c_time)) + float(int(t.c_millitm)) * 0.001
- lltype.free(t, flavor='raw')
- return result
- return float(c_time(void))
+ t = lltype.malloc(self.TIMEB, flavor='raw')
+ c_ftime(t)
+ result = float(int(t.c_time)) + float(int(t.c_millitm)) * 0.001
+ lltype.free(t, flavor='raw')
+ return result
+ return float(c_time(void))
return extdef([], float, llimpl=time_time_llimpl,
export_name='ll_time.ll_time_time')
More information about the Pypy-commit
mailing list