[PySide] Shiboken: Binding a function returning a pointer

Alexandre gauthier alexandre.gauthier-foichat at inria.fr
Fri Oct 24 00:03:39 CEST 2014


I have the following C++ function that is going to be binded to Python:

Effect::getInput(int inputNumber) const
    boost::shared_ptr<Natron::Node> node = _node->getInput(inputNumber);
    return Effect(node);

The return value has a bool isNull() const  method to determine if the object is valid or not.

In the type system I do the following:

<object-type name="Effect">
        <modify-function signature="getInput(int)const">
            <modify-argument index="return">
                <replace-type modified-type="PyObject" />
            <inject-code class="target" position="beginning">
                if (%0.isNull()) {
                    %PYARG_0 = Py_None;
                } else {
                    %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0);

Which is expanded in c++ to :

		// Begin code injection

            Effect cppResult = cppSelf->getInput(cppArg0);
            if (cppResult.isNull()) {
                pyResult = Py_None;
            } else {

		///Crash in the following line
                pyResult = Shiboken::Conversions::copyToPython((SbkObjectType*)SbkNatronEngineTypes[SBK_EFFECT_IDX], &cppResult);

            // End of code injection

Unfortunately the code crashes in the indicated line above when invoking the code from the Python interpreter. Any idea on what I’m doing wrong ?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20141024/a300ec85/attachment.html>

More information about the PySide mailing list