[Python-Dev] Re: [Python-checkins]python/dist/src/Modules gcmodule.c,2.33.6.5,2.33.6.6

Tim Peters tim.one@comcast.net
Wed, 09 Apr 2003 22:29:21 -0400


[Greg Ewing]
>> Failing that, perhaps they should be made a bit less dynamic, so that
>> the GC can make reasonable assumptions about their existence without
>> having to execute Python code.

[Tim]
> Guido already did so for new-style classes in Python 2.3.  That machinery
> doesn't exist in 2.2.2, and old-style classes remain a problem under 2.3
> too.  Backward compatibility constrains how much we can get away with, of
> course.

FYI, those who study the checkin comments know how this ended.  It ended
well!  gc no longer does anything except string-keyed dict lookups when
determining whether a finalizer exists, for old- & new- style classes, and
in 2.3 CVS & the 2.2 maintenance branch.

The only incompatibilities appear to be genuine bug fixes.  The hasattr()
method was actually incorrect in two mondo obscure cases (one where hasattr
said "yes, __del__ exists" when a finalizer couldn't actually be run, and
the other where hasattr said "no, __del__ doesn't exist" when arbitrary
Python code actually could be invoked by destructing an object).  A new
private API function _PyInstance_Lookup was added in 2.2 and 2.3, which does
for old-style class instances what _PyType_Lookup does for new-style classes
(determines whether an attribute exists via pure C string-keyed dict
lookups).