From benjamin at codespeak.net Thu Jul 1 00:14:49 2010
From: benjamin at codespeak.net (benjamin at codespeak.net)
Date: Thu, 1 Jul 2010 00:14:49 +0200 (CEST)
Subject: [pypy-svn] r75707 - in pypy/branch/fast-forward/pypy: objspace/std
objspace/std/test rlib
Message-ID: <20100630221449.5172A282B9C@codespeak.net>
Author: benjamin
Date: Thu Jul 1 00:14:47 2010
New Revision: 75707
Modified:
pypy/branch/fast-forward/pypy/objspace/std/floatobject.py
pypy/branch/fast-forward/pypy/objspace/std/newformat.py
pypy/branch/fast-forward/pypy/objspace/std/test/test_newformat.py
pypy/branch/fast-forward/pypy/rlib/rarithmetic.py
Log:
cobble some code together for float formatting
Modified: pypy/branch/fast-forward/pypy/objspace/std/floatobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/floatobject.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/floatobject.py Thu Jul 1 00:14:47 2010
@@ -1,7 +1,7 @@
import operator, new
from pypy.interpreter import gateway
from pypy.interpreter.error import OperationError
-from pypy.objspace.std import model
+from pypy.objspace.std import model, newformat
from pypy.objspace.std.multimethod import FailedToImplementArgs
from pypy.objspace.std.model import registerimplementation, W_Object
from pypy.objspace.std.register_all import register_all
@@ -106,6 +106,9 @@
def str__Float(space, w_float):
return float2string(space, w_float, "%.12g")
+def format__Float_ANY(space, w_float, w_spec):
+ return newformat.get_formatter(space, w_spec).format_float(w_float)
+
# ____________________________________________________________
# A mess to handle all cases of float comparison without relying
# on delegation, which can unfortunately loose precision when
Modified: pypy/branch/fast-forward/pypy/objspace/std/newformat.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/newformat.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/newformat.py Thu Jul 1 00:14:47 2010
@@ -419,15 +419,15 @@
self._calc_padding(string, length)
return space.wrap(self._pad(string))
- def _get_locale(self, locale_kind):
+ def _get_locale(self, tp):
space = self.space
- if locale_kind == CURRENT_LOCALE:
+ if tp == "n":
dec, thousands, grouping = rlocale.numeric_formatting()
- elif locale_kind == DEFAULT_LOCALE:
+ elif self._thousands_sep:
dec = "."
thousands = ","
grouping = "\3\0"
- elif locale_kind == NO_LOCALE:
+ else:
dec = "."
thousands = ""
grouping = "\256"
@@ -445,7 +445,7 @@
spec.n_digits = n_number - n_remainder - has_dec
spec.n_prefix = n_prefix
spec.n_lpadding = 0
- spec.n_decimal = 1 if has_dec else 0
+ spec.n_decimal = int(has_dec)
spec.n_remainder = n_remainder
spec.n_spadding = 0
spec.n_rpadding = 0
@@ -548,7 +548,7 @@
def _fill_number(self, spec, num, to_digits, n_digits, to_prefix, fill_char,
- upper):
+ to_remainder, upper):
out = self._builder()
if spec.n_lpadding:
out.append_multiple_char(fill_char, spec.n_lpadding)
@@ -563,16 +563,16 @@
out.append_multiple_char(fill_char, spec.n_spadding)
if spec.n_digits != 0:
if self._loc_thousands:
- num = self._grouped_digits
+ digits = self._grouped_digits
else:
- num = num[to_digits:]
+ digits = num[to_digits:to_digits + spec.n_digits]
if upper:
- num = self._upcase_string(num)
- out.append(num)
+ digits = self._upcase_string(digits)
+ out.append(digits)
if spec.n_decimal:
out.append(".")
if spec.n_remainder:
- out.append(num[0])
+ out.append(num[to_remainder:])
if spec.n_rpadding:
out.append_multiple_char(fill_char, spec.n_rpadding)
return self.space.wrap(out.build())
@@ -598,6 +598,7 @@
result = chr(value)
n_digits = 1
n_remainder = 1
+ to_remainder = 0
n_prefix = 0
to_prefix = 0
to_numeric = 0
@@ -628,20 +629,15 @@
to_prefix += 1
n_digits = len(result) - skip_leading
n_remainder = 0
+ to_remainder = 0
to_numeric = skip_leading
- if tp == "n":
- locale_kind = CURRENT_LOCALE
- elif self._thousands_sep:
- locale_kind = DEFAULT_LOCALE
- else:
- locale_kind = NO_LOCALE
- self._get_locale(locale_kind)
+ self._get_locale(tp)
spec = self._calc_num_width(n_prefix, sign_char, to_numeric, n_digits,
n_remainder, False, result)
fill = " " if self._fill_char == "\0" else self._fill_char
upper = self._type == "X"
return self._fill_number(spec, result, to_numeric, n_digits, to_prefix,
- fill, upper)
+ fill, to_remainder, upper)
def _long_to_base(self, base, value):
prefix = ""
@@ -718,24 +714,63 @@
tp == "G" or
tp == "%"):
w_float = space.float(w_num)
- self._format_float(w_float)
+ return self._format_float(w_float)
else:
self._unknown_presentation("int" if kind == INT_KIND else "long")
+ def _parse_number(self, s, i):
+ length = len(s)
+ while i < length and "0" <= s[i] <= "9":
+ i += 1
+ rest = i
+ dec_point = i < length and s[i] == "."
+ if dec_point:
+ rest += 1
+ return dec_point, rest
+
def _format_float(self, w_float):
space = self.space
+ flags = 0
+ default_precision = 6
if self._alternate:
msg = "alternate form not allowed in float formats"
raise OperationError(space.w_ValueError, space.wrap(msg))
tp = self._type
if tp == "\0":
tp = "g"
+ default_prec = 12
+ flags |= rarithmetic.DTSF_ADD_DOT_0
+ elif tp == "n":
+ tp = "g"
value = space.float_w(w_float)
if tp == "%":
tp = "f"
value *= 100
+ add_pct = True
+ else:
+ add_pct = False
if self._precision == -1:
- self._precision = 6
+ self._precision = default_precision
+ result, special = rarithmetic.double_to_string(value, tp,
+ self._precision, flags)
+ if add_pct:
+ result += "%"
+ n_digits = len(result)
+ if result[0] == "-":
+ sign = "-"
+ to_number = 1
+ n_digits -= 1
+ else:
+ sign = "\0"
+ to_number = 0
+ have_dec_point, to_remainder = self._parse_number(result, to_number)
+ n_remainder = len(result) - to_remainder
+ self._get_locale(tp)
+ spec = self._calc_num_width(0, sign, to_number, n_digits,
+ n_remainder, have_dec_point, result)
+ fill = " " if self._fill_char == "\0" else self._fill_char
+ return self._fill_number(spec, result, to_number, None, 0, fill,
+ to_remainder, False)
def format_float(self, w_float):
space = self.space
Modified: pypy/branch/fast-forward/pypy/objspace/std/test/test_newformat.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/test/test_newformat.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/test/test_newformat.py Thu Jul 1 00:14:47 2010
@@ -215,3 +215,15 @@
def setup_class(cls):
cls.w_i = cls.space.w_long
+
+
+class AppTestFloatFormatting:
+
+ def test_alternate(self):
+ raises(ValueError, format, 1.0, "#")
+
+ def test_simple(self):
+ assert format(0.0, "f") == "0.000000"
+
+ def test_sign(self):
+ assert format(-1.23, "1") == "-1.23"
Modified: pypy/branch/fast-forward/pypy/rlib/rarithmetic.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rlib/rarithmetic.py (original)
+++ pypy/branch/fast-forward/pypy/rlib/rarithmetic.py Thu Jul 1 00:14:47 2010
@@ -465,6 +465,22 @@
return formatd(fmt, x)
+DTSF_ADD_DOT_0 = 1
+
+DIST_FINITE = 1
+DIST_NAN = 2
+DIST_INFINITY = 3
+
+def double_to_string(value, tp, precision, flags):
+ if isnan(value):
+ special = DIST_NAN
+ elif isinf(value):
+ special = DIST_INFINITY
+ else:
+ special = DIST_FINITE
+ result = formatd_overflow(False, precision, tp, value)
+ return result, special
+
# the 'float' C type
class r_singlefloat(object):
From benjamin at codespeak.net Thu Jul 1 00:51:31 2010
From: benjamin at codespeak.net (benjamin at codespeak.net)
Date: Thu, 1 Jul 2010 00:51:31 +0200 (CEST)
Subject: [pypy-svn] r75708 - in pypy/branch/fast-forward/pypy/objspace/std:
. test
Message-ID: <20100630225131.23AAF282B9C@codespeak.net>
Author: benjamin
Date: Thu Jul 1 00:51:28 2010
New Revision: 75708
Modified:
pypy/branch/fast-forward/pypy/objspace/std/newformat.py
pypy/branch/fast-forward/pypy/objspace/std/test/test_newformat.py
Log:
fix more float formatting bugs
Modified: pypy/branch/fast-forward/pypy/objspace/std/newformat.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/newformat.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/newformat.py Thu Jul 1 00:51:28 2010
@@ -467,7 +467,7 @@
if self._fill_char == "0" and self._align == "=":
spec.n_min_width = self._width - extra_length
if self._loc_thousands:
- self._group_digits(spec, digits)
+ self._group_digits(spec, digits[to_number:])
n_grouped_digits = len(self._grouped_digits)
else:
n_grouped_digits = spec.n_digits
@@ -500,7 +500,7 @@
buf = []
grouping = self._loc_grouping
min_width = spec.n_min_width
- i = 0
+ grouping_state = 0
count = 0
left = spec.n_digits
n_ts = len(self._loc_thousands)
@@ -508,11 +508,11 @@
done = False
groupings = len(grouping)
while True:
- group = ord(grouping[i])
+ group = ord(grouping[grouping_state])
if group > 0:
if group == 256:
break
- i += 1
+ grouping_state += 1
previous = group
else:
group = previous
Modified: pypy/branch/fast-forward/pypy/objspace/std/test/test_newformat.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/test/test_newformat.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/test/test_newformat.py Thu Jul 1 00:51:28 2010
@@ -227,3 +227,10 @@
def test_sign(self):
assert format(-1.23, "1") == "-1.23"
+
+ def test_digit_separator(self):
+ assert format(-1234., "012,f") == "-1,234.000000"
+
+ def test_dont_switch_to_g(self):
+ skip("must fix when float formatting is figured out")
+ assert len(format(1.1234e90, "f")) == 98
From benjamin at codespeak.net Thu Jul 1 01:14:32 2010
From: benjamin at codespeak.net (benjamin at codespeak.net)
Date: Thu, 1 Jul 2010 01:14:32 +0200 (CEST)
Subject: [pypy-svn] r75709 - in pypy/branch/fast-forward/pypy/interpreter: .
test
Message-ID: <20100630231432.CCFFC282B9C@codespeak.net>
Author: benjamin
Date: Thu Jul 1 01:14:31 2010
New Revision: 75709
Modified:
pypy/branch/fast-forward/pypy/interpreter/function.py
pypy/branch/fast-forward/pypy/interpreter/test/test_function.py
Log:
complain when both self and class are None
Modified: pypy/branch/fast-forward/pypy/interpreter/function.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/function.py (original)
+++ pypy/branch/fast-forward/pypy/interpreter/function.py Thu Jul 1 01:14:31 2010
@@ -430,8 +430,11 @@
self.w_class = w_class # possibly space.w_None
def descr_method__new__(space, w_subtype, w_function, w_instance, w_class=None):
- if space.is_w( w_instance, space.w_None ):
+ if space.is_w(w_instance, space.w_None):
w_instance = None
+ if w_instance is None and space.is_w(w_class, space.w_None):
+ raise OperationError(space.w_TypeError,
+ space.wrap("unbound methods must have class"))
method = space.allocate_instance(Method, w_subtype)
Method.__init__(method, space, w_function, w_instance, w_class)
return space.wrap(method)
Modified: pypy/branch/fast-forward/pypy/interpreter/test/test_function.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/test/test_function.py (original)
+++ pypy/branch/fast-forward/pypy/interpreter/test/test_function.py Thu Jul 1 01:14:31 2010
@@ -482,6 +482,11 @@
raises(TypeError, m, MyInst(None))
raises(TypeError, m, MyInst(42))
+ def test_invalid_creation(self):
+ import new
+ def f(): pass
+ raises(TypeError, new.instancemethod, f, None)
+
class TestMethod:
def setup_method(self, method):
From afa at codespeak.net Thu Jul 1 10:48:22 2010
From: afa at codespeak.net (afa at codespeak.net)
Date: Thu, 1 Jul 2010 10:48:22 +0200 (CEST)
Subject: [pypy-svn] r75710 -
pypy/branch/interplevel-codecs/pypy/module/_codecs/test
Message-ID: <20100701084822.5F34C282B9E@codespeak.net>
Author: afa
Date: Thu Jul 1 10:48:19 2010
New Revision: 75710
Modified:
pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py
Log:
These tests pass, actually
Modified: pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py
==============================================================================
--- pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py (original)
+++ pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py Thu Jul 1 10:48:19 2010
@@ -12,9 +12,6 @@
raises(TypeError, _codecs.register, 1)
def test_bigU_codecs(self):
- import sys
- if sys.maxunicode <= 0xffff:
- return # this test cannot run on UCS2 builds
u = u'\U00010001\U00020002\U00030003\U00040004\U00050005'
for encoding in ('utf-8', 'utf-16', 'utf-16-le', 'utf-16-be',
'raw_unicode_escape',
@@ -22,9 +19,6 @@
assert unicode(u.encode(encoding),encoding) == u
def test_ucs4(self):
- import sys
- if sys.maxunicode <= 0xffff:
- return # this test cannot run on UCS2 builds
x = u'\U00100000'
y = x.encode("raw-unicode-escape").decode("raw-unicode-escape")
assert x == y
From afa at codespeak.net Thu Jul 1 10:52:11 2010
From: afa at codespeak.net (afa at codespeak.net)
Date: Thu, 1 Jul 2010 10:52:11 +0200 (CEST)
Subject: [pypy-svn] r75711 - pypy/branch/interplevel-codecs/pypy/rlib
Message-ID: <20100701085211.2EE30282B9E@codespeak.net>
Author: afa
Date: Thu Jul 1 10:52:09 2010
New Revision: 75711
Modified:
pypy/branch/interplevel-codecs/pypy/rlib/runicode.py
Log:
- Uniformly handle the decoding of \U and \u
- Decoded \U sequences must be unsigned int, otherwise \UFFFFFEEEE wraps and becomes \ueeee...
Modified: pypy/branch/interplevel-codecs/pypy/rlib/runicode.py
==============================================================================
--- pypy/branch/interplevel-codecs/pypy/rlib/runicode.py (original)
+++ pypy/branch/interplevel-codecs/pypy/rlib/runicode.py Thu Jul 1 10:52:09 2010
@@ -3,6 +3,7 @@
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.rlib.objectmodel import we_are_translated, specialize
from pypy.rlib.rstring import StringBuilder, UnicodeBuilder
+from pypy.rlib.rarithmetic import r_uint
if rffi.sizeof(lltype.UniChar) == 4:
MAXUNICODE = 0x10ffff
@@ -780,7 +781,8 @@
hexdigits = "0123456789ABCDEFabcdef"
-def hexescape(builder, s, pos, digits, errorhandler, message, errors):
+def hexescape(builder, s, pos, digits,
+ encoding, errorhandler, message, errors):
import sys
chr = 0
if (pos+digits>len(s)):
@@ -790,12 +792,12 @@
builder.append(res)
else:
try:
- chr = int(s[pos:pos+digits], 16)
+ chr = r_uint(int(s[pos:pos+digits], 16))
except ValueError:
endinpos = pos
while s[endinpos] in hexdigits:
endinpos += 1
- res, pos = errorhandler(errors, "unicodeescape",
+ res, pos = errorhandler(errors, encoding,
message, s, pos-2, endinpos+1)
builder.append(res)
else:
@@ -811,8 +813,8 @@
pos += digits
else:
message = "illegal Unicode character"
- res, pos = errorhandler(errors, "unicodeescape",
- message, s, pos-2, pos+1)
+ res, pos = errorhandler(errors, encoding,
+ message, s, pos-2, pos+digits)
builder.append(res)
return pos
@@ -878,21 +880,21 @@
digits = 2
message = "truncated \\xXX escape"
pos = hexescape(builder, s, pos, digits,
- errorhandler, message, errors)
+ "unicodeescape", errorhandler, message, errors)
# \uXXXX
elif ch == 'u':
digits = 4
message = "truncated \\uXXXX escape"
pos = hexescape(builder, s, pos, digits,
- errorhandler, message, errors)
+ "unicodeescape", errorhandler, message, errors)
# \UXXXXXXXX
elif ch == 'U':
digits = 8
message = "truncated \\UXXXXXXXX escape"
pos = hexescape(builder, s, pos, digits,
- errorhandler, message, errors)
+ "unicodeescape", errorhandler, message, errors)
# \N{name}
elif ch == 'N':
@@ -1052,31 +1054,14 @@
continue
if s[pos] == 'u':
- count = 4
+ digits = 4
+ message = "truncated \\uXXXX escape"
else:
- count = 8
+ digits = 8
+ message = "truncated \\UXXXXXXXX escape"
pos += 1
-
- # \uXXXX with 4 hex digits, \Uxxxxxxxx with 8
- x = 0
- try:
- x = int(s[pos:pos+count], 16)
- except ValueError:
- res, pos = errorhandler(errors, "rawunicodeescape",
- "truncated \\uXXXX",
- s, pos, size)
- result.append(res)
- continue
-
- if (x > MAXUNICODE):
- res, pos = errorhandler(errors, "rawunicodeescape",
- "\\Uxxxxxxxx out of range",
- s, pos, size)
- result.append(res)
- continue
-
- result.append(unichr(x))
- pos += count
+ pos = hexescape(result, s, pos, digits,
+ "rawunicodeescape", errorhandler, message, errors)
return result.build(), pos
@@ -1147,10 +1132,10 @@
if pos > size - unicode_bytes:
break
continue
- t = 0
+ t = r_uint(0)
h = 0
for j in range(start, stop, step):
- t += ord(s[pos + j]) << (h*8)
+ t += r_uint(ord(s[pos + j])) << (h*8)
h += 1
if t > MAXUNICODE:
res, pos = errorhandler(errors, "unicode_internal",
From fijal at codespeak.net Thu Jul 1 12:05:43 2010
From: fijal at codespeak.net (fijal at codespeak.net)
Date: Thu, 1 Jul 2010 12:05:43 +0200 (CEST)
Subject: [pypy-svn] r75712 - pypy/trunk/pypy/module/operator/test
Message-ID: <20100701100543.357A4282B9E@codespeak.net>
Author: fijal
Date: Thu Jul 1 12:05:41 2010
New Revision: 75712
Modified:
pypy/trunk/pypy/module/operator/test/test_operator.py
Log:
Strike unnecessary import
Modified: pypy/trunk/pypy/module/operator/test/test_operator.py
==============================================================================
--- pypy/trunk/pypy/module/operator/test/test_operator.py (original)
+++ pypy/trunk/pypy/module/operator/test/test_operator.py Thu Jul 1 12:05:41 2010
@@ -154,7 +154,6 @@
def test_irepeat(self):
import operator
- import py
class X(object):
def __index__(self):
From afa at codespeak.net Thu Jul 1 12:10:33 2010
From: afa at codespeak.net (afa at codespeak.net)
Date: Thu, 1 Jul 2010 12:10:33 +0200 (CEST)
Subject: [pypy-svn] r75713 - pypy/branch/interplevel-codecs/pypy/rlib
Message-ID: <20100701101033.BD3AA282B9E@codespeak.net>
Author: afa
Date: Thu Jul 1 12:10:32 2010
New Revision: 75713
Modified:
pypy/branch/interplevel-codecs/pypy/rlib/runicode.py
Log:
remove C-style parentheses
Modified: pypy/branch/interplevel-codecs/pypy/rlib/runicode.py
==============================================================================
--- pypy/branch/interplevel-codecs/pypy/rlib/runicode.py (original)
+++ pypy/branch/interplevel-codecs/pypy/rlib/runicode.py Thu Jul 1 12:10:32 2010
@@ -81,7 +81,7 @@
errorhandler=None):
if errorhandler is None:
errorhandler = raise_unicode_exception_decode
- if (size == 0):
+ if size == 0:
return u'', 0
result = UnicodeBuilder(size)
@@ -95,14 +95,14 @@
continue
n = utf8_code_length[ordch1]
- if (pos + n > size):
+ if pos + n > size:
if not final:
break
else:
r, pos = errorhandler(errors, "utf-8",
"unexpected end of data", s, pos, size)
result.append(r)
- if (pos + n > size):
+ if pos + n > size:
break
if n == 0:
r, pos = errorhandler(errors, "utf-8", "unexpected code byte",
@@ -117,7 +117,7 @@
z, two = splitter[6, 2](ordch2)
y, six = splitter[5, 3](ordch1)
assert six == 6
- if (two != 2):
+ if two != 2:
r, pos = errorhandler(errors, "utf-8", "invalid data",
s, pos, pos + 2)
result.append(r)
@@ -138,7 +138,7 @@
y, two2 = splitter[6, 2](ordch2)
x, fourteen = splitter[4, 4](ordch1)
assert fourteen == 14
- if (two1 != 2 or two2 != 2):
+ if two1 != 2 or two2 != 2:
r, pos = errorhandler(errors, "utf-8", "invalid data",
s, pos, pos + 3)
result.append(r)
@@ -167,7 +167,7 @@
x, two3 = splitter[6, 2](ordch2)
w, thirty = splitter[3, 5](ordch1)
assert thirty == 30
- if (two1 != 2 or two2 != 2 or two3 != 2):
+ if two1 != 2 or two2 != 2 or two3 != 2:
r, pos = errorhandler(errors, "utf-8", "invalid data",
s, pos, pos + 4)
result.append(r)
@@ -175,7 +175,7 @@
c = (w << 18) + (x << 12) + (y << 6) + z
# minimum value allowed for 4 byte encoding
# maximum value allowed for UTF-16
- if ((c < 0x10000) or (c > 0x10ffff)):
+ if c < 0x10000 or c > 0x10ffff:
r, pos = errorhandler(errors, "utf-8", "illegal encoding",
s, pos, pos + 4)
result.append(r)
@@ -214,22 +214,22 @@
while i < size:
ch = ord(s[i])
i += 1
- if (ch < 0x80):
- # Encode ASCII
+ if ch < 0x80:
+ # Encode ASCII
result.append(chr(ch))
- elif (ch < 0x0800) :
- # Encode Latin-1
+ elif ch < 0x0800:
+ # Encode Latin-1
result.append(chr((0xc0 | (ch >> 6))))
result.append(chr((0x80 | (ch & 0x3f))))
else:
# Encode UCS2 Unicode ordinals
- if (ch < 0x10000):
+ if ch < 0x10000:
# Special case: check for high surrogate
- if (0xD800 <= ch and ch <= 0xDBFF and i != size) :
+ if 0xD800 <= ch <= 0xDBFF and i != size:
ch2 = ord(s[i])
# Check for low surrogate and combine the two to
# form a UCS4 value
- if (0xDC00 <= ch2 and ch2 <= 0xDFFF) :
+ if 0xDC00 <= ch2 <= 0xDFFF:
ch3 = ((ch - 0xD800) << 10 | (ch2 - 0xDC00)) + 0x10000
i += 1
_encodeUCS4(result, ch3)
@@ -285,10 +285,10 @@
# stream as-is (giving a ZWNBSP character).
pos = 0
if byteorder == 'native':
- if (size >= 2):
+ if size >= 2:
bom = (ord(s[ihi]) << 8) | ord(s[ilo])
if BYTEORDER == 'little':
- if (bom == 0xFEFF):
+ if bom == 0xFEFF:
pos += 2
bo = -1
elif bom == 0xFFFE:
@@ -305,14 +305,14 @@
bo = -1
else:
bo = 1
- if (size == 0):
+ if size == 0:
return u'', 0, bo
- if (bo == -1):
+ if bo == -1:
# force little endian
ihi = 1
ilo = 0
- elif (bo == 1):
+ elif bo == 1:
# force big endian
ihi = 0
ilo = 1
@@ -332,7 +332,7 @@
break
ch = (ord(s[pos + ihi]) << 8) | ord(s[pos + ilo])
pos += 2
- if (ch < 0xD800 or ch > 0xDFFF):
+ if ch < 0xD800 or ch > 0xDFFF:
result.append(unichr(ch))
continue
# UTF-16 code pair:
@@ -344,10 +344,10 @@
result.append(r)
if len(s) - pos < 2:
break
- elif (0xD800 <= ch and ch <= 0xDBFF):
+ elif 0xD800 <= ch <= 0xDBFF:
ch2 = (ord(s[pos+ihi]) << 8) | ord(s[pos+ilo])
pos += 2
- if (0xDC00 <= ch2 and ch2 <= 0xDFFF):
+ if 0xDC00 <= ch2 <= 0xDFFF:
if MAXUNICODE < 65536:
result.append(unichr(ch))
result.append(unichr(ch2))
@@ -384,7 +384,7 @@
return ""
result = StringBuilder(size * 2 + 2)
- if (byteorder == 'native'):
+ if byteorder == 'native':
_STORECHAR(result, 0xFEFF, BYTEORDER)
byteorder = BYTEORDER
@@ -393,7 +393,7 @@
ch = ord(s[i])
i += 1
ch2 = 0
- if (ch >= 0x10000) :
+ if ch >= 0x10000:
ch2 = 0xDC00 | ((ch-0x10000) & 0x3FF)
ch = 0xD800 | ((ch-0x10000) >> 10)
@@ -465,8 +465,8 @@
else:
return ord(c) + 4
-def _utf7_ENCODE(result, ch, bits) :
- while (bits >= 6):
+def _utf7_ENCODE(result, ch, bits):
+ while bits >= 6:
result.append(_utf7_TO_BASE64(ch >> (bits - 6)))
bits -= 6
return bits
@@ -475,7 +475,7 @@
errorhandler=None):
if errorhandler is None:
errorhandler = raise_unicode_exception_decode
- if (size == 0):
+ if size == 0:
return u'', 0
inShift = False
@@ -533,7 +533,7 @@
result.append(u'-')
inShift = True
- elif _utf7_SPECIAL(oc) :
+ elif _utf7_SPECIAL(oc):
msg = "unexpected special character"
res, pos = errorhandler(errors, 'utf-7',
msg, s, pos-1, pos)
@@ -572,7 +572,7 @@
return result.build(), pos
def unicode_encode_utf_7(s, size, errors, errorhandler=None):
- if (size == 0):
+ if size == 0:
return ''
result = StringBuilder(size)
@@ -622,9 +622,9 @@
ch2 = s[pos + 1]
oc2 = ord(ch2)
- if (_utf7_SPECIAL(oc2, encodeSetO, encodeWhiteSpace)):
+ if _utf7_SPECIAL(oc2, encodeSetO, encodeWhiteSpace):
pass
- elif (_utf7_B64CHAR(oc2) or ch2 == u'-'):
+ elif _utf7_B64CHAR(oc2) or ch2 == u'-':
result.append('-')
inShift = False
else:
@@ -683,8 +683,8 @@
else:
reason = "ordinal not in range(128)"
encoding = "ascii"
-
- if (size == 0):
+
+ if size == 0:
return ''
result = StringBuilder(size)
pos = 0
@@ -785,7 +785,7 @@
encoding, errorhandler, message, errors):
import sys
chr = 0
- if (pos+digits>len(s)):
+ if pos + digits > len(s):
message = "end of string in escape sequence"
res, pos = errorhandler(errors, "unicodeescape",
message, s, pos-2, len(s))
@@ -806,7 +806,7 @@
builder.append(unichr(chr))
pos += digits
- elif (chr <= 0x10ffff):
+ elif chr <= 0x10ffff:
chr -= 0x10000L
builder.append(unichr(0xD800 + (chr >> 10)))
builder.append(unichr(0xDC00 + (chr & 0x03FF)))
@@ -824,7 +824,7 @@
if errorhandler is None:
errorhandler = raise_unicode_exception_decode
- if (size == 0):
+ if size == 0:
return u'', 0
builder = UnicodeBuilder(size)
@@ -833,7 +833,7 @@
ch = s[pos]
# Non-escape characters are interpreted as Unicode ordinals
- if (ch != '\\') :
+ if ch != '\\':
builder.append(unichr(ord(ch)))
pos += 1
continue
@@ -899,7 +899,6 @@
# \N{name}
elif ch == 'N':
message = "malformed \\N character escape"
- #pos += 1
look = pos
if unicodedata_handler is None:
message = ("\\N escapes not supported "
@@ -911,9 +910,9 @@
if look < size and s[look] == '{':
# look for the closing brace
- while (look < size and s[look] != '}'):
+ while look < size and s[look] != '}':
look += 1
- if (look > pos+1 and look < size and s[look] == '}'):
+ if look < size and s[look] == '}':
# found a name. look it up in the unicode database
message = "unknown Unicode character name"
name = s[pos+1:look]
@@ -1016,7 +1015,7 @@
errorhandler=None):
if errorhandler is None:
errorhandler = raise_unicode_exception_decode
- if (size == 0):
+ if size == 0:
return u'', 0
result = UnicodeBuilder(size)
@@ -1025,7 +1024,7 @@
ch = s[pos]
# Non-escape characters are interpreted as Unicode ordinals
- if (ch != '\\'):
+ if ch != '\\':
result.append(unichr(ord(ch)))
pos += 1
continue
@@ -1045,9 +1044,9 @@
result.append(u'\\')
break
- if (((pos - bs) & 1) == 0 or
+ if ((pos - bs) & 1 == 0 or
pos >= size or
- (s[pos] != 'u' and s[pos] != 'U')) :
+ (s[pos] != 'u' and s[pos] != 'U')):
result.append(u'\\')
result.append(unichr(ord(s[pos])))
pos += 1
@@ -1084,7 +1083,7 @@
def unicode_encode_raw_unicode_escape(s, size, errors, errorhandler=None):
# errorhandler is not used: this function cannot cause Unicode errors
- if (size == 0):
+ if size == 0:
return ''
result = StringBuilder(size)
pos = 0
@@ -1105,7 +1104,7 @@
errorhandler=None):
if errorhandler is None:
errorhandler = raise_unicode_exception_decode
- if (size == 0):
+ if size == 0:
return u'', 0
if MAXUNICODE < 65536:
@@ -1148,7 +1147,7 @@
return result.build(), pos
def unicode_encode_unicode_internal(s, size, errors, errorhandler=None):
- if (size == 0):
+ if size == 0:
return ''
if MAXUNICODE < 65536:
From jcreigh at codespeak.net Thu Jul 1 15:07:18 2010
From: jcreigh at codespeak.net (jcreigh at codespeak.net)
Date: Thu, 1 Jul 2010 15:07:18 +0200 (CEST)
Subject: [pypy-svn] r75714 -
pypy/branch/x86-64-jit-backend/pypy/module/signal
Message-ID: <20100701130718.2F259282B9E@codespeak.net>
Author: jcreigh
Date: Thu Jul 1 15:07:16 2010
New Revision: 75714
Modified:
pypy/branch/x86-64-jit-backend/pypy/module/signal/interp_signal.py
Log:
add jit.dont_look_inside to some methods in module/signal/interp_signal.py that call external functions (fix for 64-bit)
Modified: pypy/branch/x86-64-jit-backend/pypy/module/signal/interp_signal.py
==============================================================================
--- pypy/branch/x86-64-jit-backend/pypy/module/signal/interp_signal.py (original)
+++ pypy/branch/x86-64-jit-backend/pypy/module/signal/interp_signal.py Thu Jul 1 15:07:16 2010
@@ -7,6 +7,7 @@
from pypy.translator.tool.cbuild import ExternalCompilationInfo
import py
from pypy.tool import autopath
+from pypy.rlib import jit
def setup():
for key, value in cpy_signal.__dict__.items():
@@ -159,10 +160,12 @@
return space.wrap(SIG_DFL)
getsignal.unwrap_spec = [ObjSpace, int]
+ at jit.dont_look_inside
def alarm(space, timeout):
return space.wrap(c_alarm(timeout))
alarm.unwrap_spec = [ObjSpace, int]
+ at jit.dont_look_inside
def pause(space):
c_pause()
return space.w_None
@@ -173,6 +176,7 @@
raise OperationError(space.w_ValueError,
space.wrap("signal number out of range"))
+ at jit.dont_look_inside
def signal(space, signum, w_handler):
"""
signal(sig, action) -> action
From benjamin at codespeak.net Thu Jul 1 15:18:46 2010
From: benjamin at codespeak.net (benjamin at codespeak.net)
Date: Thu, 1 Jul 2010 15:18:46 +0200 (CEST)
Subject: [pypy-svn] r75715 - pypy/branch/fast-forward/pypy/module/marshal
Message-ID: <20100701131846.683FE282B9E@codespeak.net>
Author: benjamin
Date: Thu Jul 1 15:18:44 2010
New Revision: 75715
Modified:
pypy/branch/fast-forward/pypy/module/marshal/interp_marshal.py
Log:
replace artificial marshall depth with checking for stack overflow
Modified: pypy/branch/fast-forward/pypy/module/marshal/interp_marshal.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/marshal/interp_marshal.py (original)
+++ pypy/branch/fast-forward/pypy/module/marshal/interp_marshal.py Thu Jul 1 15:18:44 2010
@@ -1,6 +1,7 @@
from pypy.interpreter.baseobjspace import ObjSpace
from pypy.interpreter.error import OperationError
from pypy.rlib.rarithmetic import intmask
+from pypy.rlib import rstackovf
from pypy.module._file.interp_file import W_File
from pypy.module._file.interp_stream import StreamErrors, wrap_streamerror
import sys
@@ -20,7 +21,7 @@
# so we have to pass the instance in, instead.
##m = Marshaller(space, writer.write, space.int_w(w_version))
m = Marshaller(space, writer, space.int_w(w_version))
- m.put_w_obj(w_data)
+ m.dump_w_obj(w_data)
finally:
writer.finished()
@@ -28,7 +29,7 @@
"""Return the string that would have been written to a file
by dump(data, file)."""
m = StringMarshaller(space, space.int_w(w_version))
- m.put_w_obj(w_data)
+ m.dump_w_obj(w_data)
return space.wrap(m.get_value())
def load(space, w_f):
@@ -41,7 +42,7 @@
reader = FileReader(space, w_f)
try:
u = Unmarshaller(space, reader)
- return u.get_w_obj(False)
+ return u.load_w_obj(False)
finally:
reader.finished()
@@ -50,7 +51,7 @@
ignored."""
space.timer.start("marshal loads")
u = StringUnmarshaller(space, w_str)
- obj = u.get_w_obj(False)
+ obj = u.load_w_obj(False)
space.timer.stop("marshal loads")
return obj
@@ -132,13 +133,6 @@
return data
-MAX_MARSHAL_DEPTH = 5000
-
-# the above is unfortunately necessary because CPython
-# relies on it without run-time checking.
-# PyPy is currently in much bigger trouble, because the
-# multimethod dispatches cause deeper stack nesting.
-
class _Base(object):
def raise_exc(self, msg):
space = self.space
@@ -153,7 +147,6 @@
## self.put = putfunc
self.writer = writer
self.version = version
- self.nesting = 0 # contribution to compatibility
self.stringtable = {}
## currently we cannot use a put that is a bound method
@@ -224,28 +217,25 @@
self.put(x)
def put_w_obj(self, w_obj):
- self.nesting += 1
- if self.nesting < MAX_MARSHAL_DEPTH:
- self.space.marshal_w(w_obj, self)
- else:
+ self.space.marshal_w(w_obj, self)
+
+ def dump_w_obj(self, w_obj):
+ try:
+ self.put_w_obj(w_obj)
+ except rstackovf.StackOverflow:
+ rstackovf.check_stack_overflow()
self._overflow()
- self.nesting -= 1
def put_tuple_w(self, typecode, lst_w):
- self.nesting += 1
self.start(typecode)
lng = len(lst_w)
self.put_int(lng)
idx = 0
space = self.space
- if self.nesting < MAX_MARSHAL_DEPTH:
- while idx < lng:
- w_obj = lst_w[idx]
- self.space.marshal_w(w_obj, self)
- idx += 1
- else:
- self._overflow()
- self.nesting -= 1
+ while idx < lng:
+ w_obj = lst_w[idx]
+ self.space.marshal_w(w_obj, self)
+ idx += 1
def _overflow(self):
self.raise_exc('object too deeply nested to marshal')
@@ -357,7 +347,6 @@
def __init__(self, space, reader):
self.space = space
self.reader = reader
- self.nesting = 0
self.stringtable_w = []
def get(self, n):
@@ -433,42 +422,39 @@
return self.get(lng)
def get_w_obj(self, allow_null):
- self.nesting += 1
space = self.space
w_ret = space.w_None # something not None
- if self.nesting < MAX_MARSHAL_DEPTH:
- tc = self.get1()
- w_ret = self._dispatch[ord(tc)](space, self, tc)
- if w_ret is None and not allow_null:
- raise OperationError(space.w_TypeError, space.wrap(
- 'NULL object in marshal data'))
- else:
- self._overflow()
- self.nesting -= 1
+ tc = self.get1()
+ w_ret = self._dispatch[ord(tc)](space, self, tc)
+ if w_ret is None and not allow_null:
+ raise OperationError(space.w_TypeError, space.wrap(
+ 'NULL object in marshal data'))
return w_ret
- # inlined version to save a nesting level
+ def load_w_obj(self, allow_null):
+ try:
+ return self.get_w_obj(allow_null)
+ except rstackovf.StackOverflow:
+ rstackovf.check_stack_overflow()
+ self._overflow()
+
+ # inlined version to save a recursion level
def get_tuple_w(self):
- self.nesting += 1
lng = self.get_lng()
res_w = [None] * lng
idx = 0
space = self.space
- w_ret = space.w_None # something not None
- if self.nesting < MAX_MARSHAL_DEPTH:
- while idx < lng:
- tc = self.get1()
- w_ret = self._dispatch[ord(tc)](space, self, tc)
- if w_ret is None:
- break
- res_w[idx] = w_ret
- idx += 1
- else:
- self._overflow()
+ w_ret = space.w_None # something not
+ while idx < lng:
+ tc = self.get1()
+ w_ret = self._dispatch[ord(tc)](space, self, tc)
+ if w_ret is None:
+ break
+ res_w[idx] = w_ret
+ idx += 1
if w_ret is None:
raise OperationError(space.w_TypeError, space.wrap(
'NULL object in marshal data'))
- self.nesting -= 1
return res_w
def get_list_w(self):
From benjamin at codespeak.net Thu Jul 1 15:30:57 2010
From: benjamin at codespeak.net (benjamin at codespeak.net)
Date: Thu, 1 Jul 2010 15:30:57 +0200 (CEST)
Subject: [pypy-svn] r75716 - in
pypy/branch/fast-forward/pypy/module/marshal: . test
Message-ID: <20100701133057.637E8282B9E@codespeak.net>
Author: benjamin
Date: Thu Jul 1 15:30:55 2010
New Revision: 75716
Modified:
pypy/branch/fast-forward/pypy/module/marshal/interp_marshal.py
pypy/branch/fast-forward/pypy/module/marshal/test/test_marshal.py
Log:
reject subclasses of builtins being marshalled
Modified: pypy/branch/fast-forward/pypy/module/marshal/interp_marshal.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/marshal/interp_marshal.py (original)
+++ pypy/branch/fast-forward/pypy/module/marshal/interp_marshal.py Thu Jul 1 15:30:55 2010
@@ -220,6 +220,12 @@
self.space.marshal_w(w_obj, self)
def dump_w_obj(self, w_obj):
+ space = self.space
+ if (space.type(w_obj).is_heaptype() and
+ not space.eq_w(space.getattr(w_obj, space.wrap("__module__")),
+ space.wrap("array"))):
+ w_err = space.wrap("only builtins can be marshaled")
+ raise OperationError(space.w_ValueError, w_err)
try:
self.put_w_obj(w_obj)
except rstackovf.StackOverflow:
Modified: pypy/branch/fast-forward/pypy/module/marshal/test/test_marshal.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/marshal/test/test_marshal.py (original)
+++ pypy/branch/fast-forward/pypy/module/marshal/test/test_marshal.py Thu Jul 1 15:30:55 2010
@@ -171,6 +171,14 @@
self.marshal_check(unichr(sys.maxunicode))
+ def test_reject_subtypes(self):
+ import marshal
+ types = (float, complex, int, long, tuple, list, dict, set, frozenset)
+ for cls in types:
+ class subtype(cls):
+ pass
+ raises(ValueError, marshal.dumps, subtype)
+
class AppTestRope(AppTestMarshal):
def setup_class(cls):
From benjamin at codespeak.net Thu Jul 1 15:32:08 2010
From: benjamin at codespeak.net (benjamin at codespeak.net)
Date: Thu, 1 Jul 2010 15:32:08 +0200 (CEST)
Subject: [pypy-svn] r75717 - pypy/branch/fast-forward/pypy/module/marshal
Message-ID: <20100701133208.C814F282B9E@codespeak.net>
Author: benjamin
Date: Thu Jul 1 15:32:07 2010
New Revision: 75717
Modified:
pypy/branch/fast-forward/pypy/module/marshal/interp_marshal.py
Log:
less hacky hack
Modified: pypy/branch/fast-forward/pypy/module/marshal/interp_marshal.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/marshal/interp_marshal.py (original)
+++ pypy/branch/fast-forward/pypy/module/marshal/interp_marshal.py Thu Jul 1 15:32:07 2010
@@ -222,8 +222,7 @@
def dump_w_obj(self, w_obj):
space = self.space
if (space.type(w_obj).is_heaptype() and
- not space.eq_w(space.getattr(w_obj, space.wrap("__module__")),
- space.wrap("array"))):
+ space.lookup(w_obj, "__buffer__") is None):
w_err = space.wrap("only builtins can be marshaled")
raise OperationError(space.w_ValueError, w_err)
try:
From antocuni at codespeak.net Thu Jul 1 16:01:39 2010
From: antocuni at codespeak.net (antocuni at codespeak.net)
Date: Thu, 1 Jul 2010 16:01:39 +0200 (CEST)
Subject: [pypy-svn] r75718 - pypy/trunk/dotviewer
Message-ID: <20100701140139.19772282B9E@codespeak.net>
Author: antocuni
Date: Thu Jul 1 16:01:38 2010
New Revision: 75718
Modified:
pypy/trunk/dotviewer/sshgraphserver.py
Log:
explicitly disable the "control master" option. Else, if ControlMaster is
automatically enabled (e.g. by an option in .ssh/config), and there is already
an active connection, the port forwarding is not setup
Modified: pypy/trunk/dotviewer/sshgraphserver.py
==============================================================================
--- pypy/trunk/dotviewer/sshgraphserver.py (original)
+++ pypy/trunk/dotviewer/sshgraphserver.py Thu Jul 1 16:01:38 2010
@@ -21,7 +21,7 @@
remoteport = random.randrange(10000, 20000)
# ^^^ and just hope there is no conflict
- args = ['ssh', '-C', '-R%d:127.0.0.1:%d' % (remoteport, localport)]
+ args = ['ssh', '-S', 'none', '-C', '-R%d:127.0.0.1:%d' % (remoteport, localport)]
args = args + sshargs + ['python -u -c "exec input()"']
print ' '.join(args[:-1])
p = subprocess.Popen(args, bufsize=0,
From afa at codespeak.net Thu Jul 1 16:27:23 2010
From: afa at codespeak.net (afa at codespeak.net)
Date: Thu, 1 Jul 2010 16:27:23 +0200 (CEST)
Subject: [pypy-svn] r75719 - in
pypy/branch/interplevel-codecs/pypy/module/_codecs: . test
Message-ID: <20100701142723.6030F282B9E@codespeak.net>
Author: afa
Date: Thu Jul 1 16:27:21 2010
New Revision: 75719
Modified:
pypy/branch/interplevel-codecs/pypy/module/_codecs/interp_codecs.py
pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py
Log:
Avoid buffer overrun in append_slice(); Test and fix.
Modified: pypy/branch/interplevel-codecs/pypy/module/_codecs/interp_codecs.py
==============================================================================
--- pypy/branch/interplevel-codecs/pypy/module/_codecs/interp_codecs.py (original)
+++ pypy/branch/interplevel-codecs/pypy/module/_codecs/interp_codecs.py Thu Jul 1 16:27:21 2010
@@ -232,10 +232,11 @@
else:
builder.append(u"\\x")
zeros = 2
- nb = zeros + 2 - len(num) # num starts with '0x'
+ lnum = len(num)
+ nb = zeros + 2 - lnum # num starts with '0x'
if nb > 0:
builder.append_multiple_char(u'0', nb)
- builder.append_slice(unicode(num), 2, 8)
+ builder.append_slice(unicode(num), 2, lnum)
pos += 1
return space.newtuple([space.wrap(builder.build()), w_end])
else:
Modified: pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py
==============================================================================
--- pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py (original)
+++ pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py Thu Jul 1 16:27:21 2010
@@ -460,6 +460,9 @@
assert '\xff'.decode('utf-7', 'ignore') == ''
assert '\x00'.decode('unicode-internal', 'ignore') == ''
+ def test_backslahreplace(self):
+ assert u'a\xac\u1234\u20ac\u8000'.encode('ascii', 'backslashreplace') == 'a\\xac\u1234\u20ac\u8000'
+
def test_badhandler(self):
import codecs
results = ( 42, u"foo", (1,2,3), (u"foo", 1, 3), (u"foo", None), (u"foo",), ("foo", 1, 3), ("foo", None), ("foo",) )
From afa at codespeak.net Thu Jul 1 16:29:21 2010
From: afa at codespeak.net (afa at codespeak.net)
Date: Thu, 1 Jul 2010 16:29:21 +0200 (CEST)
Subject: [pypy-svn] r75720 - in pypy/branch/interplevel-codecs/pypy:
module/_codecs/test rlib
Message-ID: <20100701142921.266C1282B9E@codespeak.net>
Author: afa
Date: Thu Jul 1 16:29:19 2010
New Revision: 75720
Modified:
pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py
pypy/branch/interplevel-codecs/pypy/rlib/runicode.py
Log:
Decode utf-7 characters whenever possible,
to avoid integer overflow when the "inShift" excursion is too long.
Modified: pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py
==============================================================================
--- pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py (original)
+++ pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py Thu Jul 1 16:29:19 2010
@@ -541,6 +541,9 @@
assert exc.start == 0
assert exc.end == 3
+ def test_utf7_surrogate(self):
+ raises(UnicodeDecodeError, '+3ADYAA-'.decode, 'utf-7')
+
def test_utf_16_encode_decode(self):
import codecs
x = u'123abc'
Modified: pypy/branch/interplevel-codecs/pypy/rlib/runicode.py
==============================================================================
--- pypy/branch/interplevel-codecs/pypy/rlib/runicode.py (original)
+++ pypy/branch/interplevel-codecs/pypy/rlib/runicode.py Thu Jul 1 16:29:19 2010
@@ -471,6 +471,32 @@
bits -= 6
return bits
+def _utf7_DECODE(s, result, errorhandler, errors,
+ pos, charsleft, bitsleft, surrogate):
+ while bitsleft >= 16:
+ outCh = (charsleft >> (bitsleft-16)) & 0xffff
+ bitsleft -= 16
+
+ if surrogate:
+ ## We have already generated an error for the high
+ ## surrogate so let's not bother seeing if the low
+ ## surrogate is correct or not
+ surrogate = False
+ elif 0xDC00 <= outCh <= 0xDFFF:
+ ## This is a surrogate pair. Unfortunately we can't
+ ## represent it in a 16-bit character
+ surrogate = True
+ msg = "code pairs are not supported"
+ res, pos = errorhandler(errors, 'utf-7',
+ msg, s, pos-1, pos)
+ result.append(res)
+ bitsleft = 0
+ break
+ else:
+ result.append(unichr(outCh))
+ return pos, charsleft, bitsleft, surrogate
+
+
def str_decode_utf_7(s, size, errors, final=False,
errorhandler=None):
if errorhandler is None:
@@ -495,27 +521,9 @@
inShift = 0
pos += 1
- while bitsleft >= 16:
- outCh = (charsleft >> (bitsleft-16)) & 0xffff
- bitsleft -= 16
-
- if surrogate:
- ## We have already generated an error for the high
- ## surrogate so let's not bother seeing if the low
- ## surrogate is correct or not
- surrogate = False
- elif 0xDC00 <= outCh <= 0xDFFF:
- ## This is a surrogate pair. Unfortunately we can't
- ## represent it in a 16-bit character
- surrogate = True
- msg = "code pairs are not supported"
- res, pos = errorhandler(errors, 'utf-7',
- msg, s, pos-1, pos)
- result.append(res)
- bitsleft = 0
- break
- else:
- result.append(unichr(outCh))
+ pos, charsleft, bitsleft, surrogate = _utf7_DECODE(
+ s, result, errorhandler, errors,
+ pos, charsleft, bitsleft, surrogate)
if bitsleft >= 6:
## The shift sequence has a partial character in it. If
## bitsleft < 6 then we could just classify it as padding
@@ -544,6 +552,10 @@
charsleft = (charsleft << 6) | _utf7_FROM_BASE64(ch)
bitsleft += 6
pos += 1
+
+ pos, charsleft, bitsleft, surrogate = _utf7_DECODE(
+ s, result, errorhandler, errors,
+ pos, charsleft, bitsleft, surrogate)
elif ch == '+':
startinpos = pos
pos += 1
From benjamin at codespeak.net Thu Jul 1 18:23:34 2010
From: benjamin at codespeak.net (benjamin at codespeak.net)
Date: Thu, 1 Jul 2010 18:23:34 +0200 (CEST)
Subject: [pypy-svn] r75721 - in pypy/branch/fast-forward/pypy/module:
marshal/test math
Message-ID: <20100701162334.92ED2282B9E@codespeak.net>
Author: benjamin
Date: Thu Jul 1 18:23:31 2010
New Revision: 75721
Modified:
pypy/branch/fast-forward/pypy/module/marshal/test/test_marshal.py
pypy/branch/fast-forward/pypy/module/math/interp_math.py
Log:
remove sys import
Modified: pypy/branch/fast-forward/pypy/module/marshal/test/test_marshal.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/marshal/test/test_marshal.py (original)
+++ pypy/branch/fast-forward/pypy/module/marshal/test/test_marshal.py Thu Jul 1 18:23:31 2010
@@ -2,7 +2,6 @@
def make_check(space):
return space.appexec([], """():
- import sys
import marshal, StringIO
def marshal_check(case):
s = marshal.dumps(case)
Modified: pypy/branch/fast-forward/pypy/module/math/interp_math.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/math/interp_math.py (original)
+++ pypy/branch/fast-forward/pypy/module/math/interp_math.py Thu Jul 1 18:23:31 2010
@@ -46,6 +46,13 @@
return space.wrap(r)
math2._annspecialcase_ = 'specialize:arg(1)'
+def copysign(space, x, y):
+ """copysign(x, y)
+
+ Return x with the sign of y."""
+ return math2(space, math.copysign, x, y)
+copysign.unwrap_spec = [ObjSpace, float, float]
+
def pow(space, x, y):
"""pow(x,y)
From benjamin at codespeak.net Thu Jul 1 18:28:57 2010
From: benjamin at codespeak.net (benjamin at codespeak.net)
Date: Thu, 1 Jul 2010 18:28:57 +0200 (CEST)
Subject: [pypy-svn] r75722 - in pypy/branch/fast-forward/pypy: module/math
objspace/std rlib/rstruct rpython/lltypesystem/module
Message-ID: <20100701162857.F10E8282B9E@codespeak.net>
Author: benjamin
Date: Thu Jul 1 18:28:56 2010
New Revision: 75722
Modified:
pypy/branch/fast-forward/pypy/module/math/interp_math.py
pypy/branch/fast-forward/pypy/objspace/std/marshal_impl.py
pypy/branch/fast-forward/pypy/rlib/rstruct/ieee.py
pypy/branch/fast-forward/pypy/rpython/lltypesystem/module/ll_math.py
Log:
revert unintended math changes
Modified: pypy/branch/fast-forward/pypy/module/math/interp_math.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/math/interp_math.py (original)
+++ pypy/branch/fast-forward/pypy/module/math/interp_math.py Thu Jul 1 18:28:56 2010
@@ -46,13 +46,6 @@
return space.wrap(r)
math2._annspecialcase_ = 'specialize:arg(1)'
-def copysign(space, x, y):
- """copysign(x, y)
-
- Return x with the sign of y."""
- return math2(space, math.copysign, x, y)
-copysign.unwrap_spec = [ObjSpace, float, float]
-
def pow(space, x, y):
"""pow(x,y)
Modified: pypy/branch/fast-forward/pypy/objspace/std/marshal_impl.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/marshal_impl.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/marshal_impl.py Thu Jul 1 18:28:56 2010
@@ -169,11 +169,11 @@
def pack_float(f):
result = []
- ieee.pack_float(result, f, 8, False)
+ ieee.pack_float8(result, f)
return ''.join(result)
def unpack_float(s):
- return ieee.unpack_float(s, False)
+ return ieee.unpack_float8(s)
def marshal_w__Float(space, w_float, m):
if m.version > 1:
Modified: pypy/branch/fast-forward/pypy/rlib/rstruct/ieee.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rlib/rstruct/ieee.py (original)
+++ pypy/branch/fast-forward/pypy/rlib/rstruct/ieee.py Thu Jul 1 18:28:56 2010
@@ -3,7 +3,124 @@
"""
import math
-from pypy.rlib.rarithmetic import r_longlong, isinf, isnan, INFINITY, NAN
+from pypy.rlib.rarithmetic import r_longlong, r_ulonglong, isinf, isnan, INFINITY, NAN
+
+
+def py3round(x):
+ """Python 3 round function semantics, in Python 2 code.
+
+ We want to round x to the nearest int, but:
+ - return an int, not a float
+ - do round-half-to-even, not round-half-away-from-zero.
+
+ We assume that x is finite and nonnegative.
+
+ """
+ int_part = r_ulonglong(x)
+ frac_part = x - int_part
+ if frac_part > 0.5 or frac_part == 0.5 and (int_part & 1):
+ int_part += 1
+ return int_part
+
+
+def float_pack(x, size):
+ """Convert a Python float x into a 64-bit unsigned integer
+ with the same byte representation."""
+
+ if size == 8:
+ MIN_EXP = -1021 # = sys.float_info.min_exp
+ MAX_EXP = 1024 # = sys.float_info.max_exp
+ MANT_DIG = 53 # = sys.float_info.mant_dig
+ elif size == 4:
+ MIN_EXP = -125 # C's FLT_MIN_EXP
+ MAX_EXP = 128 # FLT_MAX_EXP
+ MANT_DIG = 24 # FLT_MANT_DIG
+ else:
+ raise ValueError("invalid size value")
+
+ sign = math.copysign(1.0, x) < 0.0
+ if isinf(x):
+ mant = 0
+ exp = MAX_EXP - MIN_EXP + 2
+ elif isnan(x):
+ mant = 1 << (MANT_DIG-2)
+ exp = MAX_EXP - MIN_EXP + 2
+ elif x == 0.0:
+ mant = 0
+ exp = 0
+ else:
+ m, e = math.frexp(abs(x))
+ if e < MIN_EXP:
+ # Subnormal result (or possibly smallest normal, after rounding).
+ if e < MIN_EXP - MANT_DIG:
+ # Underflow to zero; not possible when size == 8.
+ mant = r_ulonglong(0)
+ else:
+ # For size == 8, can substitute 'int' for 'py3round', both
+ # here and below: the argument will always be integral.
+ mant = py3round(m * (1 << e - (MIN_EXP - MANT_DIG)))
+ exp = 0
+ elif e > MAX_EXP:
+ # Overflow to infinity: not possible when size == 8.
+ raise OverflowError("float too large to pack with f format")
+ else:
+ mant = py3round(m * (1 << MANT_DIG))
+ exp = e - MIN_EXP
+ # N.B. It's important that the + mant really is an addition, not just a
+ # bitwise 'or'. In extreme cases, mant may have MANT_DIG+1 significant
+ # bits, as a result of rounding.
+ return ((sign << 8*size - 1) | (exp << MANT_DIG - 1)) + mant
+
+
+def float_unpack(Q, size):
+ """Convert a 32-bit or 64-bit integer created
+ by float_pack into a Python float."""
+
+ if size == 8:
+ MIN_EXP = -1021 # = sys.float_info.min_exp
+ MAX_EXP = 1024 # = sys.float_info.max_exp
+ MANT_DIG = 53 # = sys.float_info.mant_dig
+ elif size == 4:
+ MIN_EXP = -125 # C's FLT_MIN_EXP
+ MAX_EXP = 128 # FLT_MAX_EXP
+ MANT_DIG = 24 # FLT_MANT_DIG
+ else:
+ raise ValueError("invalid size value")
+
+ # extract pieces
+ sign = Q >> 8*size - 1
+ Q -= sign << 8*size - 1
+ exp = Q >> MANT_DIG - 1
+ Q -= exp << MANT_DIG - 1
+ mant = Q
+
+ if exp == MAX_EXP - MIN_EXP + 2:
+ # nan or infinity
+ result = float('nan') if mant else float('inf')
+ elif exp == 0:
+ # subnormal or zero
+ result = math.ldexp(float(mant), MIN_EXP - MANT_DIG)
+ else:
+ # normal
+ exp -= 1
+ mant += 1 << MANT_DIG - 1
+ result = math.ldexp(float(mant), exp + MIN_EXP - MANT_DIG)
+ return -result if sign else result
+
+
+def pack_float8(result, x):
+ unsigned = float_pack(x, 8)
+ for i in range(8):
+ result.append(chr((unsigned >> (i * 8)) & 0xFF))
+
+
+def unpack_float8(s):
+ unsigned = r_ulonglong(0)
+ for i in range(8):
+ unsigned |= ord(s[7 - i]) << (i * 8)
+ print unsigned
+ return float_unpack(unsigned, 8)
+
def pack_float(result, number, size, bigendian):
"""Append to 'result' the 'size' characters of the 32-bit or 64-bit
Modified: pypy/branch/fast-forward/pypy/rpython/lltypesystem/module/ll_math.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rpython/lltypesystem/module/ll_math.py (original)
+++ pypy/branch/fast-forward/pypy/rpython/lltypesystem/module/ll_math.py Thu Jul 1 18:28:56 2010
@@ -36,6 +36,8 @@
math_fmod = llexternal('fmod', [rffi.DOUBLE, rffi.DOUBLE], rffi.DOUBLE)
math_hypot = llexternal(underscore + 'hypot',
[rffi.DOUBLE, rffi.DOUBLE], rffi.DOUBLE)
+math_isnan = llexternal('isnan', [rffi.DOUBLE], rffi.INT)
+math_isinf = llexternal('isinf', [rffi.DOUBLE], rffi.INT)
# ____________________________________________________________
#
From afa at codespeak.net Thu Jul 1 18:35:55 2010
From: afa at codespeak.net (afa at codespeak.net)
Date: Thu, 1 Jul 2010 18:35:55 +0200 (CEST)
Subject: [pypy-svn] r75723 - in pypy/branch/interplevel-codecs/pypy:
module/_codecs/test rlib
Message-ID: <20100701163555.85DD2282B9E@codespeak.net>
Author: afa
Date: Thu Jul 1 18:35:53 2010
New Revision: 75723
Modified:
pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py
pypy/branch/interplevel-codecs/pypy/rlib/runicode.py
Log:
fix encode_charmap with 'replace': the replacement character must be translated again.
Modified: pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py
==============================================================================
--- pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py (original)
+++ pypy/branch/interplevel-codecs/pypy/module/_codecs/test/test_codecs.py Thu Jul 1 18:35:53 2010
@@ -526,6 +526,14 @@
def test_charmap_encode(self):
assert 'xxx'.encode('charmap') == 'xxx'
+ def test_charmap_encode_replace(self):
+ charmap = dict([ (ord(c), 2*c.upper()) for c in "abcdefgh"])
+ charmap[ord("?")] = "XYZ"
+ import codecs
+ sin = u"abcDEF"
+ sout = codecs.charmap_encode(sin, "replace", charmap)[0]
+ assert sout == "AABBCCXYZXYZXYZ"
+
def test_charmap_decode_2(self):
assert 'foo'.decode('charmap') == 'foo'
Modified: pypy/branch/interplevel-codecs/pypy/rlib/runicode.py
==============================================================================
--- pypy/branch/interplevel-codecs/pypy/rlib/runicode.py (original)
+++ pypy/branch/interplevel-codecs/pypy/rlib/runicode.py Thu Jul 1 18:35:53 2010
@@ -779,10 +779,17 @@
c = mapping.get(ch, '')
if len(c) == 0:
- r, pos = errorhandler(errors, "charmap",
- "character maps to
Author: benjamin
Date: Fri Jul 2 00:08:48 2010
New Revision: 75747
Modified:
pypy/branch/fast-forward/pypy/module/math/__init__.py
pypy/branch/fast-forward/pypy/module/math/interp_math.py
Log:
add copysign, isinf, and isnan
Modified: pypy/branch/fast-forward/pypy/module/math/__init__.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/math/__init__.py (original)
+++ pypy/branch/fast-forward/pypy/module/math/__init__.py Fri Jul 2 00:08:48 2010
@@ -11,6 +11,7 @@
'pi' : 'interp_math.get(space).w_pi',
'pow' : 'interp_math.pow',
'cosh' : 'interp_math.cosh',
+ 'copysign' : 'interp_math.copysign',
'ldexp' : 'interp_math.ldexp',
'hypot' : 'interp_math.hypot',
'tan' : 'interp_math.tan',
@@ -34,5 +35,7 @@
'modf' : 'interp_math.modf',
'exp' : 'interp_math.exp',
'acos' : 'interp_math.acos',
+ 'isinf' : 'interp_math.isinf',
+ 'isnan' : 'interp_math.isnan',
}
Modified: pypy/branch/fast-forward/pypy/module/math/interp_math.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/math/interp_math.py (original)
+++ pypy/branch/fast-forward/pypy/module/math/interp_math.py Fri Jul 2 00:08:48 2010
@@ -1,5 +1,6 @@
-
import math
+
+from pypy.rlib import rarithmetic
from pypy.interpreter.error import OperationError
from pypy.interpreter.gateway import ObjSpace, W_Root, NoneNotWrapped
@@ -46,6 +47,22 @@
return space.wrap(r)
math2._annspecialcase_ = 'specialize:arg(1)'
+def copysign(space, x, y):
+ """Return x with the sign of y."""
+ # No exceptions possible.
+ return space.wrap(rarithmetic.copysign(x, y))
+copysign.unwrap_spec = [ObjSpace, float, float]
+
+def isinf(space, x):
+ """Return True if x is infinity."""
+ return space.wrap(rarithmetic.isinf(x))
+isinf.unwrap_spec = [ObjSpace, float, float]
+
+def isnan(space, x):
+ """Return True if x is not a number."""
+ return space.wrap(rarithmetic.isnan(x))
+isnan.unwrap_spec = [ObjSpace, float, float]
+
def pow(space, x, y):
"""pow(x,y)
From benjamin at codespeak.net Fri Jul 2 00:16:04 2010
From: benjamin at codespeak.net (benjamin at codespeak.net)
Date: Fri, 2 Jul 2010 00:16:04 +0200 (CEST)
Subject: [pypy-svn] r75748 - pypy/branch/fast-forward/pypy/module/math
Message-ID: <20100701221604.42B63282B9E@codespeak.net>
Author: benjamin
Date: Fri Jul 2 00:16:02 2010
New Revision: 75748
Modified:
pypy/branch/fast-forward/pypy/module/math/interp_math.py
Log:
fix unwrap spec
Modified: pypy/branch/fast-forward/pypy/module/math/interp_math.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/math/interp_math.py (original)
+++ pypy/branch/fast-forward/pypy/module/math/interp_math.py Fri Jul 2 00:16:02 2010
@@ -56,12 +56,12 @@
def isinf(space, x):
"""Return True if x is infinity."""
return space.wrap(rarithmetic.isinf(x))
-isinf.unwrap_spec = [ObjSpace, float, float]
+isinf.unwrap_spec = [ObjSpace, float]
def isnan(space, x):
"""Return True if x is not a number."""
return space.wrap(rarithmetic.isnan(x))
-isnan.unwrap_spec = [ObjSpace, float, float]
+isnan.unwrap_spec = [ObjSpace, float]
def pow(space, x, y):
"""pow(x,y)
From getxsick at codespeak.net Fri Jul 2 00:17:42 2010
From: getxsick at codespeak.net (getxsick at codespeak.net)
Date: Fri, 2 Jul 2010 00:17:42 +0200 (CEST)
Subject: [pypy-svn] r75749 - pypy/build/ubuntu/trunk/debian
Message-ID: <20100701221742.91863282B9E@codespeak.net>
Author: getxsick
Date: Fri Jul 2 00:17:41 2010
New Revision: 75749
Modified:
pypy/build/ubuntu/trunk/debian/Makefile.in
Log:
pypy-c is pypy-c. not testing_1 anymore
Modified: pypy/build/ubuntu/trunk/debian/Makefile.in
==============================================================================
--- pypy/build/ubuntu/trunk/debian/Makefile.in (original)
+++ pypy/build/ubuntu/trunk/debian/Makefile.in Fri Jul 2 00:17:41 2010
@@ -44,7 +44,7 @@
mkdir $(TMPDIR)
PYPY_USESSION_BASENAME='-' $(TRANSLATE) $(TRANSLATEOPTS) $(TARGET) $(TARGETOPTS)
make -C $(TMPDIR)/usession-0/testing_1
- install -D $(TMPDIR)/usession-0/testing_1/testing_1 $@
+ install -D $(TMPDIR)/usession-0/testing_1/pypy-c $@
clean:
rm -rf bin
From getxsick at codespeak.net Fri Jul 2 00:21:22 2010
From: getxsick at codespeak.net (getxsick at codespeak.net)
Date: Fri, 2 Jul 2010 00:21:22 +0200 (CEST)
Subject: [pypy-svn] r75750 - pypy/build/ubuntu/1.3.0/debian
Message-ID: <20100701222122.4B0E8282B9E@codespeak.net>
Author: getxsick
Date: Fri Jul 2 00:21:20 2010
New Revision: 75750
Modified:
pypy/build/ubuntu/1.3.0/debian/Makefile.in
Log:
same as r75749
Modified: pypy/build/ubuntu/1.3.0/debian/Makefile.in
==============================================================================
--- pypy/build/ubuntu/1.3.0/debian/Makefile.in (original)
+++ pypy/build/ubuntu/1.3.0/debian/Makefile.in Fri Jul 2 00:21:20 2010
@@ -44,7 +44,7 @@
mkdir $(TMPDIR)
PYPY_USESSION_BASENAME='-' $(TRANSLATE) $(TRANSLATEOPTS) $(TARGET) $(TARGETOPTS)
make -C $(TMPDIR)/usession-0/testing_1
- install -D $(TMPDIR)/usession-0/testing_1/testing_1 $@
+ install -D $(TMPDIR)/usession-0/testing_1/pypy-c $@
clean:
rm -rf bin
From benjamin at codespeak.net Fri Jul 2 01:42:43 2010
From: benjamin at codespeak.net (benjamin at codespeak.net)
Date: Fri, 2 Jul 2010 01:42:43 +0200 (CEST)
Subject: [pypy-svn] r75751 - in pypy/branch/fast-forward/pypy/objspace/std:
. test
Message-ID: <20100701234243.7BE2F282B9E@codespeak.net>
Author: benjamin
Date: Fri Jul 2 01:42:41 2010
New Revision: 75751
Modified:
pypy/branch/fast-forward/pypy/objspace/std/floattype.py
pypy/branch/fast-forward/pypy/objspace/std/test/test_floatobject.py
Log:
fake float.__getformat__
Modified: pypy/branch/fast-forward/pypy/objspace/std/floattype.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/floattype.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/floattype.py Fri Jul 2 01:42:41 2010
@@ -1,4 +1,5 @@
from pypy.interpreter import gateway
+from pypy.interpreter.baseobjspace import ObjSpace, W_Root
from pypy.interpreter.error import OperationError
from pypy.objspace.std.stdtypedef import StdTypeDef
from pypy.objspace.std.strutil import ParseStringError
@@ -35,6 +36,18 @@
W_FloatObject.__init__(w_obj, value)
return w_obj
+
+_float_format = float.__getformat__("float")
+_double_format = float.__getformat__("double")
+def descr___getformat__(space, w_cls, kind):
+ if kind == "float":
+ return space.wrap(_float_format)
+ elif kind == "double":
+ return space.wrap(_double_format)
+ raise OperationError(space.w_ValueError,
+ space.wrap("only float and double are valid"))
+
+
# ____________________________________________________________
float_typedef = StdTypeDef("float",
@@ -42,4 +55,7 @@
Convert a string or number to a floating point number, if possible.''',
__new__ = gateway.interp2app(descr__new__),
+ __getformat__ = gateway.interp2app(descr___getformat__,
+ unwrap_spec=[ObjSpace, W_Root, str],
+ as_classmethod=True),
)
Modified: pypy/branch/fast-forward/pypy/objspace/std/test/test_floatobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/test/test_floatobject.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/test/test_floatobject.py Fri Jul 2 01:42:41 2010
@@ -317,6 +317,11 @@
assert not (nan < x)
assert not (nan > x)
+ def test___getformat__(self):
+ float.__getformat__("float")
+ float.__getformat__("double")
+ raises(ValueError, float.__getformat__, "random")
+
def test_multimethod_slice(self):
assert 5 .__add__(3.14) is NotImplemented
assert 3.25 .__add__(5) == 8.25
From benjamin at codespeak.net Fri Jul 2 02:05:54 2010
From: benjamin at codespeak.net (benjamin at codespeak.net)
Date: Fri, 2 Jul 2010 02:05:54 +0200 (CEST)
Subject: [pypy-svn] r75752 - in pypy/branch/fast-forward/pypy: interpreter
module/math objspace/flow objspace/std objspace/std/test
Message-ID: <20100702000554.28FF4282B9E@codespeak.net>
Author: benjamin
Date: Fri Jul 2 02:05:52 2010
New Revision: 75752
Modified:
pypy/branch/fast-forward/pypy/interpreter/baseobjspace.py
pypy/branch/fast-forward/pypy/module/math/__init__.py
pypy/branch/fast-forward/pypy/module/math/interp_math.py
pypy/branch/fast-forward/pypy/objspace/flow/operation.py
pypy/branch/fast-forward/pypy/objspace/std/builtinshortcut.py
pypy/branch/fast-forward/pypy/objspace/std/floatobject.py
pypy/branch/fast-forward/pypy/objspace/std/intobject.py
pypy/branch/fast-forward/pypy/objspace/std/longobject.py
pypy/branch/fast-forward/pypy/objspace/std/test/test_floatobject.py
pypy/branch/fast-forward/pypy/objspace/std/test/test_intobject.py
pypy/branch/fast-forward/pypy/objspace/std/test/test_longobject.py
Log:
add math.trunc and support for floats, ints, and longs
Modified: pypy/branch/fast-forward/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/baseobjspace.py (original)
+++ pypy/branch/fast-forward/pypy/interpreter/baseobjspace.py Fri Jul 2 02:05:52 2010
@@ -1213,6 +1213,7 @@
('getslice', 'getslice', 3, ['__getslice__']),
('setslice', 'setslice', 4, ['__setslice__']),
('delslice', 'delslice', 3, ['__delslice__']),
+ ('trunc', 'trunc', 1, ['__trunc__']),
('pos', 'pos', 1, ['__pos__']),
('neg', 'neg', 1, ['__neg__']),
('nonzero', 'truth', 1, ['__nonzero__']),
Modified: pypy/branch/fast-forward/pypy/module/math/__init__.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/math/__init__.py (original)
+++ pypy/branch/fast-forward/pypy/module/math/__init__.py Fri Jul 2 02:05:52 2010
@@ -37,5 +37,6 @@
'acos' : 'interp_math.acos',
'isinf' : 'interp_math.isinf',
'isnan' : 'interp_math.isnan',
+ 'trunc' : 'interp_math.trunc',
}
Modified: pypy/branch/fast-forward/pypy/module/math/interp_math.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/math/interp_math.py (original)
+++ pypy/branch/fast-forward/pypy/module/math/interp_math.py Fri Jul 2 02:05:52 2010
@@ -47,6 +47,11 @@
return space.wrap(r)
math2._annspecialcase_ = 'specialize:arg(1)'
+def trunc(space, w_x):
+ """Truncate x."""
+ return space.trunc(w_x)
+trunc.unwrap_spec = [ObjSpace, W_Root]
+
def copysign(space, x, y):
"""Return x with the sign of y."""
# No exceptions possible.
Modified: pypy/branch/fast-forward/pypy/objspace/flow/operation.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/flow/operation.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/flow/operation.py Fri Jul 2 02:05:52 2010
@@ -188,6 +188,7 @@
('nonzero', operator.truth),
('is_true', bool),
('is_true', operator.truth),
+ ('trunc', unsupported),
('abs' , abs),
('hex', hex),
('oct', oct),
Modified: pypy/branch/fast-forward/pypy/objspace/std/builtinshortcut.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/builtinshortcut.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/builtinshortcut.py Fri Jul 2 02:05:52 2010
@@ -35,7 +35,7 @@
'setattr', 'delattr', 'userdel', # mostly for non-builtins
'get', 'set', 'delete', # uncommon (except on functions)
'getslice', 'setslice', 'delslice', # see below
- 'delitem', # rare stuff?
+ 'delitem', 'trunc', # rare stuff?
'abs', 'hex', 'oct', # rare stuff?
'pos', 'divmod', 'cmp', # rare stuff?
'float', 'long', 'coerce', # rare stuff?
Modified: pypy/branch/fast-forward/pypy/objspace/std/floatobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/floatobject.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/floatobject.py Fri Jul 2 02:05:52 2010
@@ -8,7 +8,7 @@
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.objspace.std.longobject import W_LongObject
from pypy.rlib.rarithmetic import ovfcheck_float_to_int, intmask, isinf, isnan
-from pypy.rlib.rarithmetic import formatd, LONG_BIT
+from pypy.rlib.rarithmetic import formatd, LONG_BIT, FL_MAXINT, FL_MININT
from pypy.rlib.rbigint import rbigint
from pypy.tool.sourcetools import func_with_new_name
@@ -73,6 +73,15 @@
except OverflowError:
raise OperationError(space.w_OverflowError,
space.wrap("cannot convert float infinity to long"))
+def trunc__Float(space, w_floatobj):
+ whole = math.modf(w_floatobj.floatval)[1]
+ if FL_MININT < whole < FL_MAXINT:
+ return space.newint(int(whole))
+ try:
+ return W_LongObject.fromfloat(w_floatobj.floatval)
+ except OverflowError:
+ raise OperationError(space.w_OverflowError,
+ space.wrap("cannot convert infinity to long"))
def float_w__Float(space, w_float):
return w_float.floatval
Modified: pypy/branch/fast-forward/pypy/objspace/std/intobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/intobject.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/intobject.py Fri Jul 2 02:05:52 2010
@@ -305,6 +305,7 @@
return wrapint(space, a)
get_integer = int__Int
pos__Int = int__Int
+trunc__Int = int__Int
def index__Int(space, w_int1):
return get_integer(space, w_int1)
Modified: pypy/branch/fast-forward/pypy/objspace/std/longobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/longobject.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/longobject.py Fri Jul 2 02:05:52 2010
@@ -77,6 +77,7 @@
return w_long1
l = w_long1.num
return W_LongObject(l)
+trunc__Long = long__Long
def long__Int(space, w_intobj):
return W_LongObject.fromint(space, w_intobj.intval)
Modified: pypy/branch/fast-forward/pypy/objspace/std/test/test_floatobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/test/test_floatobject.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/test/test_floatobject.py Fri Jul 2 02:05:52 2010
@@ -322,6 +322,17 @@
float.__getformat__("double")
raises(ValueError, float.__getformat__, "random")
+ def test_trunc(self):
+ import math
+ assert math.trunc(1.5) == 1
+ assert math.trunc(-1.5) == -1
+ assert math.trunc(1.999999) == 1
+ assert math.trunc(-1.999999) == -1
+ assert math.trunc(-0.999999) == -0
+ assert math.trunc(-100.999) == -100
+ raises(OverflowError, math.trunc, float("inf"))
+
+
def test_multimethod_slice(self):
assert 5 .__add__(3.14) is NotImplemented
assert 3.25 .__add__(5) == 8.25
Modified: pypy/branch/fast-forward/pypy/objspace/std/test/test_intobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/test/test_intobject.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/test/test_intobject.py Fri Jul 2 02:05:52 2010
@@ -285,6 +285,11 @@
class AppTestInt:
+ def test_trunc(self):
+ import math
+ assert math.trunc(1) == 1
+ assert math.trunc(-1) == -1
+
def test_int_callable(self):
assert 43 == int(43)
Modified: pypy/branch/fast-forward/pypy/objspace/std/test/test_longobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/test/test_longobject.py (original)
+++ pypy/branch/fast-forward/pypy/objspace/std/test/test_longobject.py Fri Jul 2 02:05:52 2010
@@ -40,6 +40,12 @@
class AppTestLong:
+
+ def test_trunc(self):
+ import math
+ assert math.trunc(1L) == 1L
+ assert math.trunc(-1L) == -1L
+
def test_add(self):
assert int(123L + 12443L) == 123 + 12443
assert -20 + 2 + 3L + True == -14L
From antocuni at codespeak.net Fri Jul 2 10:54:25 2010
From: antocuni at codespeak.net (antocuni at codespeak.net)
Date: Fri, 2 Jul 2010 10:54:25 +0200 (CEST)
Subject: [pypy-svn] r75753 - pypy/trunk/pypy/tool/release/test
Message-ID: <20100702085425.1BDA6282B9E@codespeak.net>
Author: antocuni
Date: Fri Jul 2 10:54:22 2010
New Revision: 75753
Modified:
pypy/trunk/pypy/tool/release/test/test_package.py
Log:
fix test_package, for the case when we run the test without having run a translation first
Modified: pypy/trunk/pypy/tool/release/test/test_package.py
==============================================================================
--- pypy/trunk/pypy/tool/release/test/test_package.py (original)
+++ pypy/trunk/pypy/tool/release/test/test_package.py Fri Jul 2 10:54:22 2010
@@ -26,9 +26,16 @@
assert prefix.join('README').check()
th = tarfile.open(str(builddir.join('test.tar.bz2')))
assert th.getmember('test/lib_pypy/syslog.py')
- assert th.getmember('test/include/Python.h')
- assert th.getmember('test/include/modsupport.inl')
- assert th.getmember('test/include/pypy_decl.h')
+
+ # the headers file could be not there, because they are copied into
+ # trunk/include only during translation
+ includedir = py.path.local(pypydir).dirpath().join('include')
+ def check_include(name):
+ if includedir.join(name).check(file=True):
+ assert th.getmember('test/include/%s' % name)
+ check_include('Python.h')
+ check_include('modsupport.inl')
+ check_include('pypy_decl.h')
finally:
if fake_pypy_c:
pypy_c.remove()
From antocuni at codespeak.net Fri Jul 2 11:37:19 2010
From: antocuni at codespeak.net (antocuni at codespeak.net)
Date: Fri, 2 Jul 2010 11:37:19 +0200 (CEST)
Subject: [pypy-svn] r75754 - pypy/build/bot2/codespeak-html
Message-ID: <20100702093719.D4947282BF4@codespeak.net>
Author: antocuni
Date: Fri Jul 2 11:37:17 2010
New Revision: 75754
Modified:
pypy/build/bot2/codespeak-html/index.html
Log:
add a link to the nightly build page
Modified: pypy/build/bot2/codespeak-html/index.html
==============================================================================
--- pypy/build/bot2/codespeak-html/index.html (original)
+++ pypy/build/bot2/codespeak-html/index.html Fri Jul 2 11:37:17 2010
@@ -22,9 +22,12 @@
PyPy has alpha-level support of the CPython C API, however, as of 1.3 +
PyPy has alpha-level support for the CPython C API, however, as of 1.3 release this feature is not yet complete. Most libraries will require a bit of effort to work, but there are known success stories. Check out PyPy blog for updates.
@@ -131,4 +131,4 @@