[pypy-commit] pypy stdlib-2.7.6: merge default
bdkearns
noreply at buildbot.pypy.org
Wed Mar 5 05:39:05 CET 2014
Author: Brian Kearns <bdkearns at gmail.com>
Branch: stdlib-2.7.6
Changeset: r69701:204b726bdfe3
Date: 2014-03-04 22:50 -0500
http://bitbucket.org/pypy/pypy/changeset/204b726bdfe3/
Log: merge default
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -95,5 +95,10 @@
.. branch: test-58c3d8552833
Fix for getarrayitem_gc_pure optimization
+.. branch: simple-range-strategy
+Implements SimpleRangeListStrategy for case range(n) where n is a positive number.
+Makes some traces nicer by getting rid of multiplication for calculating loop counter
+and propagates that n > 0 further to get rid of guards.
+
.. branch: stdlib-2.7.5
.. branch: vendor/stdlib
diff --git a/pypy/module/__pypy__/test/test_special.py b/pypy/module/__pypy__/test/test_special.py
--- a/pypy/module/__pypy__/test/test_special.py
+++ b/pypy/module/__pypy__/test/test_special.py
@@ -57,6 +57,8 @@
l = [1.1, 2.2, 3.3]
assert list_strategy(l) == "float"
l = range(3)
+ assert list_strategy(l) == "simple_range"
+ l = range(1, 2)
assert list_strategy(l) == "range"
l = [1, "b", 3]
assert list_strategy(l) == "object"
diff --git a/pypy/module/_pypyjson/targetjson.py b/pypy/module/_pypyjson/targetjson.py
--- a/pypy/module/_pypyjson/targetjson.py
+++ b/pypy/module/_pypyjson/targetjson.py
@@ -4,12 +4,10 @@
sys.path.insert(0, str(ROOT))
import time
-from rpython.rlib.streamio import open_file_as_stream
from pypy.interpreter.error import OperationError
from pypy.module._pypyjson.interp_decoder import loads
-
## MSG = open('msg.json').read()
class W_Root(object):
@@ -92,7 +90,7 @@
def wrapfloat(self, x):
return W_Float(x)
-
+
def wrap(self, x):
if isinstance(x, int):
return W_Int(x)
@@ -109,7 +107,6 @@
def myloads(msg):
return loads(fakespace, W_String(msg))
-
def bench(title, N, fn, arg):
a = time.clock()
@@ -124,14 +121,14 @@
return 1
filename = argv[1]
N = int(argv[2])
- f = open_file_as_stream(filename)
- msg = f.readall()
-
+ f = open(filename)
+ msg = f.read()
+
try:
bench('loads ', N, myloads, msg)
except OperationError, e:
print 'Error', e._compute_value(fakespace)
-
+
return 0
# _____ Define and setup target ___
diff --git a/pypy/module/_rawffi/structure.py b/pypy/module/_rawffi/structure.py
--- a/pypy/module/_rawffi/structure.py
+++ b/pypy/module/_rawffi/structure.py
@@ -20,6 +20,7 @@
from rpython.rtyper.lltypesystem import lltype, rffi
+
def unpack_fields(space, w_fields):
fields_w = space.unpackiterable(w_fields)
fields = []
diff --git a/pypy/module/gc/__init__.py b/pypy/module/gc/__init__.py
--- a/pypy/module/gc/__init__.py
+++ b/pypy/module/gc/__init__.py
@@ -1,5 +1,6 @@
from pypy.interpreter.mixedmodule import MixedModule
-
+
+
class Module(MixedModule):
interpleveldefs = {
'collect': 'interp_gc.collect',
@@ -8,15 +9,14 @@
'isenabled': 'interp_gc.isenabled',
'enable_finalizers': 'interp_gc.enable_finalizers',
'disable_finalizers': 'interp_gc.disable_finalizers',
- 'garbage' : 'space.newlist([])',
+ 'garbage': 'space.newlist([])',
#'dump_heap_stats': 'interp_gc.dump_heap_stats',
}
- appleveldefs = {
- }
+ appleveldefs = {}
def __init__(self, space, w_name):
if (not space.config.translating or
- space.config.translation.gctransformer == "framework"):
+ space.config.translation.gctransformer == "framework"):
self.appleveldefs.update({
'dump_rpy_heap': 'app_referents.dump_rpy_heap',
})
diff --git a/pypy/module/gc/interp_gc.py b/pypy/module/gc/interp_gc.py
--- a/pypy/module/gc/interp_gc.py
+++ b/pypy/module/gc/interp_gc.py
@@ -1,7 +1,7 @@
from pypy.interpreter.gateway import unwrap_spec
from pypy.interpreter.error import OperationError
from rpython.rlib import rgc
-from rpython.rlib.streamio import open_file_as_stream
+
@unwrap_spec(generation=int)
def collect(space, generation=0):
@@ -56,7 +56,7 @@
if not tb:
raise OperationError(space.w_RuntimeError,
space.wrap("Wrong GC"))
- f = open_file_as_stream(filename, mode="w")
+ f = open(filename, mode="w")
for i in range(len(tb)):
f.write("%d %d " % (tb[i].count, tb[i].size))
f.write(",".join([str(tb[i].links[j]) for j in range(len(tb))]) + "\n")
diff --git a/pypy/module/gc/test/test_gc.py b/pypy/module/gc/test/test_gc.py
--- a/pypy/module/gc/test/test_gc.py
+++ b/pypy/module/gc/test/test_gc.py
@@ -1,5 +1,6 @@
import py
+
class AppTestGC(object):
def test_collect(self):
import gc
@@ -69,6 +70,7 @@
gc.enable()
assert gc.isenabled()
+
class AppTestGcDumpHeap(object):
pytestmark = py.test.mark.xfail(run=False)
@@ -81,10 +83,10 @@
self.count = count
self.size = size
self.links = links
-
+
def fake_heap_stats():
return [X(1, 12, [0, 0]), X(2, 10, [10, 0])]
-
+
cls._heap_stats = rgc._heap_stats
rgc._heap_stats = fake_heap_stats
fname = udir.join('gcdump.log')
@@ -94,10 +96,10 @@
def teardown_class(cls):
import py
from rpython.rlib import rgc
-
+
rgc._heap_stats = cls._heap_stats
assert py.path.local(cls._fname).read() == '1 12 0,0\n2 10 10,0\n'
-
+
def test_gc_heap_stats(self):
import gc
gc.dump_heap_stats(self.fname)
@@ -124,6 +126,7 @@
for r in rlist:
assert r() is None
+
class AppTestGcMapDictIndexCache(AppTestGcMethodCache):
spaceconfig = {"objspace.std.withmethodcache": True,
"objspace.std.withmapdict": True}
diff --git a/pypy/module/pypyjit/test_pypy_c/test_generators.py b/pypy/module/pypyjit/test_pypy_c/test_generators.py
--- a/pypy/module/pypyjit/test_pypy_c/test_generators.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_generators.py
@@ -2,7 +2,7 @@
class TestGenerators(BaseTestPyPyC):
- def test_simple_generator(self):
+ def test_simple_generator1(self):
def main(n):
def f():
for i in range(10000):
@@ -28,7 +28,36 @@
jump(..., descr=...)
""")
assert loop.match_by_id("subtract", """
- setfield_gc(p7, 35, descr=<.*last_instr .*>) # XXX bad, kill me
+ i2 = int_sub(i1, 42)
+ """)
+
+ def test_simple_generator2(self):
+ def main(n):
+ def f():
+ for i in range(1, 10000):
+ i -= 1
+ i -= 42 # ID: subtract
+ yield i
+
+ def g():
+ for i in f(): # ID: generator
+ pass
+
+ g()
+
+ log = self.run(main, [500])
+ loop, = log.loops_by_filename(self.filepath)
+ assert loop.match_by_id("generator", """
+ cond_call(..., descr=...)
+ i16 = force_token()
+ p45 = new_with_vtable(ConstClass(W_IntObject))
+ setfield_gc(p45, i29, descr=<FieldS .*>)
+ setarrayitem_gc(p8, 0, p45, descr=<ArrayP .>)
+ i47 = arraylen_gc(p8, descr=<ArrayP .>) # Should be removed by backend
+ jump(..., descr=...)
+ """)
+ assert loop.match_by_id("subtract", """
+ setfield_gc(p7, 38, descr=<.*last_instr .*>) # XXX bad, kill me
i2 = int_sub_ovf(i1, 42)
guard_no_overflow(descr=...)
""")
diff --git a/pypy/module/pypyjit/test_pypy_c/test_misc.py b/pypy/module/pypyjit/test_pypy_c/test_misc.py
--- a/pypy/module/pypyjit/test_pypy_c/test_misc.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_misc.py
@@ -160,7 +160,7 @@
jump(..., descr=...)
""")
- def test_range_iter(self):
+ def test_range_iter_simple(self):
def main(n):
def g(n):
return range(n)
@@ -178,6 +178,36 @@
guard_not_invalidated?
i16 = int_ge(i11, i12)
guard_false(i16, descr=...)
+ i20 = int_add(i11, 1)
+ i21 = force_token()
+ setfield_gc(p4, i20, descr=<.* .*W_AbstractSeqIterObject.inst_index .*>)
+ guard_not_invalidated?
+ i25 = int_ge(i11, i9)
+ guard_false(i25, descr=...)
+ i27 = int_add_ovf(i7, i11)
+ guard_no_overflow(descr=...)
+ --TICK--
+ jump(..., descr=...)
+ """)
+
+ def test_range_iter_normal(self):
+ def main(n):
+ def g(n):
+ return range(n)
+ s = 0
+ for i in range(1, n): # ID: for
+ tmp = g(n)
+ s += tmp[i] # ID: getitem
+ a = 0
+ return s
+ #
+ log = self.run(main, [1000])
+ assert log.result == 1000 * 999 / 2
+ loop, = log.loops_by_filename(self.filepath)
+ assert loop.match("""
+ guard_not_invalidated?
+ i16 = int_ge(i11, i12)
+ guard_false(i16, descr=...)
i17 = int_mul(i11, i14)
i18 = int_add(i15, i17)
i20 = int_add(i11, 1)
diff --git a/pypy/module/select/test/test_select.py b/pypy/module/select/test/test_select.py
--- a/pypy/module/select/test/test_select.py
+++ b/pypy/module/select/test/test_select.py
@@ -293,7 +293,8 @@
class AppTestSelectWithSockets(_AppTestSelect):
"""Same tests with connected sockets.
socket.socketpair() does not exists on win32,
- so we start our own server."""
+ so we start our own server.
+ """
spaceconfig = {
"usemodules": ["select", "_socket", "rctime", "thread"],
}
@@ -315,7 +316,7 @@
except OperationError, e: # should get a "Permission denied"
if not e.match(space, space.getattr(w_socketmod, space.wrap("error"))):
raise
- print e
+ print e.errorstr(space)
except cls.w_sock_err, e: # should get a "Permission denied"
print e
else:
@@ -331,4 +332,8 @@
thread.start_new_thread(s2.connect, (self.sockaddress,))
s1, addr2 = self.sock.accept()
+ # speed up the tests that want to fill the buffers
+ s1.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 4096)
+ s2.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 4096)
+
return s1, s2
diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py
--- a/pypy/objspace/std/intobject.py
+++ b/pypy/objspace/std/intobject.py
@@ -13,6 +13,7 @@
from rpython.rlib.rarithmetic import (
LONG_BIT, is_valid_int, ovfcheck, r_longlong, r_uint, string_to_int)
from rpython.rlib.rbigint import rbigint
+from rpython.rlib.rfloat import DBL_MANT_DIG
from rpython.rlib.rstring import (
InvalidBaseError, ParseStringError, ParseStringOverflowError)
from rpython.tool.sourcetools import func_renamer, func_with_new_name
@@ -163,10 +164,18 @@
def _truediv(space, x, y):
+ if not y:
+ raise oefmt(space.w_ZeroDivisionError, "division by zero")
+
+ if (DBL_MANT_DIG < LONG_BIT and
+ (r_uint(abs(x)) >> DBL_MANT_DIG or r_uint(abs(y)) >> DBL_MANT_DIG)):
+ # large x or y, use long arithmetic
+ raise OverflowError
+
+ # both ints can be exactly represented as doubles, do a
+ # floating-point division
a = float(x)
b = float(y)
- if b == 0.0:
- raise oefmt(space.w_ZeroDivisionError, "division by zero")
return space.wrap(a / b)
@@ -589,7 +598,7 @@
descr_floordiv, descr_rfloordiv = _make_descr_binop(_floordiv)
descr_div, descr_rdiv = _make_descr_binop(_div)
- descr_truediv, descr_rtruediv = _make_descr_binop(_truediv, ovf=False)
+ descr_truediv, descr_rtruediv = _make_descr_binop(_truediv)
descr_mod, descr_rmod = _make_descr_binop(_mod)
descr_divmod, descr_rdivmod = _make_descr_binop(
_divmod, ovf2small=_divmod_ovf2small)
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -43,6 +43,9 @@
if length <= 0:
strategy = space.fromcache(EmptyListStrategy)
storage = strategy.erase(None)
+ elif start == 0 and step == 1:
+ strategy = space.fromcache(SimpleRangeListStrategy)
+ storage = strategy.erase((length,))
else:
strategy = space.fromcache(RangeListStrategy)
storage = strategy.erase((start, step, length))
@@ -138,7 +141,6 @@
class W_ListObject(W_Root):
-
strategy = None
def __init__(self, space, wrappeditems, sizehint=-1):
@@ -999,15 +1001,7 @@
self.sizehint = hint
-class RangeListStrategy(ListStrategy):
- """RangeListStrategy is used when a list is created using the range method.
- The storage is a tuple containing only three integers start, step and
- length and elements are calculated based on these values. On any operation
- destroying the range (inserting, appending non-ints) the strategy is
- switched to IntegerListStrategy."""
-
- _applevel_repr = "range"
-
+class BaseRangeListStrategy(ListStrategy):
def switch_to_integer_strategy(self, w_list):
items = self._getitems_range(w_list, False)
strategy = w_list.strategy = self.space.fromcache(IntegerListStrategy)
@@ -1022,10 +1016,6 @@
def init_from_list_w(self, w_list, list_w):
raise NotImplementedError
- erase, unerase = rerased.new_erasing_pair("range")
- erase = staticmethod(erase)
- unerase = staticmethod(unerase)
-
def clone(self, w_list):
storage = w_list.lstorage # lstorage is tuple, no need to clone
w_clone = W_ListObject.from_storage_and_strategy(self.space, storage,
@@ -1040,6 +1030,157 @@
w_other.strategy = self
w_other.lstorage = w_list.lstorage
+ def getitem(self, w_list, i):
+ return self.wrap(self._getitem_unwrapped(w_list, i))
+
+ def getitems_int(self, w_list):
+ return self._getitems_range(w_list, False)
+
+ def getitems_copy(self, w_list):
+ return self._getitems_range(w_list, True)
+
+ def getstorage_copy(self, w_list):
+ # tuple is immutable
+ return w_list.lstorage
+
+ @jit.dont_look_inside
+ def getitems_fixedsize(self, w_list):
+ return self._getitems_range_unroll(w_list, True)
+
+ def getitems_unroll(self, w_list):
+ return self._getitems_range_unroll(w_list, True)
+
+ def getslice(self, w_list, start, stop, step, length):
+ self.switch_to_integer_strategy(w_list)
+ return w_list.getslice(start, stop, step, length)
+
+ def append(self, w_list, w_item):
+ if type(w_item) is W_IntObject:
+ self.switch_to_integer_strategy(w_list)
+ else:
+ w_list.switch_to_object_strategy()
+ w_list.append(w_item)
+
+ def inplace_mul(self, w_list, times):
+ self.switch_to_integer_strategy(w_list)
+ w_list.inplace_mul(times)
+
+ def deleteslice(self, w_list, start, step, slicelength):
+ self.switch_to_integer_strategy(w_list)
+ w_list.deleteslice(start, step, slicelength)
+
+ def setitem(self, w_list, index, w_item):
+ self.switch_to_integer_strategy(w_list)
+ w_list.setitem(index, w_item)
+
+ def setslice(self, w_list, start, step, slicelength, sequence_w):
+ self.switch_to_integer_strategy(w_list)
+ w_list.setslice(start, step, slicelength, sequence_w)
+
+ def insert(self, w_list, index, w_item):
+ self.switch_to_integer_strategy(w_list)
+ w_list.insert(index, w_item)
+
+ def extend(self, w_list, w_any):
+ self.switch_to_integer_strategy(w_list)
+ w_list.extend(w_any)
+
+ def reverse(self, w_list):
+ self.switch_to_integer_strategy(w_list)
+ w_list.reverse()
+
+ def sort(self, w_list, reverse):
+ step = self.step(w_list)
+ if step > 0 and reverse or step < 0 and not reverse:
+ self.switch_to_integer_strategy(w_list)
+ w_list.sort(reverse)
+
+
+class SimpleRangeListStrategy(BaseRangeListStrategy):
+ """SimpleRangeListStrategy is used when a list is created using the range
+ method providing only positive length. The storage is a one element tuple
+ with positive integer storing length."""
+
+ _applevel_repr = "simple_range"
+
+ erase, unerase = rerased.new_erasing_pair("simple_range")
+ erase = staticmethod(erase)
+ unerase = staticmethod(unerase)
+
+ def find(self, w_list, w_obj, startindex, stopindex):
+ if type(w_obj) is W_IntObject:
+ obj = self.unwrap(w_obj)
+ length = self.unerase(w_list.lstorage)[0]
+ if 0 <= obj < length and startindex <= obj < stopindex:
+ return obj
+ else:
+ raise ValueError
+ return ListStrategy.find(self, w_list, w_obj, startindex, stopindex)
+
+ def length(self, w_list):
+ return self.unerase(w_list.lstorage)[0]
+
+ def step(self, w_list):
+ return 1
+
+ def _getitem_unwrapped(self, w_list, i):
+ length = self.unerase(w_list.lstorage)[0]
+ if i < 0:
+ i += length
+ if i < 0:
+ raise IndexError
+ elif i >= length:
+ raise IndexError
+ return i
+
+ @specialize.arg(2)
+ def _getitems_range(self, w_list, wrap_items):
+ length = self.unerase(w_list.lstorage)[0]
+ if wrap_items:
+ r = [None] * length
+ else:
+ r = [0] * length
+ i = 0
+ while i < length:
+ if wrap_items:
+ r[i] = self.wrap(i)
+ else:
+ r[i] = i
+ i += 1
+
+ return r
+
+ _getitems_range_unroll = jit.unroll_safe(
+ func_with_new_name(_getitems_range, "_getitems_range_unroll"))
+
+ def pop_end(self, w_list):
+ new_length = self.unerase(w_list.lstorage)[0] - 1
+ w_result = self.wrap(new_length)
+ if new_length > 0:
+ w_list.lstorage = self.erase((new_length,))
+ else:
+ strategy = w_list.strategy = self.space.fromcache(EmptyListStrategy)
+ w_list.lstorage = strategy.erase(None)
+ return w_result
+
+ def pop(self, w_list, index):
+ self.switch_to_integer_strategy(w_list)
+ return w_list.pop(index)
+
+
+class RangeListStrategy(BaseRangeListStrategy):
+ """RangeListStrategy is used when a list is created using the range method.
+ The storage is a tuple containing only three integers start, step and
+ length and elements are calculated based on these values. On any operation
+ destroying the range (inserting, appending non-ints) the strategy is
+ switched to IntegerListStrategy."""
+
+ _applevel_repr = "range"
+
+ erase, unerase = rerased.new_erasing_pair("range")
+ erase = staticmethod(erase)
+ unerase = staticmethod(unerase)
+
def find(self, w_list, w_obj, startindex, stopindex):
if type(w_obj) is W_IntObject:
obj = self.unwrap(w_obj)
@@ -1059,6 +1200,9 @@
def length(self, w_list):
return self.unerase(w_list.lstorage)[2]
+ def step(self, w_list):
+ return self.unerase(w_list.lstorage)[1]
+
def _getitem_unwrapped(self, w_list, i):
v = self.unerase(w_list.lstorage)
start = v[0]
@@ -1072,19 +1216,6 @@
raise IndexError
return start + i * step
- def getitems_int(self, w_list):
- return self._getitems_range(w_list, False)
-
- def getitem(self, w_list, i):
- return self.wrap(self._getitem_unwrapped(w_list, i))
-
- def getitems_copy(self, w_list):
- return self._getitems_range(w_list, True)
-
- def getstorage_copy(self, w_list):
- # tuple is unmutable
- return w_list.lstorage
-
@specialize.arg(2)
def _getitems_range(self, w_list, wrap_items):
l = self.unerase(w_list.lstorage)
@@ -1107,34 +1238,9 @@
return r
- @jit.dont_look_inside
- def getitems_fixedsize(self, w_list):
- return self._getitems_range_unroll(w_list, True)
-
- def getitems_unroll(self, w_list):
- return self._getitems_range_unroll(w_list, True)
_getitems_range_unroll = jit.unroll_safe(
func_with_new_name(_getitems_range, "_getitems_range_unroll"))
- def getslice(self, w_list, start, stop, step, length):
- self.switch_to_integer_strategy(w_list)
- return w_list.getslice(start, stop, step, length)
-
- def append(self, w_list, w_item):
- if type(w_item) is W_IntObject:
- self.switch_to_integer_strategy(w_list)
- else:
- w_list.switch_to_object_strategy()
- w_list.append(w_item)
-
- def inplace_mul(self, w_list, times):
- self.switch_to_integer_strategy(w_list)
- w_list.inplace_mul(times)
-
- def deleteslice(self, w_list, start, step, slicelength):
- self.switch_to_integer_strategy(w_list)
- w_list.deleteslice(start, step, slicelength)
-
def pop_end(self, w_list):
start, step, length = self.unerase(w_list.lstorage)
w_result = self.wrap(start + (length - 1) * step)
@@ -1158,32 +1264,6 @@
self.switch_to_integer_strategy(w_list)
return w_list.pop(index)
- def setitem(self, w_list, index, w_item):
- self.switch_to_integer_strategy(w_list)
- w_list.setitem(index, w_item)
-
- def setslice(self, w_list, start, step, slicelength, sequence_w):
- self.switch_to_integer_strategy(w_list)
- w_list.setslice(start, step, slicelength, sequence_w)
-
- def sort(self, w_list, reverse):
- step = self.unerase(w_list.lstorage)[1]
- if step > 0 and reverse or step < 0 and not reverse:
- self.switch_to_integer_strategy(w_list)
- w_list.sort(reverse)
-
- def insert(self, w_list, index, w_item):
- self.switch_to_integer_strategy(w_list)
- w_list.insert(index, w_item)
-
- def extend(self, w_list, w_any):
- self.switch_to_integer_strategy(w_list)
- w_list.extend(w_any)
-
- def reverse(self, w_list):
- self.switch_to_integer_strategy(w_list)
- w_list.reverse()
-
class AbstractUnwrappedStrategy(object):
@@ -1541,7 +1621,7 @@
_base_extend_from_list = _extend_from_list
def _extend_from_list(self, w_list, w_other):
- if w_other.strategy is self.space.fromcache(RangeListStrategy):
+ if isinstance(w_other.strategy, BaseRangeListStrategy):
l = self.unerase(w_list.lstorage)
other = w_other.getitems_int()
assert other is not None
diff --git a/pypy/objspace/std/test/test_intobject.py b/pypy/objspace/std/test/test_intobject.py
--- a/pypy/objspace/std/test/test_intobject.py
+++ b/pypy/objspace/std/test/test_intobject.py
@@ -563,6 +563,25 @@
base = MyInt(24)
assert int('10', base) == 24
+ def test_truediv(self):
+ import operator
+ x = 1000000
+ a = x / 2
+ assert a == 500000
+ a = operator.truediv(x, 2)
+ assert a == 500000.0
+
+ x = 63050394783186940
+ a = x / 7
+ assert a == 9007199254740991
+ a = operator.truediv(x, 7)
+ assert a == 9007199254740991.0
+ exec("from __future__ import division; "
+ "a = x / 7; b = operator.truediv(x, 7)")
+ assert a == 9007199254740991.0
+ assert b == 9007199254740991.0
+
+
class AppTestIntShortcut(AppTestInt):
spaceconfig = {"objspace.std.intshortcut": True}
diff --git a/pypy/objspace/std/test/test_listobject.py b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -166,7 +166,6 @@
self.space.setitem(w_lhslist, w_slice, w_rhslist)
assert self.space.unwrap(w_lhslist) == expected
-
test1([5,7,1,4], 1, 3, [9,8], [5,9,8,4])
test1([5,7,1,4], 1, 3, [9], [5,9,4])
test1([5,7,1,4], 1, 3, [9,8,6],[5,9,8,6,4])
@@ -294,6 +293,7 @@
self.space.w_True)
assert self.space.eq_w(self.space.eq(w_list2, w_list3),
self.space.w_False)
+
def test_ne(self):
w = self.space.wrap
@@ -312,6 +312,7 @@
self.space.w_False)
assert self.space.eq_w(self.space.ne(w_list2, w_list3),
self.space.w_True)
+
def test_lt(self):
w = self.space.wrap
@@ -429,6 +430,7 @@
with py.test.raises(ValueError):
intlist.find(w(4), 0, 2)
+
class AppTestW_ListObject(object):
def setup_class(cls):
import platform
@@ -662,7 +664,6 @@
raises(IndexError, "l[1]")
def test_setitem(self):
-
l = []
raises(IndexError, "l[1] = 2")
@@ -861,7 +862,6 @@
raises(TypeError, "[0]*MyInt(3)")
raises(TypeError, "[0]*MyIndex(MyInt(3))")
-
def test_index(self):
c = range(10)
assert c.index(0) == 0
@@ -1318,6 +1318,8 @@
assert ([5] >= [N]) is False
def test_resizelist_hint(self):
+ if self.on_cpython:
+ skip('pypy-only test')
import __pypy__
l2 = []
__pypy__.resizelist_hint(l2, 100)
@@ -1326,6 +1328,8 @@
assert len(l1) == 0
def test_use_method_for_wrong_object(self):
+ if self.on_cpython:
+ skip('pypy-only test')
raises(TypeError, list.append.im_func, 1, 2)
def test_ne_NotImplemented(self):
@@ -1439,7 +1443,20 @@
def test_getitem(self):
l = range(5)
- raises(IndexError, "l[-10]")
+ raises(IndexError, "l[-6]")
+ raises(IndexError, "l[5]")
+ assert l[0] == 0
+ assert l[-1] == 4
+ assert l[-2] == 3
+ assert l[-5] == 0
+
+ l = range(1, 5)
+ raises(IndexError, "l[-5]")
+ raises(IndexError, "l[4]")
+ assert l[0] == 1
+ assert l[-1] == 4
+ assert l[-2] == 3
+ assert l[-4] == 1
def test_append(self):
l = range(5)
@@ -1515,6 +1532,7 @@
notshared = l[:]
assert notshared == []
+
class AppTestListFastSubscr:
spaceconfig = {"objspace.std.optimized_list_getitem": True}
diff --git a/pypy/objspace/std/test/test_liststrategies.py b/pypy/objspace/std/test/test_liststrategies.py
--- a/pypy/objspace/std/test/test_liststrategies.py
+++ b/pypy/objspace/std/test/test_liststrategies.py
@@ -1,5 +1,8 @@
import sys
-from pypy.objspace.std.listobject import W_ListObject, EmptyListStrategy, ObjectListStrategy, IntegerListStrategy, FloatListStrategy, BytesListStrategy, RangeListStrategy, make_range_list, UnicodeListStrategy
+from pypy.objspace.std.listobject import (
+ W_ListObject, EmptyListStrategy, ObjectListStrategy, IntegerListStrategy,
+ FloatListStrategy, BytesListStrategy, RangeListStrategy,
+ SimpleRangeListStrategy, make_range_list, UnicodeListStrategy)
from pypy.objspace.std import listobject
from pypy.objspace.std.test.test_listobject import TestW_ListObject
@@ -18,7 +21,7 @@
UnicodeListStrategy)
assert isinstance(W_ListObject(space, [w(u'a'), w('b')]).strategy,
ObjectListStrategy) # mixed unicode and bytes
-
+
def test_empty_to_any(self):
space = self.space
w = space.wrap
@@ -183,7 +186,7 @@
def test_setslice(self):
space = self.space
w = space.wrap
-
+
l = W_ListObject(space, [])
assert isinstance(l.strategy, EmptyListStrategy)
l.setslice(0, 1, 2, W_ListObject(space, [w(1), w(2), w(3)]))
@@ -286,7 +289,7 @@
def test_empty_setslice_with_objectlist(self):
space = self.space
w = space.wrap
-
+
l = W_ListObject(space, [])
o = W_ListObject(space, [space.wrap(1), space.wrap("2"), space.wrap(3)])
l.setslice(0, 1, o.length(), o)
@@ -347,6 +350,13 @@
empty = W_ListObject(space, [])
assert isinstance(empty.strategy, EmptyListStrategy)
+ r = make_range_list(space, 0, 1, 10)
+ empty.extend(r)
+ assert isinstance(empty.strategy, SimpleRangeListStrategy)
+ assert space.is_true(space.eq(empty.getitem(1), w(1)))
+
+ empty = W_ListObject(space, [])
+ assert isinstance(empty.strategy, EmptyListStrategy)
empty.extend(W_ListObject(space, [w(1), w(2), w(3)]))
assert isinstance(empty.strategy, IntegerListStrategy)
@@ -397,6 +407,72 @@
l.append(self.space.wrap(19))
assert isinstance(l.strategy, IntegerListStrategy)
+ def test_simplerangelist(self):
+ l = make_range_list(self.space, 0, 1, 10)
+ assert isinstance(l.strategy, SimpleRangeListStrategy)
+ v = l.pop(5)
+ assert self.space.eq_w(v, self.space.wrap(5))
+ assert isinstance(l.strategy, IntegerListStrategy)
+
+ l = make_range_list(self.space, 0, 1, 10)
+ assert isinstance(l.strategy, SimpleRangeListStrategy)
+ v = l.pop(0)
+ assert self.space.eq_w(v, self.space.wrap(0))
+ assert isinstance(l.strategy, IntegerListStrategy)
+
+ l = make_range_list(self.space, 0, 1, 10)
+ assert isinstance(l.strategy, SimpleRangeListStrategy)
+ v = l.pop_end()
+ assert self.space.eq_w(v, self.space.wrap(9))
+ assert isinstance(l.strategy, SimpleRangeListStrategy)
+ v = l.pop_end()
+ assert self.space.eq_w(v, self.space.wrap(8))
+ assert isinstance(l.strategy, SimpleRangeListStrategy)
+
+ l = make_range_list(self.space, 0, 1, 5)
+ assert isinstance(l.strategy, SimpleRangeListStrategy)
+ l.append(self.space.wrap("string"))
+ assert isinstance(l.strategy, ObjectListStrategy)
+
+ l = make_range_list(self.space, 0,1,5)
+ assert isinstance(l.strategy, SimpleRangeListStrategy)
+ l.append(self.space.wrap(19))
+ assert isinstance(l.strategy, IntegerListStrategy)
+
+ l = make_range_list(self.space, 0,1,5)
+ assert isinstance(l.strategy, SimpleRangeListStrategy)
+ assert l.find(self.space.wrap(0)) == 0
+ assert l.find(self.space.wrap(4)) == 4
+
+ try:
+ l.find(self.space.wrap(5))
+ except ValueError:
+ pass
+ else:
+ assert False, "Did not raise ValueError"
+
+ try:
+ l.find(self.space.wrap(0), 5, 6)
+ except ValueError:
+ pass
+ else:
+ assert False, "Did not raise ValueError"
+
+ assert l.length() == 5
+
+ l = make_range_list(self.space, 0, 1, 1)
+ assert self.space.eq_w(l.pop(0), self.space.wrap(0))
+
+ l = make_range_list(self.space, 0, 1, 10)
+ l.sort(False)
+ assert isinstance(l.strategy, SimpleRangeListStrategy)
+
+ assert self.space.eq_w(l.getitem(5), self.space.wrap(5))
+
+ l = make_range_list(self.space, 0, 1, 1)
+ assert self.space.eq_w(l.pop_end(), self.space.wrap(0))
+ assert isinstance(l.strategy, EmptyListStrategy)
+
def test_keep_range(self):
# simple list
l = make_range_list(self.space, 1,1,5)
diff --git a/pypy/objspace/std/test/test_rangeobject.py b/pypy/objspace/std/test/test_rangeobject.py
--- a/pypy/objspace/std/test/test_rangeobject.py
+++ b/pypy/objspace/std/test/test_rangeobject.py
@@ -72,28 +72,43 @@
r.sort(key=lambda x: -x)
assert r == range(9, -1, -1)
def test_pop(self):
+ # RangeListStrategy
+ r = range(1, 10)
+ res = r.pop()
+ assert res == 9
+ assert self.not_forced(r)
+ assert repr(r) == repr(range(1, 9))
+ res = r.pop(0)
+ assert res == 1
+ assert self.not_forced(r)
+ assert repr(r) == repr(range(2, 9))
+ res = r.pop(len(r) - 1)
+ assert res == 8
+ assert self.not_forced(r)
+ assert repr(r) == repr(range(2, 8))
+ res = r.pop(2)
+ assert res == 4
+ assert not self.not_forced(r)
+ assert r == [2, 3, 5, 6, 7]
+ res = r.pop(2)
+ assert res == 5
+ assert not self.not_forced(r)
+ assert r == [2, 3, 6, 7]
+
+ # SimpleRangeListStrategy
r = range(10)
res = r.pop()
assert res == 9
assert self.not_forced(r)
- assert repr(r) == repr(range(9))
+ res = r.pop()
+ assert res == 8
+ assert repr(r) == repr(range(8))
+ assert self.not_forced(r)
res = r.pop(0)
assert res == 0
- assert self.not_forced(r)
- assert repr(r) == repr(range(1, 9))
- res = r.pop(len(r) - 1)
- assert res == 8
- assert self.not_forced(r)
- assert repr(r) == repr(range(1, 8))
- res = r.pop(2)
- assert res == 3
assert not self.not_forced(r)
- assert r == [1, 2, 4, 5, 6, 7]
- res = r.pop(2)
- assert res == 4
- assert not self.not_forced(r)
- assert r == [1, 2, 5, 6, 7]
-
+ assert r == [1, 2, 3, 4, 5, 6, 7]
+
def test_reduce(self):
it = iter(range(10))
assert it.next() == 0
diff --git a/pypy/tool/gdb_pypy.py b/pypy/tool/gdb_pypy.py
--- a/pypy/tool/gdb_pypy.py
+++ b/pypy/tool/gdb_pypy.py
@@ -8,8 +8,6 @@
(gdb) python execfile('/path/to/gdb_pypy.py')
"""
-from __future__ import with_statement
-
import re
import sys
import os.path
@@ -120,15 +118,16 @@
"""
Returns a mapping offset --> description
"""
+ import tempfile
+ import zlib
vname = 'pypy_g_rpython_memory_gctypelayout_GCData.gcd_inst_typeids_z'
length = int(self.gdb.parse_and_eval('*(long*)%s' % vname))
vstart = '(char*)(((long*)%s)+1)' % vname
- self.gdb.execute('dump binary memory /tmp/typeids.txt.z %s %s+%d'
- % (vstart, vstart, length))
- s = open('/tmp/typeids.txt.z', 'rb').read()
- import zlib; typeids_txt = zlib.decompress(s)
- typeids = TypeIdsMap(typeids_txt.splitlines(True), self.gdb)
- return typeids
+ with tempfile.NamedTemporaryFile('rb') as fobj:
+ self.gdb.execute('dump binary memory %s %s %s+%d' %
+ (fobj.name, vstart, vstart, length))
+ data = fobj.read()
+ return TypeIdsMap(zlib.decompress(data).splitlines(True), self.gdb)
class TypeIdsMap(object):
diff --git a/rpython/rlib/rfile.py b/rpython/rlib/rfile.py
--- a/rpython/rlib/rfile.py
+++ b/rpython/rlib/rfile.py
@@ -1,4 +1,3 @@
-
""" This file makes open() and friends RPython. Note that RFile should not
be used directly and instead it's magically appearing each time you call
python builtin open()
@@ -17,27 +16,27 @@
def llexternal(*args, **kwargs):
return rffi.llexternal(*args, compilation_info=eci, **kwargs)
-FILE = lltype.Struct('FILE') # opaque type maybe
-
class CConfig(object):
_compilation_info_ = eci
off_t = platform.SimpleType('off_t')
+config = platform.configure(CConfig)
-CC = platform.configure(CConfig)
-OFF_T = CC['off_t']
+OFF_T = config['off_t']
+FILE = lltype.Struct('FILE') # opaque type maybe
+
c_open = llexternal('fopen', [rffi.CCHARP, rffi.CCHARP], lltype.Ptr(FILE))
c_close = llexternal('fclose', [lltype.Ptr(FILE)], rffi.INT)
c_fwrite = llexternal('fwrite', [rffi.CCHARP, rffi.SIZE_T, rffi.SIZE_T,
- lltype.Ptr(FILE)], rffi.SIZE_T)
+ lltype.Ptr(FILE)], rffi.SIZE_T)
c_fread = llexternal('fread', [rffi.CCHARP, rffi.SIZE_T, rffi.SIZE_T,
- lltype.Ptr(FILE)], rffi.SIZE_T)
+ lltype.Ptr(FILE)], rffi.SIZE_T)
c_feof = llexternal('feof', [lltype.Ptr(FILE)], rffi.INT)
c_ferror = llexternal('ferror', [lltype.Ptr(FILE)], rffi.INT)
c_clearerror = llexternal('clearerr', [lltype.Ptr(FILE)], lltype.Void)
c_fseek = llexternal('fseek', [lltype.Ptr(FILE), rffi.LONG, rffi.INT],
- rffi.INT)
+ rffi.INT)
c_tmpfile = llexternal('tmpfile', [], lltype.Ptr(FILE))
c_fileno = llexternal('fileno', [lltype.Ptr(FILE)], rffi.INT)
c_ftell = llexternal('ftell', [lltype.Ptr(FILE)], rffi.LONG)
@@ -53,6 +52,13 @@
BASE_BUF_SIZE = 4096
BASE_LINE_SIZE = 100
+
+def _error(ll_file):
+ errno = c_ferror(ll_file)
+ c_clearerror(ll_file)
+ raise OSError(errno, os.strerror(errno))
+
+
def create_file(filename, mode="r", buffering=-1):
assert buffering == -1
assert filename is not None
@@ -71,6 +77,7 @@
lltype.free(ll_name, flavor='raw')
return RFile(ll_f)
+
def create_temp_rfile():
res = c_tmpfile()
if not res:
@@ -78,6 +85,7 @@
raise OSError(errno, os.strerror(errno))
return RFile(res)
+
def create_popen_file(command, type):
ll_command = rffi.str2charp(command)
try:
@@ -93,6 +101,7 @@
lltype.free(ll_command, flavor='raw')
return RPopenFile(ll_f)
+
class RFile(object):
def __init__(self, ll_file):
self.ll_file = ll_file
@@ -224,7 +233,7 @@
while raw_buf[strlen] != '\0':
strlen += 1
if (strlen == BASE_LINE_SIZE - 1 and
- raw_buf[BASE_LINE_SIZE - 2] != '\n'):
+ raw_buf[BASE_LINE_SIZE - 2] != '\n'):
return -1 # overflow!
# common case
return strlen
@@ -255,9 +264,3 @@
class RPopenFile(RFile):
_do_close = staticmethod(c_pclose)
-
-
-def _error(ll_file):
- errno = c_ferror(ll_file)
- c_clearerror(ll_file)
- raise OSError(errno, os.strerror(errno))
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -7,6 +7,7 @@
from rpython.rlib import jit
from rpython.translator.platform import platform
+
class CConstantErrno(CConstant):
# these accessors are used when calling get_errno() or set_errno()
# on top of CPython
@@ -20,6 +21,7 @@
def __setitem__(self, index, value):
assert index == 0
ll2ctypes.TLS.errno = value
+
if os.name == 'nt':
if platform.name == 'msvc':
includes=['errno.h','stdio.h']
diff --git a/rpython/rtyper/rbuiltin.py b/rpython/rtyper/rbuiltin.py
--- a/rpython/rtyper/rbuiltin.py
+++ b/rpython/rtyper/rbuiltin.py
@@ -1,4 +1,3 @@
-
from rpython.annotator import model as annmodel
from rpython.flowspace.model import Constant
from rpython.rlib import rarithmetic, objectmodel
diff --git a/rpython/rtyper/tool/rffi_platform.py b/rpython/rtyper/tool/rffi_platform.py
--- a/rpython/rtyper/tool/rffi_platform.py
+++ b/rpython/rtyper/tool/rffi_platform.py
@@ -198,12 +198,14 @@
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
- assert not hasattr(CConfig, attr), "Found legacy attribute %s on CConfig" % (attr,)
+ assert not hasattr(CConfig, attr), \
+ "Found legacy attribute %s on CConfig" % attr
+
entries = []
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
- entries.append((key, value))
+ entries.append((key, value))
if entries: # can be empty if there are only CConfigSingleEntries
writer = _CWriter(CConfig)
More information about the pypy-commit
mailing list