[pypy-commit] pypy default: replace FixedSizeArray with CArrayPtr and scoped_alloc

mattip pypy.commits at gmail.com
Wed Mar 23 17:59:22 EDT 2016


Author: mattip <matti.picus at gmail.com>
Branch: 
Changeset: r83308:3d5dcf2b84e1
Date: 2016-03-23 23:54 +0200
http://bitbucket.org/pypy/pypy/changeset/3d5dcf2b84e1/

Log:	replace FixedSizeArray with CArrayPtr and scoped_alloc

diff --git a/rpython/rlib/rtime.py b/rpython/rlib/rtime.py
--- a/rpython/rlib/rtime.py
+++ b/rpython/rlib/rtime.py
@@ -148,13 +148,12 @@
 
 if _WIN32:
     # hacking to avoid LARGE_INTEGER which is a union...
-    A = lltype.FixedSizeArray(lltype.SignedLongLong, 1)
     QueryPerformanceCounter = external(
-        'QueryPerformanceCounter', [lltype.Ptr(A)], lltype.Void,
-        releasegil=False)
+        'QueryPerformanceCounter', [rffi.CArrayPtr(lltype.SignedLongLong)],
+         lltype.Void, releasegil=False)
     QueryPerformanceFrequency = external(
-        'QueryPerformanceFrequency', [lltype.Ptr(A)], rffi.INT,
-        releasegil=False)
+        'QueryPerformanceFrequency', [rffi.CArrayPtr(lltype.SignedLongLong)], 
+        rffi.INT, releasegil=False)
     class State(object):
         divisor = 0.0
         counter_start = 0
@@ -178,15 +177,14 @@
                            releasegil=False)
 
 def win_perf_counter():
-    a = lltype.malloc(A, flavor='raw')
-    if state.divisor == 0.0:
+    with lltype.scoped_alloc(rffi.CArray(rffi.lltype.SignedLongLong), 1) as a:
+        if state.divisor == 0.0:
+            QueryPerformanceCounter(a)
+            state.counter_start = a[0]
+            QueryPerformanceFrequency(a)
+            state.divisor = float(a[0])
         QueryPerformanceCounter(a)
-        state.counter_start = a[0]
-        QueryPerformanceFrequency(a)
-        state.divisor = float(a[0])
-    QueryPerformanceCounter(a)
-    diff = a[0] - state.counter_start
-    lltype.free(a, flavor='raw')
+        diff = a[0] - state.counter_start
     return float(diff) / state.divisor
 
 @replace_time_function('clock')


More information about the pypy-commit mailing list