Re: [PATCH spice-gtk] main: use stable comparison function for monitors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 02/28/2013 05:50 PM, Christophe Fergeau wrote:
On Thu, Feb 28, 2013 at 10:14:46AM +0100, Hans de Goede wrote:
On 02/20/2013 06:09 PM, Hans de Goede wrote:
On 02/20/2013 11:35 AM, Marc-André Lureau wrote:
I think that should be: "(char*)p2 - (char*)p1" So that if the
address of p2 is bigger they compare as p2 > p1, and qsort will
keep the order of the array the same for monitors with identical
coordinates.

After further discussion, it turns out I'm wrong. So ACK for the patch
as is.

Having a summary of why this is right or wrong would be helful to have in
the list archive if anyone (even you or Marc-Andre) wonder why this was
done this way in a few months from now ;)

Ok, the summary is that on very slowly and carefully reading the qsort manpage
Marc-André and I agreed the original code was doing the right thing. We
specifically focussed on this bit of the manpage:

"The comparison function must return an integer less than, equal to,  or
greater  than  zero  if  the first argument is considered to be respec‐
tively less than, equal to, or greater than the second.  If two members
compare as equal, their order in the sorted array is undefined."

I also took a long look at the strcmp function which can be used as a
drop in sort function for qsort and has similar behavior.

Regards,

Hans
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]