[pypy-svn] r38627 - in pypy/dist/pypy/rpython: lltypesystem ootypesystem test
arigo at codespeak.net
arigo at codespeak.net
Mon Feb 12 19:28:56 CET 2007
Author: arigo
Date: Mon Feb 12 19:28:53 2007
New Revision: 38627
Modified:
pypy/dist/pypy/rpython/lltypesystem/ll_str.py
pypy/dist/pypy/rpython/ootypesystem/ll_str.py
pypy/dist/pypy/rpython/test/test_rint.py
Log:
(arre, arigo)
Special-case hex() and oct() of sys.maxint-1. Avoids segfaults of pypy-c.
Modified: pypy/dist/pypy/rpython/lltypesystem/ll_str.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/ll_str.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/ll_str.py Mon Feb 12 19:28:53 2007
@@ -49,14 +49,16 @@
sign = 0
if i < 0:
sign = 1
- i = -i
+ i = r_uint(-i)
+ else:
+ i = r_uint(i)
if i == 0:
len = 1
temp[0] = '0'
else:
while i:
- temp[len] = hex_chars[i%16]
- i //= 16
+ temp[len] = hex_chars[i & 0xf]
+ i >>= 4
len += 1
len += sign
if addPrefix:
@@ -88,10 +90,12 @@
sign = 0
if i < 0:
sign = 1
- i = -i
+ i = r_uint(-i)
+ else:
+ i = r_uint(i)
while i:
- temp[len] = hex_chars[i%8]
- i //= 8
+ temp[len] = hex_chars[i & 0x7]
+ i >>= 3
len += 1
len += sign
if addPrefix:
Modified: pypy/dist/pypy/rpython/ootypesystem/ll_str.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ll_str.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/ll_str.py Mon Feb 12 19:28:53 2007
@@ -1,4 +1,6 @@
+import sys
from pypy.rpython.ootypesystem.ootype import new, oostring, StringBuilder
+from pypy.rpython.ootypesystem.ootype import make_string
def ll_int_str(repr, i):
return ll_int2dec(i)
@@ -6,12 +8,20 @@
def ll_int2dec(i):
return oostring(i, 10)
+SPECIAL_VALUE = -sys.maxint-1
+SPECIAL_VALUE_HEX = make_string(
+ '-' + hex(sys.maxint+1).replace('L', '').replace('l', ''))
+SPECIAL_VALUE_OCT = make_string(
+ '-' + oct(sys.maxint+1).replace('L', '').replace('l', ''))
+
def ll_int2hex(i, addPrefix):
if not addPrefix:
return oostring(i, 16)
buf = new(StringBuilder)
if i<0:
+ if i == SPECIAL_VALUE:
+ return SPECIAL_VALUE_HEX
i = -i
buf.ll_append_char('-')
@@ -26,6 +36,8 @@
buf = new(StringBuilder)
if i<0:
+ if i == SPECIAL_VALUE:
+ return SPECIAL_VALUE_OCT
i = -i
buf.ll_append_char('-')
Modified: pypy/dist/pypy/rpython/test/test_rint.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rint.py (original)
+++ pypy/dist/pypy/rpython/test/test_rint.py Mon Feb 12 19:28:53 2007
@@ -78,6 +78,10 @@
res = self.interpret(dummy, [-123])
assert self.ll_to_string(res) == '-0x7b'
+ res = self.interpret(dummy, [-sys.maxint-1])
+ res = self.ll_to_string(res)
+ assert res == '-0x8' + '0' * (len(res)-4)
+
def test_oct_of_int(self):
def dummy(i):
return oct(i)
@@ -91,6 +95,10 @@
res = self.interpret(dummy, [-123])
assert self.ll_to_string(res) == '-0173'
+ res = self.interpret(dummy, [-sys.maxint-1])
+ res = self.ll_to_string(res)
+ assert res == '-' + oct(sys.maxint+1).replace('L', '').replace('l', '')
+
def test_unsigned(self):
def dummy(i):
i = r_uint(i)
More information about the Pypy-commit
mailing list