[Python-Dev] GC and ExtensionClass

Guido van Rossum guido@digicool.com
Sat, 12 May 2001 16:08:05 -0500


> At some point, extension classes used a literal copy of
> PyTypeObject. Unfortunately, that copy was made with Python 1.4 or so,
> and only had the spare fields that were expected then. Today,
> PyTypeObject has much more fields, so extension objects produce random
> errors (eg. with GC) when used in a modern interpreter (where the copy
> has not been synchronized). Whatever immediately follows the type
> object in memory may be interpreted as GC flag.

Not quite true.  ExtensionClasses (at least recent versions that
worked with 1.5.2) contain a copy of the type object up to and
including the tp_flags field, and the 2.1 code is careful not to use
any newer fields without first checking the corresponding flag bit.

Now, if you are using the 1.4 version of ExtensionClasses you might
not have the tp_flags field either (I don't know, I can't easily
check) but the 1.5.2-compatible version of ExtensionClasses doesn't
even require recompilation to work with Python 2.1.

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