Commits

wlav  committed 63b2442

allow typed pointer null creation and setting

  • Participants
  • Parent commits d57f7dd
  • Branches reflex-support

Comments (0)

Files changed (3)

File pypy/module/cppyy/converter.py

         except OperationError:
             pass             # no set on buffer/array/None
 
-class VoidPtrRefConverter(TypeConverter):
+class VoidPtrRefConverter(VoidPtrPtrConverter):
     _immutable_ = True
-
-    def convert_argument(self, space, w_obj, address, call_local):
-        x = rffi.cast(rffi.VOIDPP, address)
-        x[0] = rffi.cast(rffi.VOIDP, get_rawobject(space, w_obj))
-        ba = rffi.cast(rffi.CCHARP, address)
-        ba[capi.c_function_arg_typeoffset()] = 'r'
-
+    uses_local = True
 
 class InstancePtrConverter(TypeConverter):
     _immutable_ = True

File pypy/module/cppyy/test/advancedcpp.h

     long gime_address_ptr_ref(void*& obj) {
         return (long)obj;
     }
+
+    static long set_address_ptr_ptr(void** obj) {
+        (*(long**)obj) = (long*)0x4321;
+        return 42;
+    }
+
+    static long set_address_ptr_ref(void*& obj) {
+        obj = (void*)0x1234;
+        return 21;
+    }
 };
 
 

File pypy/module/cppyy/test/test_advancedcpp.py

         assert 0 == pp.gime_address_ptr(0)
         assert 0 == pp.gime_address_ptr(None)
 
+        ptr = cppyy.bind_object(0, some_concrete_class)
+        assert cppyy.addressof(ptr) == 0
+        pp.set_address_ptr_ref(ptr)
+        assert cppyy.addressof(ptr) == 0x1234
+        pp.set_address_ptr_ptr(ptr)
+        assert cppyy.addressof(ptr) == 0x4321
+
     def test09_opaque_pointer_assing(self):
         """Test passing around of opaque pointers"""