Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r57113:185a699fb143
Date: 2012-09-03 22:43 +0200
http://bitbucket.org/pypy/pypy/changeset/185a699fb143/
Log: hg merge default
diff --git a/lib-python/2.7/test/test_winreg.py
b/lib-python/2.7/test/test_winreg.py
--- a/lib-python/2.7/test/test_winreg.py
+++ b/lib-python/2.7/test/test_winreg.py
@@ -1,7 +1,7 @@
# Test the windows specific win32reg module.
# Only win32reg functions not hit here: FlushKey, LoadKey and SaveKey
-import os, sys
+import os, sys, errno
import unittest
from test import test_support
threading = test_support.import_module("threading")
@@ -283,7 +283,13 @@
def test_dynamic_key(self):
# Issue2810, when the value is dynamically generated, these
# throw "WindowsError: More data is available" in 2.6 and 3.1
- EnumValue(HKEY_PERFORMANCE_DATA, 0)
+ try:
+ EnumValue(HKEY_PERFORMANCE_DATA, 0)
+ except OSError as e:
+ if e.errno in (errno.EPERM, errno.EACCES):
+ self.skipTest("access denied to registry key "
+ "(are you running in a non-interactive
session?)")
+ raise
QueryValueEx(HKEY_PERFORMANCE_DATA, None)
# Reflection requires XP x64/Vista at a minimum. XP doesn't have this stuff
diff --git a/lib-python/conftest.py b/lib-python/conftest.py
--- a/lib-python/conftest.py
+++ b/lib-python/conftest.py
@@ -259,7 +259,7 @@
RegrTest('test_isinstance.py', core=True),
RegrTest('test_iter.py', core=True),
RegrTest('test_iterlen.py'),
- RegrTest('test_itertools.py', core=True),
+ RegrTest('test_itertools.py', core=True, usemodules="itertools struct"),
RegrTest('test_json.py'),
RegrTest('test_keywordonlyarg.py'),
RegrTest('test_kqueue.py'),
diff --git a/pypy/interpreter/astcompiler/optimize.py
b/pypy/interpreter/astcompiler/optimize.py
--- a/pypy/interpreter/astcompiler/optimize.py
+++ b/pypy/interpreter/astcompiler/optimize.py
@@ -21,28 +21,22 @@
def as_constant_truth(self, space):
"""Return the truth of this node if known."""
- raise AssertionError("only for expressions")
-
- def as_constant(self):
- """Return the value of this node as a wrapped constant if possible."""
- raise AssertionError("only for expressions")
-
- def accept_jump_if(self, gen, condition, target):
- raise AssertionError("only for expressions")
-
-
-class __extend__(ast.expr):
-
- def as_constant_truth(self, space):
const = self.as_constant()
if const is None:
return CONST_NOT_CONST
return int(space.is_true(const))
def as_constant(self):
+ """Return the value of this node as a wrapped constant if possible."""
return None
def accept_jump_if(self, gen, condition, target):
+ raise AssertionError("only for expressions")
+
+
+class __extend__(ast.expr):
+
+ def accept_jump_if(self, gen, condition, target):
self.walkabout(gen)
if condition:
gen.emit_jump(ops.POP_JUMP_IF_TRUE, target, True)
diff --git a/pypy/interpreter/test/test_compiler.py
b/pypy/interpreter/test/test_compiler.py
--- a/pypy/interpreter/test/test_compiler.py
+++ b/pypy/interpreter/test/test_compiler.py
@@ -873,7 +873,7 @@
('a = 14%4', '(2)'), # binary modulo
('a = 2+3', '(5)'), # binary add
('a = 13-4', '(9)'), # binary subtract
- # ('a = (12,13)[1]', '(13)'), # binary subscr -
pointless optimization
+ ('a = (12,13)[1]', '(13)'), # binary subscr
('a = 13 << 2', '(52)'), # binary lshift
('a = 13 >> 2', '(3)'), # binary rshift
('a = 13 & 7', '(5)'), # binary and
@@ -894,6 +894,10 @@
asm = dis_single('a="x"*1000')
assert '(1000)' in asm
+ def test_folding_of_binops_on_constants_crash(self):
+ compile('()[...]', '', 'eval')
+ # assert did not crash
+
def test_dis_stopcode(self):
source = """def _f(a):
print(a)
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py
b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -21,7 +21,10 @@
mandatory_b_prefix = 'b'
mandatory_u_prefix = ''
readbuf = lambda buf: buf.tobytes()
- bufchar = ord
+ if sys.version_info < (3, 3):
+ bufchar = lambda x: bytes([ord(x)])
+ else:
+ bufchar = ord
bytechr = lambda n: bytes([n])
u = ""
@@ -906,7 +909,7 @@
('j', BInt, -1)])
BFunc21 = new_function_type((BStruct,), BInt, False)
f = cast(BFunc21, _testfunc(21))
- res = f(range(13, 3, -1))
+ res = f(list(range(13, 3, -1)))
lst = [(n << i) for (i, n) in enumerate(range(13, 3, -1))]
assert res == sum(lst)
@@ -1076,7 +1079,7 @@
('i', BInt, -1),
('j', BInt, -1)])
def cb():
- return newp(BStructPtr, range(13, 3, -1))[0]
+ return newp(BStructPtr, list(range(13, 3, -1)))[0]
BFunc = new_function_type((), BStruct)
f = callback(BFunc, cb)
s = f()
@@ -1810,11 +1813,12 @@
c[2] = b'-'
buf[:2] = b'HI'
assert string(c) == b'HI-there'
- assert buf[:4:2] == b'H-'
- if '__pypy__' not in sys.builtin_module_names:
- # XXX pypy doesn't support the following assignment so far
- buf[:4:2] = b'XY'
- assert string(c) == b'XIYthere'
+ if sys.version_info < (3,) or sys.version_info >= (3, 3):
+ assert buf[:4:2] == b'H-'
+ if '__pypy__' not in sys.builtin_module_names:
+ # XXX pypy doesn't support the following assignment so far
+ buf[:4:2] = b'XY'
+ assert string(c) == b'XIYthere'
def test_getcname():
BUChar = new_primitive_type("unsigned char")
diff --git a/pypy/module/_rawffi/__init__.py b/pypy/module/_rawffi/__init__.py
--- a/pypy/module/_rawffi/__init__.py
+++ b/pypy/module/_rawffi/__init__.py
@@ -30,13 +30,11 @@
'get_libc' : 'interp_rawffi.get_libc',
'get_errno' : 'interp_rawffi.get_errno',
'set_errno' : 'interp_rawffi.set_errno',
+ 'get_last_error' : 'interp_rawffi.get_last_error',
+ 'set_last_error' : 'interp_rawffi.set_last_error',
'SegfaultException' :
'space.new_exception_class("_rawffi.SegfaultException")',
}
- if sys.platform == 'win32':
- interpleveldefs['get_last_error'] = 'interp_rawffi.get_last_error'
- interpleveldefs['set_last_error'] = 'interp_rawffi.set_last_error'
-
appleveldefs = {
}
diff --git a/pypy/module/_rawffi/interp_rawffi.py
b/pypy/module/_rawffi/interp_rawffi.py
--- a/pypy/module/_rawffi/interp_rawffi.py
+++ b/pypy/module/_rawffi/interp_rawffi.py
@@ -541,11 +541,19 @@
def set_errno(space, w_errno):
rposix.set_errno(space.int_w(w_errno))
-def get_last_error(space):
- from pypy.rlib.rwin32 import GetLastError
- return space.wrap(GetLastError())
-
-@unwrap_spec(error=int)
-def set_last_error(space, error):
- from pypy.rlib.rwin32 import SetLastError
- SetLastError(error)
+if sys.platform == 'win32':
+ def get_last_error(space):
+ from pypy.rlib.rwin32 import GetLastError
+ return space.wrap(GetLastError())
+ @unwrap_spec(error=int)
+ def set_last_error(space, error):
+ from pypy.rlib.rwin32 import SetLastError
+ SetLastError(error)
+else:
+ # always have at least a dummy version of these functions
+ # (https://bugs.pypy.org/issue1242)
+ def get_last_error(space):
+ return space.wrap(0)
+ @unwrap_spec(error=int)
+ def set_last_error(space, error):
+ pass
diff --git a/pypy/module/itertools/interp_itertools.py
b/pypy/module/itertools/interp_itertools.py
--- a/pypy/module/itertools/interp_itertools.py
+++ b/pypy/module/itertools/interp_itertools.py
@@ -772,7 +772,7 @@
item = data[i] = next()
cnt[0] += 1
else:
- item = data.pop(i)
+ item = data[i] # data.pop(i) if it's the last one
yield item
it = iter(iterable)
return tuple([gen(it.next) for i in range(n)])
@@ -782,46 +782,42 @@
myiter = space.interpclass_w(w_iterable)
if isinstance(myiter, W_TeeIterable): # optimization only
- tee_state = myiter.tee_state
+ chained_list = myiter.chained_list
+ w_iterator = myiter.w_iterator
iterators_w = [w_iterable] * n
for i in range(1, n):
- iterators_w[i] = space.wrap(W_TeeIterable(space, tee_state))
+ iterators_w[i] = space.wrap(W_TeeIterable(space, w_iterator,
+ chained_list))
else:
- tee_state = TeeState(space, w_iterable)
- iterators_w = [space.wrap(W_TeeIterable(space, tee_state)) for x in
range(n)]
+ w_iterator = space.iter(w_iterable)
+ chained_list = TeeChainedListNode()
+ iterators_w = [space.wrap(
+ W_TeeIterable(space, w_iterator, chained_list))
+ for x in range(n)]
return space.newtuple(iterators_w)
-class TeeState(object):
- def __init__(self, space, w_iterable):
- self.space = space
- self.w_iterable = self.space.iter(w_iterable)
- self.num_saved = 0
- self.saved_w = []
-
- def get_next(self, index):
- if index >= self.num_saved:
- w_obj = self.space.next(self.w_iterable)
- self.saved_w.append(w_obj)
- self.num_saved += 1
- return w_obj
- else:
- return self.saved_w[index]
+class TeeChainedListNode(object):
+ w_obj = None
class W_TeeIterable(Wrappable):
- def __init__(self, space, tee_state):
+ def __init__(self, space, w_iterator, chained_list):
self.space = space
- self.tee_state = tee_state
- self.index = 0
+ self.w_iterator = w_iterator
+ assert chained_list is not None
+ self.chained_list = chained_list
def iter_w(self):
return self.space.wrap(self)
def next_w(self):
- try:
- w_obj = self.tee_state.get_next(self.index)
- return w_obj
- finally:
- self.index += 1
+ chained_list = self.chained_list
+ w_obj = chained_list.w_obj
+ if w_obj is None:
+ w_obj = self.space.next(self.w_iterator)
+ chained_list.next = TeeChainedListNode()
+ chained_list.w_obj = w_obj
+ self.chained_list = chained_list.next
+ return w_obj
def W_TeeIterable___new__(space, w_subtype, w_iterable):
# Obscure and undocumented function. PyPy only supports w_iterable
@@ -830,8 +826,8 @@
# semantics are then slightly different; see the XXX in lib-python's
# test_itertools).
myiter = space.interp_w(W_TeeIterable, w_iterable)
- tee_state = myiter.tee_state
- return space.wrap(W_TeeIterable(space, tee_state))
+ return space.wrap(W_TeeIterable(space, myiter.w_iterator,
+ myiter.chained_list))
W_TeeIterable.typedef = TypeDef(
'_tee',
diff --git a/pypy/module/itertools/test/test_itertools.py
b/pypy/module/itertools/test/test_itertools.py
--- a/pypy/module/itertools/test/test_itertools.py
+++ b/pypy/module/itertools/test/test_itertools.py
@@ -615,6 +615,17 @@
ref = weakref.ref(b)
assert ref() is b
+ def test_tee_bug1(self):
+ import itertools
+ a, b = itertools.tee('abcde')
+ x = a.next()
+ assert x == 'a'
+ c, d = itertools.tee(a)
+ x = c.next()
+ assert x == 'b'
+ x = d.next()
+ assert x == 'b'
+
class AppTestItertools26:
def setup_class(cls):
diff --git a/pypy/translator/cli/test/test_unicode.py
b/pypy/translator/cli/test/test_unicode.py
--- a/pypy/translator/cli/test/test_unicode.py
+++ b/pypy/translator/cli/test/test_unicode.py
@@ -24,3 +24,9 @@
def test_strformat_unicode_arg(self):
py.test.skip('fixme!')
+
+ def test_unicode_decode(self):
+ py.test.skip('fixme!')
+
+ def test_unicode_encode(self):
+ py.test.skip('fixme!')
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit