sizeof PyTypeObject difference

Martin v. Löwis loewis at informatik.hu-berlin.de
Mon Sep 30 04:34:47 EDT 2002


"Tom Widrick" <lordmacro at hotmail.com> writes:

> Well, aren't instances of a metatype types?  I know this statement was
> probably made from invalid assumptions, but just as a point.
> Since types are variable sized, as you say, how does this tie in with
> tp_basicsize and metatypes?

The instances of the type type are types, yes. If you have your own
metatype, it is your decision to determine what instances of it are.

The snippet you posted looks consistent, so the error must lie
elsewhere.

As for variable-sized objects: the instances of the type type are
variable-sized; if you create your own metatype, it is your decision
what the layout of them is. Of course, if you use functions of the
type type to implement your meta-type, you have to follow the
conventions of the type type, which are undocumented, and may be
unaccessible to external code.

> > That is hard to believe. Declaring the typedef alone can't cause a
> > core dump. Defining an object of that type, and putting the value of
> > 196 into it can't cause a core dump, either. You must be doing other
> > things, like using the resulting object in some way, to cause a core
> > dump.
> 
> Trying to use the metatype as a metaclass for a python class.

That's still not precise enough: Did you merely use the type as the
__metaclass__ attribute, or did you also try to create instances of
the resulting type?

> As an aside, are there any other quarks about making metatypes in C? the
> xxsubtype.c example in the distrib is helpful, along with the PEPs, but I'm
> yet to find a good example of a metatype implemented in C (besides the 2
> builtin metatypes, but I don't think those serve as  great minimalistic
> examples).

xxsubtype demonstrate how to subtype a type in C. Creating metatypes
in C is not really supported; you need to study the source code, and
may find that the things you want to do cannot be done without
changing typeobject.c.

In any case, I recommend to contact Christian Tismer.

Regards,
Martin



More information about the Python-list mailing list