This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author zhalas
Recipients zhalas
Date 2013-04-01.12:49:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1364820542.51.0.192116883803.issue17610@psf.upfronthosting.co.za>
In-reply-to
Content
Comparison function slotdef_cmp in  Objects/typeobject.c is based on the assumption that qsort may be stabilised by taking memory addresses of compared objects into consideration. This assumption is not guaranteed by the C standard and may not always be true, like for example in the case of qsort implemented as a typical quicksort.
Sometimes it may be even more harmful, as some implementations may be unhappy about comparison function changing its value just because an element was moved to another memory location (I discovered this problem while porting Python to HelenOS, where this comparison function caused qsort to enter infinite recursion).

The actual function:

/* Comparison function for qsort() to compare slotdefs by their offset, and
   for equal offset by their address (to force a stable sort). */
static int
slotdef_cmp(const void *aa, const void *bb)
{
    const slotdef *a = (const slotdef *)aa, *b = (const slotdef *)bb;
    int c = a->offset - b->offset;
    if (c != 0)
        return c;
    else
        /* Cannot use a-b, as this gives off_t,
           which may lose precision when converted to int. */
        return (a > b) ? 1 : (a < b) ? -1 : 0;
}
History
Date User Action Args
2013-04-01 12:49:02zhalassetrecipients: + zhalas
2013-04-01 12:49:02zhalassetmessageid: <1364820542.51.0.192116883803.issue17610@psf.upfronthosting.co.za>
2013-04-01 12:49:02zhalaslinkissue17610 messages
2013-04-01 12:49:01zhalascreate