[C++-sig] Reference to pointer from C++ to Python
Christiano Scarpati Alvarenga
christiano.sa at outlook.com
Sun Oct 18 03:36:28 EDT 2020
Hello, I have a function that expects as argument a boost::python::object and such function can be
used by python world.
The function works like this:
bool function(boost::python::object &object)
{
// ...
XPTO * & x = boost::python::extract<XPTO * & >(object);
// ...
x = nullptr;
}
That is, the argument used in the python world will be a None after calling this function.
Ok, that is working when I call from python.
But the project has a lot of tests (using GTest) and the test verifying
nullptr after calling this function is failing and happens fullly in C++ world.
I am trying to do this:
XPTO* x;
// ...
boost::python::reference_existing_object::apply<XPTO * &>::type converter;
boost::python::object object(boost::python::handle(converter(x)));
XPTO * & y = boost::python::extract<XPTO * & >(object);
I can see in debugger:
x == y
The problem is:
&x != &y when they should be equal in order to the function to be able to change the pointer to
nullptr doing y = nullptr.
I am trying this for hours; I really appreciate any suggestion or help. Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/cplusplus-sig/attachments/20201018/b4121e8e/attachment.html>
More information about the Cplusplus-sig
mailing list