[PyKDE] Modify init/dealloc on structs

Phil Thompson phil at riverbankcomputing.co.uk
Wed Jul 12 15:42:00 BST 2006


On Wednesday 12 July 2006 2:29 pm, Daniele Varrazzo wrote:
> Hello,
>
> i need to wrap C structures that require some initialization (they
> must be memsetted to 0) and careful freeing if C-owned (to free
> aggregate structures as well).
>
> Can %MethodCode be used to customize dealloc_ABC and init_ABC code for
> a wrapped ABC struct? How?
>
> Alternatively i could provide a /Factory/ function to correctly
> initialize an ABC instance, but then i'd like to hide ABC from he
> module interface and only expose createABC() to avoid the creation of
> uninitialized structures. Furthermore troubles remain on destruction
> (expose a destryABC?)
>
> What is the best approach to tackle this kind problem with SIP?

It's not very well documented but SIP allows you to specify constructors and 
non-virtual destructors for C structs. Both allow %MethodCode.

Phil




More information about the PyQt mailing list