[ python-Bugs-848856 ] couple of new list.sort bugs
SourceForge.net
noreply at sourceforge.net
Tue Dec 2 01:52:09 EST 2003
Bugs item #848856, was opened at 2003-11-25 06:12
Message generated for change (Comment added) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=848856&group_id=5470
Category: Python Interpreter Core
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Michael Hudson (mwh)
Assigned to: Raymond Hettinger (rhettinger)
Summary: couple of new list.sort bugs
Initial Comment:
I really feel I should apologise for this one:
[mwh at pc150 build-debug]$ cat t.py
class SortKiller(object):
def __init__(self, i):
pass
def __del__(self):
del l[:]
l = range(10)
l.sort(key=SortKiller)
[mwh at pc150 build-debug]$ ./python t.py
Segmentation fault
This can be fixed by moving the "restoring the objects
of the list from the wrappers" code *before* the "put
saved_ob_item back in the list" code.
The second is less serious but probably more annoying
to fix:
[mwh at pc150 build-debug]$ cat u.py
def k(x): return 1/x
l = range(-2,2)
try:
l.sort(key=k)
except ZeroDivisionError:
pass
print l
[mwh at pc150 build-debug]$ ./python u.py
[<sortwrapper object at 0x40130410>, <sortwrapper
object at 0x401303c0>, 0, 1]
[6571 refs]
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2003-12-02 01:52
Message:
Logged In: YES
user_id=80475
On the code path leading to a dsu_fail, does PyMem_FREE()
ever get called?
Would there be some added protection value to INCREFing self
at the beginning and DECREFing it at the end?
----------------------------------------------------------------------
Comment By: Michael Hudson (mwh)
Date: 2003-12-01 13:36
Message:
Logged In: YES
user_id=6656
Boy is this stuff hard to get right!
See what you think of the attached patch.
----------------------------------------------------------------------
Comment By: Michael Hudson (mwh)
Date: 2003-12-01 12:38
Message:
Logged In: YES
user_id=6656
Here's a much less devious test case:
$ cat w.py
def k(x):
del l[:]
return x
l = range(10)
l.sort(key=k)
$ ./python w.py
Segmentation fault
i think doing the "hide ob_item" swizzle should be just
about the first thing list_sort does and undoing it should
be about the last. Patch soon (I hope).
----------------------------------------------------------------------
Comment By: Michael Hudson (mwh)
Date: 2003-12-01 07:37
Message:
Logged In: YES
user_id=6656
I have a feeling that your fix for problem #2 has made
problem #1 harder to fix...
will have a look later, no time right now.
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2003-11-28 20:56
Message:
Logged In: YES
user_id=80475
The second was easy to fix.
The first is defying my attempts to fix it. You're welcome
to take a crack at it.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=848856&group_id=5470
More information about the Python-bugs-list
mailing list