[pypy-commit] pypy ffi-backend: Fixes.

arigo noreply at buildbot.pypy.org
Sat Jun 23 11:36:00 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: ffi-backend
Changeset: r55769:ac9ed01aaf60
Date: 2012-06-23 11:35 +0200
http://bitbucket.org/pypy/pypy/changeset/ac9ed01aaf60/

Log:	Fixes.

diff --git a/pypy/module/_ffi_backend/cdataobj.py b/pypy/module/_ffi_backend/cdataobj.py
--- a/pypy/module/_ffi_backend/cdataobj.py
+++ b/pypy/module/_ffi_backend/cdataobj.py
@@ -127,10 +127,10 @@
         misc.write_raw_float_data(self._cdata, source, self.ctype.size)
         keepalive_until_here(self)
 
-##    def convert_to_object(self):
-##        w_obj = self.ctype.convert_to_object(self._cdata)
-##        keepalive_until_here(self)
-##        return w_obj
+    def convert_to_object(self):
+        w_obj = self.ctype.convert_to_object(self._cdata)
+        keepalive_until_here(self)
+        return w_obj
 
     def get_array_length(self):
         from pypy.module._ffi_backend import ctypeobj
diff --git a/pypy/module/_ffi_backend/ctypeobj.py b/pypy/module/_ffi_backend/ctypeobj.py
--- a/pypy/module/_ffi_backend/ctypeobj.py
+++ b/pypy/module/_ffi_backend/ctypeobj.py
@@ -88,7 +88,6 @@
         elif space.is_w(w_ob, space.w_None):
             value = lltype.nullptr(rffi.CCHARP.TO)
         else:
-            xxx
             value = misc.as_unsigned_long_long(space, w_ob, strict=False)
             value = rffi.cast(rffi.CCHARP, value)
         return cdataobj.W_CData(space, value, self)
@@ -161,8 +160,9 @@
     def cast(self, w_ob):
         space = self.space
         ob = space.interpclass_w(w_ob)
-        if isinstance(ob, cdataobj.W_CData):
-            xxx
+        if (isinstance(ob, cdataobj.W_CData) and
+               isinstance(ob.ctype, W_CTypePtrOrArray)):
+            value = rffi.cast(lltype.Signed, ob._cdata)
         elif space.isinstance_w(w_ob, space.w_str):
             value = self.cast_single_char(w_ob)
         elif space.is_w(w_ob, space.w_None):
@@ -261,8 +261,11 @@
         space = self.space
         ob = space.interpclass_w(w_ob)
         if isinstance(ob, cdataobj.W_CData):
-            xxx
-        elif space.isinstance_w(w_ob, space.w_str):
+            if not isinstance(ob.ctype, W_CTypePrimitive):
+                xxx
+            w_ob = ob.convert_to_object()
+        #
+        if space.isinstance_w(w_ob, space.w_str):
             value = self.cast_single_char(w_ob)
         elif space.is_w(w_ob, space.w_None):
             value = 0.0


More information about the pypy-commit mailing list