[Python-Dev] Extending types in C (original) (raw)

[Python-Dev] Extending types in C - help needed

Thomas Heller thomas.heller@ion-tof.com
Wed, 6 Feb 2002 21:53:08 +0100


I have thought about this a little more and come to the conclusion that you cannot define a metaclass that creates type objects that have more C slots than the standard type object lay-out. It would be the same as trying to add a C slot to the instances of a string subtype: there's variable-length data at the end, and you cannot place anything before that variable-length data because all the C code that works with the base type knows where the variable length data start; you cannot place anything after that variable-lenth data because there's no way to address it from C.

It's a pity, isn't it?

A better solution is to store additional information in the dict.

You loose nice features: access these (new) slots from Python by providing tp_members entries for them (for example).

Are you planning to address this issue in the future?

Thanks,

Thomas