<div dir="ltr">Hi,<div><br></div><div>The reproducing code for this issue involves several files, so I've created a gist:</div><div><br></div><div><a href="https://gist.github.com/ArthurGW/a3e906e2d1247adc140f988d06c883f3">https://gist.github.com/ArthurGW/a3e906e2d1247adc140f988d06c883f3</a></div><div><br></div><div>It seems like between SIP 6.0.3 and SIP 6.1.0 (and up to the current version) the /Transfer/ annotation is no longer working for function (i.e. not method) arguments. Previously if I had a structure something like this:</div><div><br></div><div> %Module(name=test_transfer)</div><div><br></div><div> class Test {};<br><br> void test_install(Test *obj /Transfer/);<br></div><div><br></div><div>
with the wrapped C++ function `test_install` assigning the `Test` object `obj` to a `std::unique_ptr` that is not cleared while the program is running, and I called this from python as:</div><div><br></div><div> import test_transfer</div> test_transfer.test_install(test_transfer.Test())<div><br></div><div>then the associated C++ and Python `Test` objects were kept alive. However, since SIP 6.1, the destructor on the `Test` object is called immediately when `test_install` finishes, so the `std::unique_ptr` ends up pointing to freed memory.</div><div><br></div><div>There are two fixes I can do for this myself: either make `test_install` a method on a `Holder` object (see files named "METHOD..." in the gist), or write the transfer code myself (WORKING.sip) as:</div><div><br></div><div> void test_install(PyObject *obj /TypeHintIn = "Test"/);<br> %MethodCode<br><br> Test *tobj{reinterpret_cast<Test*>(sipConvertToType(a0, sipType_Test, NULL, SIP_NOT_NONE, 0, &sipIsErr))};<br> sipTransferTo(a0, Py_None);<br><br> test_install(tobj);<br> %End<br></div><div><br></div><div>It feels like this second fix is how that annotation is supposed to work, so I shouldn't need to do this?</div><div><br></div><div>(Setup: python 3.8.8, on windows.)</div><div><br></div><div>Cheers,</div><div>Arthur</div></div>