1. Alexis D.
  2. pypy

Commits

wlav  committed 58ff96d

ptr-ptr and ptr-ref return types as ptr returns

  • Participants
  • Parent commits 94adcd5
  • Branches reflex-support

Comments (0)

Files changed (4)

File pypy/module/cppyy/executor.py

View file
         ptr_result = rffi.cast(capi.C_OBJECT, libffifunc.call(argchain, rffi.VOIDP))
         return interp_cppyy.new_instance(space, w_returntype, self.cpptype, ptr_result, False, False)
 
+class InstancePtrPtrExecutor(InstancePtrExecutor):
+    _immutable_ = True
+
+    def execute(self, space, w_returntype, cppmethod, cppthis, num_args, args):
+        from pypy.module.cppyy import interp_cppyy
+        voidp_result = capi.c_call_r(cppmethod, cppthis, num_args, args)
+        ref_address = rffi.cast(rffi.VOIDPP, voidp_result)
+        ptr_result = rffi.cast(capi.C_OBJECT, ref_address[0])
+        return interp_cppyy.new_instance(space, w_returntype, self.cpptype, ptr_result, False, False)
+
+    def execute_libffi(self, space, w_returntype, libffifunc, argchain):
+        from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
+        raise FastCallNotPossible
 
 class InstanceExecutor(InstancePtrExecutor):
     _immutable_ = True
         # type check for the benefit of the annotator
         from pypy.module.cppyy.interp_cppyy import W_CPPType
         cpptype = space.interp_w(W_CPPType, cpptype, can_be_None=False)
-        if compound == "*" or compound == "&":
+        if compound == "":
+            return InstanceExecutor(space, clean_name, cpptype)
+        elif compound == "*" or compound == "&":
             return InstancePtrExecutor(space, clean_name, cpptype)
-        elif compound == "":
-            return InstanceExecutor(space, clean_name, cpptype)
+        elif compound == "**" or compound == "*&":
+            return InstancePtrPtrExecutor(space, clean_name, cpptype)
     elif capi.c_is_enum(clean_name):
         return UnsignedIntExecutor(space, "", None)
 

File pypy/module/cppyy/test/datatypes.cxx

View file
 
     m_pod.m_int    = 888;
     m_pod.m_double = 3.14;
+
+    m_ppod = &m_pod;
 };
 
 cppyy_test_data::~cppyy_test_data()
 double* cppyy_test_data::get_double_array()  { return m_double_array; }
 double* cppyy_test_data::get_double_array2() { return m_double_array2; }
 
+cppyy_test_pod cppyy_test_data::get_pod_val() { return m_pod; }
+cppyy_test_pod* cppyy_test_data::get_pod_ptr() { return &m_pod; }
+cppyy_test_pod& cppyy_test_data::get_pod_ref() { return m_pod; }
+cppyy_test_pod*& cppyy_test_data::get_pod_ptrref() { return m_ppod; }
+
 //- setters -----------------------------------------------------------------
 void cppyy_test_data::set_bool(bool b)              { m_bool   = b; }
 void cppyy_test_data::set_char(char c)              { m_char   = c; }

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

View file
     double* get_double_array();
     double* get_double_array2();
 
+    cppyy_test_pod get_pod_val();
+    cppyy_test_pod* get_pod_ptr();
+    cppyy_test_pod& get_pod_ref();
+    cppyy_test_pod*& get_pod_ptrref();
+
 // setters
     void set_bool(bool b);
     void set_char(char c);
 
 // object types
     cppyy_test_pod m_pod;
+    cppyy_test_pod* m_ppod;
 
 public:
     static char           s_char;

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

View file
         assert c.s_enum == cppyy_test_data.s_enum
         assert c.s_enum == cppyy_test_data.kSomething
         assert cppyy_test_data.s_enum == cppyy_test_data.kSomething
+
+    def test12_object_returns(self):
+        """Test access to and return of PODs"""
+
+        import cppyy
+
+        c = cppyy.gbl.cppyy_test_data()
+
+        assert c.m_pod.m_int == 888
+        assert c.m_pod.m_double == 3.14
+
+        pod = c.get_pod_val()
+        assert pod.m_int == 888
+        assert pod.m_double == 3.14
+
+        assert c.get_pod_ptr().m_int == 888
+        assert c.get_pod_ptr().m_double == 3.14
+        c.get_pod_ptr().m_int = 777
+        assert c.get_pod_ptr().m_int == 777
+
+        assert c.get_pod_ref().m_int == 777
+        assert c.get_pod_ref().m_double == 3.14
+        c.get_pod_ref().m_int = 666
+        assert c.get_pod_ref().m_int == 666
+
+        assert c.get_pod_ptrref().m_int == 666
+        assert c.get_pod_ptrref().m_double == 3.14