Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

couple of new list.sort bugs #39596

Closed
mwhudson opened this issue Nov 25, 2003 · 9 comments
Closed

couple of new list.sort bugs #39596

mwhudson opened this issue Nov 25, 2003 · 9 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@mwhudson
Copy link

BPO 848856
Nosy @mwhudson, @rhettinger
Files
  • list-nagery.diff: fix attempt Support "bpo-" in Misc/NEWS #1
  • list-nagery-2.diff: fix attempt Rename README to README.rst and enhance formatting #2
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/mwhudson'
    closed_at = <Date 2003-12-04.11:26:39.000>
    created_at = <Date 2003-11-25.11:12:33.000>
    labels = ['interpreter-core']
    title = 'couple of new list.sort bugs'
    updated_at = <Date 2003-12-04.11:26:39.000>
    user = 'https://github.com/mwhudson'

    bugs.python.org fields:

    activity = <Date 2003-12-04.11:26:39.000>
    actor = 'mwh'
    assignee = 'mwh'
    closed = True
    closed_date = None
    closer = None
    components = ['Interpreter Core']
    creation = <Date 2003-11-25.11:12:33.000>
    creator = 'mwh'
    dependencies = []
    files = ['1113', '1114']
    hgrepos = []
    issue_num = 848856
    keywords = []
    message_count = 9.0
    messages = ['19115', '19116', '19117', '19118', '19119', '19120', '19121', '19122', '19123']
    nosy_count = 2.0
    nosy_names = ['mwh', 'rhettinger']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue848856'
    versions = ['Python 2.4']

    @mwhudson
    Copy link
    Author

    I really feel I should apologise for this one:

    [mwh@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@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@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@pc150 build-debug]$ ./python u.py
    [<sortwrapper object at 0x40130410>, <sortwrapper
    object at 0x401303c0>, 0, 1]
    [6571 refs]

    @mwhudson mwhudson self-assigned this Nov 25, 2003
    @mwhudson mwhudson added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Nov 25, 2003
    @rhettinger
    Copy link
    Contributor

    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.

    @mwhudson
    Copy link
    Author

    mwhudson commented Dec 1, 2003

    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.

    @mwhudson
    Copy link
    Author

    mwhudson commented Dec 1, 2003

    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).

    @mwhudson
    Copy link
    Author

    mwhudson commented Dec 1, 2003

    Logged In: YES
    user_id=6656

    Boy is this stuff hard to get right!

    See what you think of the attached patch.

    @rhettinger
    Copy link
    Contributor

    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?

    @mwhudson
    Copy link
    Author

    mwhudson commented Dec 2, 2003

    Logged In: YES
    user_id=6656

    On the code path leading to a dsu_fail, does
    PyMem_FREE() ever get called?

    Good catch. New patch attached.

    Would there be some added protection value to INCREFing self
    at the beginning and DECREFing it at the end?

    Um, I don't think so, as the calling machinery holds a
    reference to self (and all the other arguments) during the
    call. Or did you mean something else?

    @rhettinger
    Copy link
    Contributor

    Logged In: YES
    user_id=80475

    Looks good.
    Please add your crashers to the test suite and check it all in.

    @mwhudson
    Copy link
    Author

    mwhudson commented Dec 4, 2003

    Logged In: YES
    user_id=6656

    OK, checked in as:

    Objects/listobject.c revision 2.167
    Lib/test/test_sort.py revision 1.9

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants