RosettaCommons/binder

Method parameter reference to primitive type not working

adrianalin opened this issue · 1 comments

Method parameter reference for example int& is not working, the value is unchanged after method returns.
I changed the binder/examples/example_struct/include/test_struct/test_struct.hpp and added a new method:

struct test_my_struct
{...
	void increment_ref(int& val) { val++; }
...
};

in python:

>>> import test_struct
>>> tms=test_struct.testers.test_my_struct()
>>> val=1
>>> tms.increment_ref(val)
>>> val
1
>>>

Do I need to add something to config?

lyskov commented

Well, Python primitive types are not "boxed" so this behavior is expected. I do not think there is a way to make this work without changing underlying C++ function type signature. Note that this is not a limitation of Binder or Pybind11 but rather result of how Python is handling primitive types (ints, floats, strings etc)