Using alternative PyObject* in dynamically created classes

Jacek Generowicz jacek.generowicz at cern.ch
Tue Nov 23 08:07:01 EST 2004


Jacek Generowicz <jacek.generowicz at cern.ch> writes:

> I would like some of my _dynamically_ created new-style classes to
> have instances which are not represented by the standard PyObject, but
> one which has an extra void* slot which I want to use for my nefarious
> purposes, in extension functions. The pointer need not be initialized
> (for now) I just want it to be there in case I want to stuff something
> in there later on in the run.
> 
> What is the laziest way of achieving this?
> 
> As far as I can tell, PyTypeObject (and its allocators, deallocators,
> methods in general) only refer to the type of the instance struct via
> tp_basicsize (where only the struct's size is held). 
> 
> So my first attempt merely resets tp_basicsize to the size of my
> alternative instance struct, as soon as the class is created. This
> goes horribly wrong when instances of the class are deallocated, but I
> can't see why.
> 
> Where else must I provide information about the instance struct type ?
> 
> 
> [I will be away for a few days, from a few hours from now; please
> don't take a long response time as a sign of rudeness.]


Hmm ... no takers ?

:-(




More information about the Python-list mailing list