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

qsort doesn't work for double arrays #61138

Closed
stephanepoirier mannequin opened this issue Jan 11, 2013 · 3 comments
Closed

qsort doesn't work for double arrays #61138

stephanepoirier mannequin opened this issue Jan 11, 2013 · 3 comments
Labels
topic-ctypes type-bug An unexpected behavior, bug, or error

Comments

@stephanepoirier
Copy link
Mannequin

stephanepoirier mannequin commented Jan 11, 2013

BPO 16934
Nosy @amauryfa, @mdickinson, @abalkin, @meadori
Files
  • testQSort33.py
  • 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 = None
    closed_at = <Date 2013-01-11.14:57:43.131>
    created_at = <Date 2013-01-11.14:13:56.837>
    labels = ['ctypes', 'type-bug', 'invalid']
    title = "qsort doesn't work for double arrays"
    updated_at = <Date 2013-01-11.14:57:43.127>
    user = 'https://bugs.python.org/stephanepoirier'

    bugs.python.org fields:

    activity = <Date 2013-01-11.14:57:43.127>
    actor = 'mark.dickinson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2013-01-11.14:57:43.131>
    closer = 'mark.dickinson'
    components = ['ctypes']
    creation = <Date 2013-01-11.14:13:56.837>
    creator = 'stephane.poirier'
    dependencies = []
    files = ['28696']
    hgrepos = []
    issue_num = 16934
    keywords = []
    message_count = 3.0
    messages = ['179680', '179683', '179685']
    nosy_count = 5.0
    nosy_names = ['amaury.forgeotdarc', 'mark.dickinson', 'belopolsky', 'meador.inge', 'stephane.poirier']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue16934'
    versions = ['Python 2.6', 'Python 2.7', 'Python 3.3']

    @stephanepoirier
    Copy link
    Mannequin Author

    stephanepoirier mannequin commented Jan 11, 2013

    qsort doesn't sort arrays that are defined with double elements.
    You can find attached a script that shows this function working well for int (as described in the ctypes documentation). If int array is replaced by double array qsort doesn't sort any more.
    Even worse, with python 2.6, the difference between a[0] and b[0] may be nan.
    The script can be launch by
    python.exe testQSort33.py

    @stephanepoirier stephanepoirier mannequin added topic-ctypes type-bug An unexpected behavior, bug, or error labels Jan 11, 2013
    @mdickinson
    Copy link
    Member

    What happens if you replace the line:

        CMPFUNC = CFUNCTYPE(c_double, POINTER(c_double), POINTER(c_double))

    in your example code with

        CMPFUNC = CFUNCTYPE(c_int, POINTER(c_double), POINTER(c_double))

    ?

    @mdickinson
    Copy link
    Member

    Closing as invalid: the issue is not in Python but with the CMPFUNC line. Your py_cmp_func should return an integer rather than a float to be compatible with libc.qsort.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-ctypes type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant