[pypy-svn] r75760 - in pypy/branch/interplevel-array: lib_pypy pypy/module/array pypy/module/array/test

hakanardo at codespeak.net hakanardo at codespeak.net
Fri Jul 2 14:29:08 CEST 2010


Author: hakanardo
Date: Fri Jul  2 14:29:07 2010
New Revision: 75760

Added:
   pypy/branch/interplevel-array/lib_pypy/oldarray.py   (props changed)
      - copied unchanged from r75759, pypy/branch/interplevel-array/lib_pypy/array.py
   pypy/branch/interplevel-array/pypy/module/array/
   pypy/branch/interplevel-array/pypy/module/array/__init__.py
   pypy/branch/interplevel-array/pypy/module/array/interp_array.py
   pypy/branch/interplevel-array/pypy/module/array/test/
   pypy/branch/interplevel-array/pypy/module/array/test/test_array.py
Removed:
   pypy/branch/interplevel-array/lib_pypy/array.py
Log:
simple lltype.malloc wrapper

Added: pypy/branch/interplevel-array/pypy/module/array/__init__.py
==============================================================================
--- (empty file)
+++ pypy/branch/interplevel-array/pypy/module/array/__init__.py	Fri Jul  2 14:29:07 2010
@@ -0,0 +1,12 @@
+# Package initialisation
+from pypy.interpreter.mixedmodule import MixedModule
+
+class Module(MixedModule):
+
+    appleveldefs = {
+    }
+    
+    interpleveldefs = {
+        'array'    : 'interp_array.array',
+    }
+

Added: pypy/branch/interplevel-array/pypy/module/array/interp_array.py
==============================================================================
--- (empty file)
+++ pypy/branch/interplevel-array/pypy/module/array/interp_array.py	Fri Jul  2 14:29:07 2010
@@ -0,0 +1,44 @@
+from pypy.interpreter.baseobjspace import Wrappable
+from pypy.interpreter.typedef import TypeDef
+from pypy.rpython.lltypesystem import lltype, rffi
+from pypy.interpreter.gateway import interp2app, ObjSpace
+from pypy.rlib.jit import dont_look_inside
+from pypy.rlib import rgc
+
+FloatArray=lltype.GcArray(lltype.Float)
+
+class W_Array(Wrappable):
+    @dont_look_inside
+    def __init__(self, space, size):
+        self.space=space
+        self.size=size
+        print "malloc"
+        #self.buffer = lltype.malloc(rffi.DOUBLEP.TO, size, flavor='raw', zero=True)
+        #self.buffer = rgc.malloc_nonmovable(lltype.GcArray(lltype.Float), size)
+        self.buffer = lltype.malloc(FloatArray, size, zero=True)
+        print "buf: ", self.buffer
+
+    def __del__(self):
+        print "free"
+        #lltype.free(self.buffer, flavor='raw')
+
+    def descr_getitem(self, idx):
+        return self.space.wrap(self.buffer[idx])
+    descr_getitem.unwrap_spec = ['self', int]
+    
+    def descr_setitem(self, idx, val):
+        self.buffer[idx]=val
+    descr_setitem.unwrap_spec = ['self', int, float]
+
+W_Array.typedef = TypeDef(
+    'Array',
+    __getitem__ = interp2app(W_Array.descr_getitem),
+    __setitem__ = interp2app(W_Array.descr_setitem),
+)
+        
+        
+
+
+def array(space,size):
+    return W_Array(space, size)
+array.unwrap_spec=(ObjSpace, int)

Added: pypy/branch/interplevel-array/pypy/module/array/test/test_array.py
==============================================================================
--- (empty file)
+++ pypy/branch/interplevel-array/pypy/module/array/test/test_array.py	Fri Jul  2 14:29:07 2010
@@ -0,0 +1,26 @@
+from pypy.conftest import gettestobjspace
+
+class AppTestcArray:
+    def setup_class(cls):
+        cls.space = gettestobjspace(usemodules=('array',))
+        cls.w_array = cls.space.appexec([], """():
+            import array
+            return array.array
+        """)
+
+    def test_simple(self):
+        a=self.array(10)
+        a[5]=7.42
+        assert a[5]==7.42
+
+
+## space.sys.get('modules')
+
+## w_import   = space.builtin.get('__import__')
+## w_array  = space.call(w_import, space.newlist([space.wrap('array')]))
+
+## print w_array
+## space.appexec([], "(): import array; print array.array(7)")
+## print space.appexec([], "(): import array; return array.array(7)")
+## space.appexec([], "(): import array; a=array.array(7); print a[2]")
+## space.appexec([], "(): import array; a=array.array(7); a[2]=7.42; print a[2]")



More information about the Pypy-commit mailing list