I'm using PyBind11 to run a Python interpreter, and I need to call a Python function in c++ with some pointer arguments.
According to the docs of pybind11, it looks like that a argument being passed to Python side should be freed normally by the Python interpreter, instead of the c++ main program. But this time the argument is a pointer to a static object, it should NOT be freed by anyone. How to code such a binding/calling?
I know that pybind11::return_value_policy::reference can be used to prevent a returning result from being freed, but it is for a returning object, not for arguments.
Any hint will be appreciated!
You can define a python wrapper inside an embedded module and access it from inside the python code. Then you can specify an appropriate return value policy when defining the getter, like this:
Then either call the
statics.global_object()directly from the python code, or, if you still want to use pass it as an argument from C++, call thestatics.global_object()in the interpreter and store the result in C++ as apy::objectwhich you can then pass as an argument.