Author: Alex Gaynor <[email protected]>
Branch: kill-someobject
Changeset: r57931:b430e7ffd5f9
Date: 2012-10-08 15:29 +0200
http://bitbucket.org/pypy/pypy/changeset/b430e7ffd5f9/
Log: make pure python r_{u,}longlong initialization work with strings
diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py
--- a/pypy/rlib/rarithmetic.py
+++ b/pypy/rlib/rarithmetic.py
@@ -403,22 +403,26 @@
res = pow(x, y, m)
return self._widen(other, res)
+
class signed_int(base_int):
SIGNED = True
+
def __new__(klass, val=0):
- if type(val) is float:
+ if isinstance(val, (float, str)):
val = long(val)
- if val > klass.MASK>>1 or val < -(klass.MASK>>1)-1:
- raise OverflowError("%s does not fit in signed %d-bit
integer"%(val, klass.BITS))
+ if val > klass.MASK >> 1 or val < -(klass.MASK >> 1) - 1:
+ raise OverflowError("%s does not fit in signed %d-bit integer" %
(val, klass.BITS))
if val < 0:
val = ~ ((~val) & klass.MASK)
return super(signed_int, klass).__new__(klass, val)
typemap = {}
+
class unsigned_int(base_int):
SIGNED = False
+
def __new__(klass, val=0):
- if isinstance(val, (float, long)):
+ if isinstance(val, (float, long, str)):
val = long(val)
return super(unsigned_int, klass).__new__(klass, val & klass.MASK)
typemap = {}
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit