Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 266493

Summary: [patch] vercmp in sys-apps/portage-2.2_rc30 and earlier can return long
Product: Portage Development Reporter: Douglas Anderson <douglasjanderson>
Component: CoreAssignee: Portage team <dev-portage>
Status: RESOLVED FIXED    
Severity: minor Keywords: InVCS
Priority: High    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Bug Depends on:    
Bug Blocks: 210077, 268228    
Attachments: ensure vercmp output is -1, 0 or 1
simplify pkgcmp

Description Douglas Anderson 2009-04-17 09:20:47 UTC
cmp functions in python should return -1, 0, or 1, although any int will work. However, due to some packages with very long version numbers currently in the tree, portage.versions.vercmp can return a long type, which will break any compare functions.

Reproducible: Always

Steps to Reproduce:
Python 2.6.1 (r261:67515, Apr  7 2009, 11:30:57)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from portage.versions import *
>>> pkg1 = pkgsplit('btrace-0.0.20060428050322')
>>> pkg2 = pkgsplit('btrace-0.0.20071210202527')
>>> pkg1, pkg2
(('btrace', '0.0.20060428050322', 'r0'), ('btrace', '0.0.20071210202527', 'r0'))
>>> vercmp(pkg1[1], pkg2[1])
-10782152205L
>>> # ^^ returns long, compare functions must return int. this causes problems 
... class Foo(object):
...     def __cmp__(self, x):
...             return -10782152205
... 
>>> [Foo() for _ in range(100)].sort()


Actual Results:  
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: long int too large to convert to int

Expected Results:  
>>> from portage.versions import *
>>> pkg1 = pkgsplit('btrace-0.0.20060428050322')
>>> pkg2 = pkgsplit('btrace-0.0.20071210202527')
>>> pkg1, pkg2
(('btrace', '0.0.20060428050322', 'r0'), ('btrace', '0.0.20071210202527', 'r0'))
>>> vercmp(pkg1[1], pkg2[1])
-1
Comment 1 Douglas Anderson 2009-04-17 09:24:47 UTC
Created attachment 188656 [details, diff]
ensure vercmp output is -1, 0 or 1
Comment 2 Zac Medico gentoo-dev 2009-04-17 21:13:11 UTC
Thanks, I've committed a version of your patch in r13353. 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:

  http://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons
Comment 3 Douglas Anderson 2009-04-18 02:16:06 UTC
Created attachment 188763 [details, diff]
simplify pkgcmp

Thanks, Zac. I totally forgot about cmp going away.

Fixing vercmp also lets us simplify pkgcmp:
Comment 4 Zac Medico gentoo-dev 2009-04-18 04:46:12 UTC
(In reply to comment #3)
> Created an attachment (id=188763) [edit]
> simplify pkgcmp

Thanks, that's in svn r13354.
Comment 5 Zac Medico gentoo-dev 2009-04-19 23:34:29 UTC
This is fixed in 2.2_rc31.
Comment 6 Zac Medico gentoo-dev 2009-05-02 02:42:10 UTC
This is fixed in 2.1.6.12.