[Pyrex] unsigned integers bug

Rainer Deyke rainerd at eldwood.com
Wed Oct 19 21:31:12 CEST 2005


I am trying to wrap a struct that contains a member of type 'unsigned'. 
  When I try to assign a value of 0xff000000 to this member, I get a 
Python exception: "OverflowError: long int too large to convert to int".

In trying to write a workaround, I discovered another bug: Pyrex doesn't 
understand long literals.  A literal of 0x100000000 was clipped to 0 by 
the C compiler, and a literal of 0x100000000 was rejected by Pyrex.

I eventually ended up using a workaround that looked like this:

def set_value(self, value):
   if value > 0x7fffffff:
     value = value - 0x40000000 - 0x40000000 - 0x40000000 - 0x40000000
   self.value = value

def get_value(self):
   value = self.value
   if value < 0:
     value = value + 0x40000000 + 0x40000000 + 0x40000000 + 0x40000000


Information about my system:
   Python 2.4.1
   Pyrex 0.9.3
   Windows XP, service pack 2
   Visual Studio 2003 C/C++ compiler, invoked by distutils


-- 
Rainer Deyke - rainerd at eldwood.com - http://eldwood.com




More information about the Pyrex mailing list