diff --git a/examples/foomodulegen.py b/examples/foomodulegen.py index 466defb..bfcfaa5 100755 --- a/examples/foomodulegen.py +++ b/examples/foomodulegen.py @@ -139,7 +139,8 @@ def my_module_gen(out_file): SomeObject.add_method(CppMethod( ReturnValue.new('std::string'), 'get_prefix_with_foo_ref', - [Parameter.new('Foo&', 'foo', is_const=True)], + [Parameter.new('Foo&', 'foo', is_const=True, + direction=Parameter.DIRECTION_INOUT)], is_virtual=True, is_const=True)) #SomeObject.add_method(CppMethod( diff --git a/pybindgen/cppclass.py b/pybindgen/cppclass.py index a635e4c..2be21d4 100644 --- a/pybindgen/cppclass.py +++ b/pybindgen/cppclass.py @@ -915,8 +915,12 @@ class CppClassRefParameter(CppClassParameterBase): ## the ->obj pointer after the python call; this is so ## that the python code directly manipulates the object ## received as parameter, instead of a copy. + if self.is_const: + value = "const_cast<%s*>(&(%s))" % (self.cpp_class.full_name, self.value) + else: + value = "&(%s)" % self.value wrapper.before_call.write_code( - "%s->obj = &(%s);" % (self.py_name, self.value)) + "%s->obj = %s;" % (self.py_name, value)) wrapper.build_params.add_parameter("O", [self.py_name]) wrapper.before_call.add_cleanup_code("Py_DECREF(%s);" % self.py_name)