[Python-checkins] r51141 - in python/branches/release24-maint: Lib/test/test_types.py Misc/NEWS Objects/bufferobject.c

thomas.heller python-checkins at python.org
Tue Aug 8 19:42:32 CEST 2006


Author: thomas.heller
Date: Tue Aug  8 19:42:30 2006
New Revision: 51141

Modified:
   python/branches/release24-maint/Lib/test/test_types.py
   python/branches/release24-maint/Misc/NEWS
   python/branches/release24-maint/Objects/bufferobject.c
Log:
memcmp() can return values other than -1, 0, and +1 but tp_compare
must not.

Modified: python/branches/release24-maint/Lib/test/test_types.py
==============================================================================
--- python/branches/release24-maint/Lib/test/test_types.py	(original)
+++ python/branches/release24-maint/Lib/test/test_types.py	Tue Aug  8 19:42:30 2006
@@ -229,6 +229,7 @@
 try: buffer('asdf', -1)
 except ValueError: pass
 else: raise TestFailed, "buffer('asdf', -1) should raise ValueError"
+cmp(buffer("abc"), buffer("def")) # used to raise a warning: tp_compare didn't return -1, 0, or 1
 
 try: buffer(None)
 except TypeError: pass

Modified: python/branches/release24-maint/Misc/NEWS
==============================================================================
--- python/branches/release24-maint/Misc/NEWS	(original)
+++ python/branches/release24-maint/Misc/NEWS	Tue Aug  8 19:42:30 2006
@@ -12,6 +12,8 @@
 Core and builtins
 -----------------
 
+- Bug #1536786: buffer comparison could emit a RuntimeWarning.
+
 - Bug #1535165: fixed a segfault in input() and raw_input() when
   sys.stdin is closed.
 

Modified: python/branches/release24-maint/Objects/bufferobject.c
==============================================================================
--- python/branches/release24-maint/Objects/bufferobject.c	(original)
+++ python/branches/release24-maint/Objects/bufferobject.c	Tue Aug  8 19:42:30 2006
@@ -230,7 +230,7 @@
 	if (min_len > 0) {
 		cmp = memcmp(p1, p2, min_len);
 		if (cmp != 0)
-			return cmp;
+			return cmp < 0 ? -1 : 1;
 	}
 	return (len_self < len_other) ? -1 : (len_self > len_other) ? 1 : 0;
 }


More information about the Python-checkins mailing list