[pypy-svn] rev 2520 - pypy/trunk/src/pypy/objspace/std
pmaupin at codespeak.net
pmaupin at codespeak.net
Thu Dec 18 16:59:00 CET 2003
Author: pmaupin
Date: Thu Dec 18 16:58:59 2003
New Revision: 2520
Modified:
pypy/trunk/src/pypy/objspace/std/listobject.py
Log:
Check that comparison function returns int
Modified: pypy/trunk/src/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/listobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/listobject.py Thu Dec 18 16:58:59 2003
@@ -451,6 +451,12 @@
# Python Quicksort Written by Magnus Lie Hetland
# http://www.hetland.org/python/quicksort.html
+
+# NOTE: we cannot yet detect that a user comparision
+# function modifies the list in-place. The
+# CPython sort() should be studied to learn how
+# to implement this functionality.
+
def _partition(list, start, end, lt):
pivot = list[end] # Partition around the last value
bottom = start-1 # Start outside the area to be partitioned
@@ -497,7 +503,11 @@
return space.is_true(space.lt(a,b))
else:
def lt(a,b):
- return space.unwrap(space.call_function(w_cmp, a, b)) < 0
+ result = space.unwrap(space.call_function(w_cmp, a, b))
+ if not isinstance(result,int):
+ raise OperationError(space.w_TypeError,
+ space.wrap("comparison function must return int"))
+ return result < 0
# XXX Basic quicksort implementation
# XXX this is not stable !!
More information about the Pypy-commit
mailing list