Author: Wim Lavrijsen <wlavrij...@lbl.gov> Branch: reflex-support Changeset: r53278:58ff96db778c Date: 2012-03-08 16:50 -0800 http://bitbucket.org/pypy/pypy/changeset/58ff96db778c/
Log: ptr-ptr and ptr-ref return types as ptr returns diff --git a/pypy/module/cppyy/executor.py b/pypy/module/cppyy/executor.py --- a/pypy/module/cppyy/executor.py +++ b/pypy/module/cppyy/executor.py @@ -255,6 +255,19 @@ 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 @@ -324,10 +337,12 @@ # 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) diff --git a/pypy/module/cppyy/test/datatypes.cxx b/pypy/module/cppyy/test/datatypes.cxx --- a/pypy/module/cppyy/test/datatypes.cxx +++ b/pypy/module/cppyy/test/datatypes.cxx @@ -51,6 +51,8 @@ m_pod.m_int = 888; m_pod.m_double = 3.14; + + m_ppod = &m_pod; }; cppyy_test_data::~cppyy_test_data() @@ -106,6 +108,11 @@ 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; } diff --git a/pypy/module/cppyy/test/datatypes.h b/pypy/module/cppyy/test/datatypes.h --- a/pypy/module/cppyy/test/datatypes.h +++ b/pypy/module/cppyy/test/datatypes.h @@ -52,6 +52,11 @@ 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); @@ -102,6 +107,7 @@ // object types cppyy_test_pod m_pod; + cppyy_test_pod* m_ppod; public: static char s_char; diff --git a/pypy/module/cppyy/test/test_datatypes.py b/pypy/module/cppyy/test/test_datatypes.py --- a/pypy/module/cppyy/test/test_datatypes.py +++ b/pypy/module/cppyy/test/test_datatypes.py @@ -416,3 +416,30 @@ 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 _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit