[Python-bugs-list] [ python-Bugs-751998 ] Object destruction is broken for slots
SourceForge.net
noreply@sourceforge.net
Mon, 16 Jun 2003 16:38:41 -0700
Bugs item #751998, was opened at 2003-06-10 11:55
Message generated for change (Comment added) made by nnorwitz
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.2.3
>Status: Closed
Resolution: Fixed
Priority: 6
Submitted By: Kevin Jacobs (jacobs99)
Assigned to: Neal Norwitz (nnorwitz)
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: Neal Norwitz (nnorwitz)
Date: 2003-06-16 19:38
Message:
Logged In: YES
user_id=33168
Checked in a test too:
* Lib/test/test_descr.py 1.194, 1.113.4.34
* Objects/typeobject.c 2.126.4.39
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2003-06-13 16:57
Message:
Logged In: YES
user_id=6380
Sorry, the checkin barfed and I didn't notice. Try again now.
----------------------------------------------------------------------
Comment By: Neal Norwitz (nnorwitz)
Date: 2003-06-13 16:41
Message:
Logged In: YES
user_id=33168
Hmm, did you check anything in? The report says it's broken
in CVS, but works in 2.3b1. It is still broken for me
without the patch. Did you want me to test the patch and
then backport?
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2003-06-13 15:42
Message:
Logged In: YES
user_id=6380
Thanks! Fixed in CVS for 2.3. This should be backported to
2.2 too; assiged to Neal Norwitz for that purpose.
----------------------------------------------------------------------
Comment By: Kevin Jacobs (jacobs99)
Date: 2003-06-10 14:24
Message:
Logged In: YES
user_id=459565
er, see Bug 742911 instead.
----------------------------------------------------------------------
Comment By: Kevin Jacobs (jacobs99)
Date: 2003-06-10 14:21
Message:
Logged In: YES
user_id=459565
Oh, and with the patch, 'make test' completes without
any new errors, my attached test case works, as does
the minimal test case associated with Bug 751998.
----------------------------------------------------------------------
Comment By: Kevin Jacobs (jacobs99)
Date: 2003-06-10 14: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 13: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