A fix for OverflowError in 64bits platforms

Manuel Vazquez Acosta mva.led at gmail.com
Thu Jul 3 10:20:54 EDT 2008


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,854,775,807 items ;)--- Maybe a bug in the documentation,
though

However, Archetypes.Schema.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.moveField('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.moveField(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.



More information about the Python-list mailing list