[pypy-svn] r47503 - pypy/dist/pypy/module/_ffi

fijal at codespeak.net fijal at codespeak.net
Tue Oct 16 17:37:27 CEST 2007


Author: fijal
Date: Tue Oct 16 17:37:26 2007
New Revision: 47503

Modified:
   pypy/dist/pypy/module/_ffi/interp_ffi.py
   pypy/dist/pypy/module/_ffi/structure.py
Log:
* Do the right thing to access buffer
* Do the right think with characters (test coming)


Modified: pypy/dist/pypy/module/_ffi/interp_ffi.py
==============================================================================
--- pypy/dist/pypy/module/_ffi/interp_ffi.py	(original)
+++ pypy/dist/pypy/module/_ffi/interp_ffi.py	Tue Oct 16 17:37:26 2007
@@ -142,13 +142,18 @@
             mod = space.getbuiltinmodule('_ffi')
             w_StructureInstance = space.getattr(mod, w('StructureInstance'))
             if space.is_true(space.isinstance(w_arg, w_StructureInstance)):
-                #ptr.push_arg(lltype.cast_int_to_ptr(rffi.VOIDP, space.int_w(space.getattr(w_arg, w('buffer')))))
-                push_func(add_arg, argdesc, w_arg.ll_buffer)
+                ptr = rffi.cast(rffi.VOIDP, space.int_w(space.getattr(w_arg, w('buffer'))))
+                push_func(add_arg, argdesc, ptr)
             else:
                 raise OperationError(space.w_TypeError, w(
                     "Expected structure, array or simple type"))
     elif argtype == "c" or argtype == "b" or argtype == "B":
-        push_func(add_arg, argdesc, space.str_w(w_arg))
+        s = space.str_w(w_arg)
+        if len(s) != 1:
+            raise OperationError(space.w_ValueError, w(
+                "Expected string of length one as character"))
+        s = s[0]
+        push_func(add_arg, argdesc, s)
     else:
         assert argtype in "iIhHlLqQ"
         push_func(add_arg, argdesc, space.int_w(w_arg))

Modified: pypy/dist/pypy/module/_ffi/structure.py
==============================================================================
--- pypy/dist/pypy/module/_ffi/structure.py	(original)
+++ pypy/dist/pypy/module/_ffi/structure.py	Tue Oct 16 17:37:26 2007
@@ -46,14 +46,14 @@
 def push_field(self, num, value):
     ptr = rffi.ptradd(self.ll_buffer, self.ll_positions[num])
     TP = lltype.typeOf(value)
-    T = rffi.CArrayPtr(TP)
+    T = lltype.Ptr(rffi.CArray(TP))
     rffi.cast(T, ptr)[0] = value
 push_field._annspecialcase_ = 'specialize:argtype(2)'
     
 def cast_pos(self, ll_t):
     i = self.next_pos
     pos = rffi.ptradd(self.ll_buffer, self.ll_positions[i])
-    TP = rffi.CArrayPtr(ll_t)
+    TP = lltype.Ptr(rffi.CArray(ll_t))
     return rffi.cast(TP, pos)[0]
 cast_pos._annspecialcase_ = 'specialize:arg(1)'
 
@@ -101,6 +101,9 @@
         if self.free_afterwards:
             lltype.free(self.ll_buffer, flavor='raw')
 
+    def getbuffer(space, self):
+        return space.wrap(rffi.cast(rffi.INT, self.ll_buffer))
+
 def descr_new_structure_instance(space, w_type, w_shape, w_adr, w_fieldinits):
     return W_StructureInstance(space, w_shape, w_adr, w_fieldinits)
 
@@ -109,4 +112,5 @@
     __new__     = interp2app(descr_new_structure_instance),
     __getattr__ = interp2app(W_StructureInstance.getattr),
     __setattr__ = interp2app(W_StructureInstance.setattr),
+    buffer      = GetSetProperty(W_StructureInstance.getbuffer),
 )



More information about the Pypy-commit mailing list