[Python-Dev] flextype.c -- extended type system
Mon, 16 Sep 2002 21:24:54 +0200
From: "David Abrahams" <firstname.lastname@example.org>
> All of my (dynamically-generated) extension classes need a piece of data
> which tells them how much extra data to allocate in the variable-sized area
> of their instances. This is an implementation detail which I don't want to
Not so different from what I need...
> expose to users. Right now I have to stick it in the class' __dict__, which
> not only means that it's exposed, but that users can change it at will. It
> also costs me an extra lookup every time an instance of the extension class
> is allocated. It would be much nicer if I could get a little data area in
> the type object where I could stick this value, but right now there's no
> place to put it.
You can (but you probably know this already) replace the type's tp_dict
by a custom subclass of PyDict_Object, which adds additional fields.
> Chris' patch allows me to handle the issue much more naturally. It doesn't
> seem esoteric to add information to a type which doesn't live it its
> __dict__. Not being able to do so makes types very different from other
Actually this is not specific to types - it is for all variable size