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.

classification
Title: buffer comparison emits a RuntimeWarning
Type: Stage:
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: theller Nosy List: theller, tim.peters
Priority: normal Keywords:

Created on 2006-08-08 15:50 by theller, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bufferobject.patch theller, 2006-08-08 15:50
Messages (3)
msg29471 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2006-08-08 15:50
On some systems, the memcmp() function returns values
other than -1, 0, or +1, which gives a warning:

>>> cmp(buffer("abc"), buffer("def"))
__main__:1: RuntimeWarning: tp_compare didn't return
-1, 0 or 1
-1
>>>

The problem occurred on OS X and Windows CE.

Patch and test attached.
msg29472 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2006-08-08 16:52
Logged In: YES 
user_id=31435

Looks good to me, although I'd collapse the new code to just:

    if (cmp != 0)
        return cmp < 0 ? -1 : 1;

Marked Accepted and assigned back to you for checkin (or if
you can't, assign back to me).  Proabably affects 2.4 too.
msg29473 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2006-08-08 17:45
Logged In: YES 
user_id=11105

Thanks.

Committed, with the suggested changes, as r51139/51140 on
the trunk, and r51141 on the release-24maint branch.
History
Date User Action Args
2022-04-11 14:56:19adminsetgithub: 43794
2006-08-08 15:50:49thellercreate