A fix for OverflowError in 64bits platforms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Manuel Vazquez Acosta

    A fix for OverflowError in 64bits platforms

    Hi all,

    I'm debugging a Plone site in an AMD64 laptop. When I first tried to run
    Zope, I got this exception:

    OverflowError: signed integer is greater than maximum

    In the archives I encounter no solutions. This is what I could find, so
    I share with you all:

    It seems that on 64bit platforms, sys.maxint is much greater than list's
    insertion maximum index. I'm not sure if this a bug in python or a
    logical bound ---given the amount of RAM it would take to insert
    9,223,372,036,8 54,775,807 items ;)--- Maybe a bug in the documentation,
    though

    However, Archetypes.Sche ma.moveField method documents the use of maxint
    for inserting at the end of the Schema::
    maxint can be used to move the field to the last position possible
    >>from sys import maxint
    >>spos = schema.copy()
    >>spos.moveFiel d('a', pos=maxint)
    >>spos.keys()
    ['b', 'c', 'a']

    I have seen this usage in some products. This raises and OverflowError
    on 64bit platforms.

    The fix is simple in the code of the caller::
    from sys import maxint
    if maxint >33: # Am I running on 64bits?
    maxint = maxint >33
    theschema.moveF ield(the_name, pos=maxint)

    Now, the maxint variable holds an acceptable value.

    I think the docstring should be appended with a "Note: On 64bits
    platform this raises an OverflowError blah blah..."

    Best regards,
    Manuel.
Working...