[PyQt] SIP newbie question, adding a destructor to a C struct

Riccardo Vianello riccardo.vianello at gmail.com
Thu Oct 21 21:36:09 BST 2010


Hi all,

I'm trying to wrap a C structure that requires some
initialization/disposal code. As far as I could understand, I should
provide the wrapper definition with the "C++" prototypes for a
constructor/destructor pair and associate each of them with the
required code in a %MethodCode directive. This seems to work as I
expected for the constructor, but I couldn't find the destructor's
code anywhere in the generated code.. I might be missing something
obvious, but after spending some time on this without success, I would
be grateful if anyone could provide a hint. The specification file I'm
using is similar to the one I copied here below.

Thanks in advance,
Riccardo


%CModule ctor_dtor 0

struct CStruct {

%TypeHeaderCode
    #include <stdio.h>
    struct CStruct {/*...*/};
    void cstruct_initialization( struct CStruct * cs )
    {
        printf("cstruct_initialization\n");
    }
    void cstruct_disposal( struct CStruct * cs )
    {
        printf("cstruct_disposal\n");
    }
%End

    CStruct();
%MethodCode
    sipCpp = sipMalloc(sizeof (struct CStruct));
    cstruct_initialization(sipCpp);
%End

    ~CStruct();
%MethodCode
    cstruct_disposal(sipCpp);
%End

};


More information about the PyQt mailing list