[Python-3000] A better way to initialize PyTypeObject

Talin talin at acm.org
Tue Nov 28 19:54:33 CET 2006


Guido van Rossum wrote:
> Some comments:
> 
> - Fredrik's solution makes one call per registered method. (I don't
> know if the patch he refers to follows that model.) That seems a fair
> amount of code for an average type -- I'm wondering if it's too early
> to worry about code bloat (I don't think the speed is going to
> matter).

One other thought: The special constants could themselves be nothing 
more than the offset into the PyTypeObject struct, i.e.:

    #define SPECMETHOD_NEW ((const char*)offsetof(PyTypeObject,tp_new))

In the PyType_Ready code, you would see if the method name had a value 
of less than sizeof(PyTypeObject); If so, then it's a special method 
name, and you fill in the struct at the specified offset.

So the interpretation of the table could be very simple and fast. It has 
a slight disadvantage from the approach of using actual string names for 
special methods, in that it doesn't allow the VM to silently 
promote/demote methods to 'special' status.

-- Talin


More information about the Python-3000 mailing list