RosettaCommons / binder

Binder, tool for automatic generation of Python bindings
MIT License
321 stars 66 forks source link

Method parameter reference to primitive type not working #262

Closed adrianalin closed 1 year ago

adrianalin commented 1 year ago

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 1 year ago

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)