1 |
Author: zmedico |
2 |
Date: 2009-04-30 07:16:36 +0000 (Thu, 30 Apr 2009) |
3 |
New Revision: 13509 |
4 |
|
5 |
Modified: |
6 |
main/branches/2.1.6/pym/portage/versions.py |
7 |
Log: |
8 |
Bug #266493 - Never return a long from vercmp() since that can trigger an |
9 |
OverflowError if it's returned by a __cmp__ implementation. Thanks to |
10 |
Douglas Anderson <dja@××××××.com> for the initial patch. I've modified it |
11 |
to use the (a > b) - (a < b) construct as suggested in the py3k docs, since |
12 |
cmp() is no longer supported in py3k. (trunk r13353) |
13 |
|
14 |
Modified: main/branches/2.1.6/pym/portage/versions.py |
15 |
=================================================================== |
16 |
--- main/branches/2.1.6/pym/portage/versions.py 2009-04-30 07:13:58 UTC (rev 13508) |
17 |
+++ main/branches/2.1.6/pym/portage/versions.py 2009-04-30 07:16:36 UTC (rev 13509) |
18 |
@@ -124,9 +124,12 @@ |
19 |
vercmp_cache[mykey] = 1 |
20 |
return 1 |
21 |
elif list1[i] != list2[i]: |
22 |
- vercmp_cache[mykey] = list1[i] - list2[i] |
23 |
- return list1[i] - list2[i] |
24 |
- |
25 |
+ a = list1[i] |
26 |
+ b = list2[i] |
27 |
+ rval = (a > b) - (a < b) |
28 |
+ vercmp_cache[mykey] = rval |
29 |
+ return rval |
30 |
+ |
31 |
# main version is equal, so now compare the _suffix part |
32 |
list1 = match1.group(6).split("_")[1:] |
33 |
list2 = match2.group(6).split("_")[1:] |
34 |
@@ -142,7 +145,11 @@ |
35 |
else: |
36 |
s2 = suffix_regexp.match(list2[i]).groups() |
37 |
if s1[0] != s2[0]: |
38 |
- return suffix_value[s1[0]] - suffix_value[s2[0]] |
39 |
+ a = suffix_value[s1[0]] |
40 |
+ b = suffix_value[s2[0]] |
41 |
+ rval = (a > b) - (a < b) |
42 |
+ vercmp_cache[mykey] = rval |
43 |
+ return rval |
44 |
if s1[1] != s2[1]: |
45 |
# it's possible that the s(1|2)[1] == '' |
46 |
# in such a case, fudge it. |
47 |
@@ -154,9 +161,11 @@ |
48 |
r2 = int(s2[1]) |
49 |
except ValueError: |
50 |
r2 = 0 |
51 |
- if r1 - r2: |
52 |
- return r1 - r2 |
53 |
- |
54 |
+ rval = (r1 > r2) - (r1 < r2) |
55 |
+ if rval: |
56 |
+ vercmp_cache[mykey] = rval |
57 |
+ return rval |
58 |
+ |
59 |
# the suffix part is equal to, so finally check the revision |
60 |
if match1.group(10): |
61 |
r1 = int(match1.group(10)) |
62 |
@@ -166,8 +175,9 @@ |
63 |
r2 = int(match2.group(10)) |
64 |
else: |
65 |
r2 = 0 |
66 |
- vercmp_cache[mykey] = r1 - r2 |
67 |
- return r1 - r2 |
68 |
+ rval = (r1 > r2) - (r1 < r2) |
69 |
+ vercmp_cache[mykey] = rval |
70 |
+ return rval |
71 |
|
72 |
def pkgcmp(pkg1, pkg2): |
73 |
""" |