[pypy-commit] pypy reflex-support: allow arrays through void** arguments

wlav noreply at buildbot.pypy.org
Fri Jul 20 01:31:29 CEST 2012


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r56241:f42fb7b18dcf
Date: 2012-07-19 11:27 -0700
http://bitbucket.org/pypy/pypy/changeset/f42fb7b18dcf/

Log:	allow arrays through void** arguments

diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py
--- a/pypy/module/cppyy/converter.py
+++ b/pypy/module/cppyy/converter.py
@@ -353,7 +353,7 @@
         try:
             buf = space.buffer_w(w_obj)
             x[0] = rffi.cast(rffi.VOIDP, buf.get_raw_address())
-        except (OperationError, ValueError):
+        except (OperationError, ValueError), e:
             x[0] = rffi.cast(rffi.VOIDP, get_rawobject(space, w_obj))
         ba[capi.c_function_arg_typeoffset()] = 'o'
 
@@ -365,17 +365,23 @@
     uses_local = True
 
     def convert_argument(self, space, w_obj, address, call_local):
+        x = rffi.cast(rffi.VOIDPP, address)
+        ba = rffi.cast(rffi.CCHARP, address)
         r = rffi.cast(rffi.VOIDPP, call_local)
-        r[0] = rffi.cast(rffi.VOIDP, get_rawobject(space, w_obj))
-        x = rffi.cast(rffi.VOIDPP, address)
+        try:
+            buf = space.buffer_w(w_obj)
+            r[0] = rffi.cast(rffi.VOIDP, buf.get_raw_address())
+        except (OperationError, ValueError), e:
+            r[0] = rffi.cast(rffi.VOIDP, get_rawobject(space, w_obj))
         x[0] = rffi.cast(rffi.VOIDP, call_local)
-        address = rffi.cast(capi.C_OBJECT, address)
-        ba = rffi.cast(rffi.CCHARP, address)
         ba[capi.c_function_arg_typeoffset()] = 'a'
 
     def finalize_call(self, space, w_obj, call_local):
         r = rffi.cast(rffi.VOIDPP, call_local)
-        set_rawobject(space, w_obj, r[0])
+        try:
+            set_rawobject(space, w_obj, r[0])
+        except OperationError:
+            pass             # no set on buffer/array
 
 class VoidPtrRefConverter(TypeConverter):
     _immutable_ = True
diff --git a/pypy/module/cppyy/test/test_advancedcpp.py b/pypy/module/cppyy/test/test_advancedcpp.py
--- a/pypy/module/cppyy/test/test_advancedcpp.py
+++ b/pypy/module/cppyy/test/test_advancedcpp.py
@@ -7,7 +7,7 @@
 currpath = py.path.local(__file__).dirpath()
 test_dct = str(currpath.join("advancedcppDict.so"))
 
-space = gettestobjspace(usemodules=['cppyy'])
+space = gettestobjspace(usemodules=['cppyy', 'array'])
 
 def setup_module(mod):
     if sys.platform == 'win32':
@@ -383,6 +383,10 @@
         assert cppyy.addressof(o) == pp.gime_address_ptr_ptr(o)
         assert cppyy.addressof(o) == pp.gime_address_ptr_ref(o)
 
+        import array
+        addressofo = array.array('l', [cppyy.addressof(o)])
+        assert addressofo.buffer_info()[0] == pp.gime_address_ptr_ptr(addressofo)
+
     def test09_opaque_pointer_assing(self):
         """Test passing around of opaque pointers"""
 


More information about the pypy-commit mailing list