public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] portage r13353 - main/trunk/pym/portage
@ 2009-04-17 21:08 Zac Medico (zmedico)
  0 siblings, 0 replies; only message in thread
From: Zac Medico (zmedico) @ 2009-04-17 21:08 UTC (permalink / raw
  To: gentoo-commits

Author: zmedico
Date: 2009-04-17 21:08:36 +0000 (Fri, 17 Apr 2009)
New Revision: 13353

Modified:
   main/trunk/pym/portage/versions.py
Log:
Bug #266493 - Never return a long from vercmp() since that can trigger an
OverflowError if it's returned by a __cmp__ implementation. Thanks to
Douglas Anderson <dja@gendja.com> for the initial patch. I've modified it
to use the (a > b) - (a < b) construct as suggested in the py3k docs, since
cmp() is no longer supported in py3k.


Modified: main/trunk/pym/portage/versions.py
===================================================================
--- main/trunk/pym/portage/versions.py	2009-04-16 22:12:39 UTC (rev 13352)
+++ main/trunk/pym/portage/versions.py	2009-04-17 21:08:36 UTC (rev 13353)
@@ -124,9 +124,12 @@
 			vercmp_cache[mykey] = 1
 			return 1
 		elif list1[i] != list2[i]:
-			vercmp_cache[mykey] = list1[i] - list2[i]
-			return list1[i] - list2[i]
-	
+			a = list1[i]
+			b = list2[i]
+			rval = (a > b) - (a < b)
+			vercmp_cache[mykey] = rval
+			return rval
+
 	# main version is equal, so now compare the _suffix part
 	list1 = match1.group(6).split("_")[1:]
 	list2 = match2.group(6).split("_")[1:]
@@ -142,7 +145,11 @@
 		else:
 			s2 = suffix_regexp.match(list2[i]).groups()
 		if s1[0] != s2[0]:
-			return suffix_value[s1[0]] - suffix_value[s2[0]]
+			a = suffix_value[s1[0]]
+			b = suffix_value[s2[0]]
+			rval = (a > b) - (a < b)
+			vercmp_cache[mykey] = rval
+			return rval
 		if s1[1] != s2[1]:
 			# it's possible that the s(1|2)[1] == ''
 			# in such a case, fudge it.
@@ -154,9 +161,11 @@
 				r2 = int(s2[1])
 			except ValueError:
 				r2 = 0
-			if r1 - r2:
-				return r1 - r2
-	
+			rval = (r1 > r2) - (r1 < r2)
+			if rval:
+				vercmp_cache[mykey] = rval
+				return rval
+
 	# the suffix part is equal to, so finally check the revision
 	if match1.group(10):
 		r1 = int(match1.group(10))
@@ -166,8 +175,9 @@
 		r2 = int(match2.group(10))
 	else:
 		r2 = 0
-	vercmp_cache[mykey] = r1 - r2
-	return r1 - r2
+	rval = (r1 > r2) - (r1 < r2)
+	vercmp_cache[mykey] = rval
+	return rval
 	
 def pkgcmp(pkg1, pkg2):
 	"""




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-04-17 21:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-17 21:08 [gentoo-commits] portage r13353 - main/trunk/pym/portage Zac Medico (zmedico)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox