[Python-bugs-list] [ python-Bugs-751998 ] Object destruction is broken for slots

SourceForge.net noreply@sourceforge.net
Tue, 10 Jun 2003 11:19:21 -0700


Bugs item #751998, was opened at 2003-06-10 10:55
Message generated for change (Comment added) made by jacobs99
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=751998&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 6
Submitted By: Kevin Jacobs (jacobs99)
Assigned to: Guido van Rossum (gvanrossum)
Summary: Object destruction is broken for slots

Initial Comment:
The following code worked without errors in
Python 2.3b1, but seems to be broken in
the current Python 2.3 CVS:

class Foo(object):
  __slots__ = ('bar','__dict__')

  def __init__(self):
    self.bar = 1
    self.baz = 2

  def __del__(self):
    print 'In __del__.'
    print '  baz =',self.baz
    print '  bar =',self.bar

foo=Foo()

Python 2.3b1: No error, output:
  In __del__.
    baz = 2
    bar = 1

However, the current CVS outputs:
  In __del__.
    baz = 2
    Exception exceptions.AttributeError: 'bar' in 
    <bound method Foo.__del__ of 
    <__main__.Foo object at 0x403ace6c>> ignored

Somehow, descriptor lookup seems to be failing
in objects that are in the process of being deleted,
since commenting out the __slots__ declaration 
makes the problem go away.

I wish I had time to look into this, but I'm currently 
swamped.  Hopefully this is the result of something
recent and this report will trigger some light-bulbs.
If not, I'll see if I can make time next week.  As it
stands, I see this as a serious bug, since it prevents
finalization from completing on these objects.


----------------------------------------------------------------------

>Comment By: Kevin Jacobs (jacobs99)
Date: 2003-06-10 13:19

Message:
Logged In: YES 
user_id=459565

Okay, I had a few minutes free.  The problem is that
slots are being deallocated too early -- before tp_dealloc.
I'm attaching a patch that corrects this at the expense of
having to travel up the path of base class tp_dealloc
entries twice.  Here is the new sequence of actions:

1) Find the nearest base with a different tp_dealloc
2) Clear weakrefs
3) Call finalizer
4) Check to see if object was resurrected, if so stop
5) Clear all slots up to nearest base with a different 
    tp_dealloc
6) DECREF dict pointer, if necessary
7) proceed as usual... (call basedealloc, DECREF type, etc.)

Without my patch, step number 5  is done as part of step
1, and bad things happen.


----------------------------------------------------------------------

Comment By: Kevin Jacobs (jacobs99)
Date: 2003-06-10 12:07

Message:
Logged In: YES 
user_id=459565

The fix checked in to solve Bug 751998 is the cause of this
potentially more serious one bug.  I have yet to figure 
out why, though I have isolated the problem to revision
2.234 of typeobject.c.  I've not looked to see if this also 
affects Python 2.2.3, though I wouldn't be too suprised if it 
does.

More soon, hopefully.  Maybe...


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=751998&group_id=5470