[Python-3000] A better way to initialize PyTypeObject

Guido van Rossum guido at python.org
Tue Nov 28 22:09:03 CET 2006


On 11/28/06, Talin <talin at acm.org> wrote:
> 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))

I think this would cause too many issues with backwards compatibility.

I like the idea much better to use special names (e.g. starting with a ".").

> 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.

I think the interpretation will be fast enough (or else what you said
about premature optimization earlier wouldn't be correct. :-)

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list