Author: Philip Jenvey <pjen...@underboss.org> Branch: py3k Changeset: r58259:760a976a876f Date: 2012-10-19 11:26 -0700 http://bitbucket.org/pypy/pypy/changeset/760a976a876f/
Log: merge default diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py --- a/lib_pypy/_ctypes/structure.py +++ b/lib_pypy/_ctypes/structure.py @@ -69,7 +69,8 @@ resnames.append(name) names = resnames self._names = names - self.__dict__.update(fields) + for name, field in fields.items(): + setattr(self, name, field) class Field(object): def __init__(self, name, offset, size, ctype, num, is_bitfield): diff --git a/lib_pypy/pypy_test/test_ctypes_support.py b/lib_pypy/pypy_test/test_ctypes_support.py deleted file mode 100644 --- a/lib_pypy/pypy_test/test_ctypes_support.py +++ /dev/null @@ -1,32 +0,0 @@ -from __future__ import absolute_import - -import py -from ctypes import * -try: - from ctypes_support import standard_c_lib, get_errno, set_errno -except ImportError: # on top of cpython - from lib_pypy.ctypes_support import standard_c_lib, get_errno, set_errno - - -def test_stdlib_and_errno(): - py.test.skip("this is expected on top of pypy, we need to fix ctypes in a way that is now in 2.6 in order to make this reliable") - write = standard_c_lib.write - write.argtypes = [c_int, c_char_p, c_size_t] - write.restype = c_size_t - # clear errno first - set_errno(0) - assert get_errno() == 0 - write(-345, "abc", 3) - assert get_errno() != 0 - set_errno(0) - assert get_errno() == 0 - -def test_argument_conversion_and_checks(): - strlen = standard_c_lib.strlen - strlen.argtypes = [c_char_p] - strlen.restype = c_size_t - assert strlen("eggs") == 4 - - # Should raise ArgumentError, not segfault - py.test.raises(ArgumentError, strlen, False) - diff --git a/pypy/interpreter/function.py b/pypy/interpreter/function.py --- a/pypy/interpreter/function.py +++ b/pypy/interpreter/function.py @@ -434,6 +434,7 @@ raise operationerrfmt(space.w_ValueError, "%s() requires a code object with %d free vars, not %d", self.name, closure_len, len(code.co_freevars)) + self.fget_func_doc(space) # see test_issue1293 self.code = code def fget_func_closure(self, space): diff --git a/pypy/interpreter/test/test_function.py b/pypy/interpreter/test/test_function.py --- a/pypy/interpreter/test/test_function.py +++ b/pypy/interpreter/test/test_function.py @@ -322,6 +322,12 @@ assert f.__doc__ == "hi" assert type(f.__doc__) is str + def test_issue1293(self): + def f1(): "doc f1" + def f2(): "doc f2" + f1.__code__ = f2.__code__ + assert f1.__doc__ == "doc f1" + def test_subclassing(self): # cannot subclass 'function' or 'builtin_function' def f(): diff --git a/pypy/module/fcntl/interp_fcntl.py b/pypy/module/fcntl/interp_fcntl.py --- a/pypy/module/fcntl/interp_fcntl.py +++ b/pypy/module/fcntl/interp_fcntl.py @@ -255,6 +255,9 @@ else: intarg = rffi.cast(rffi.INT, intarg) # C long => C int rv = ioctl_int(fd, op, intarg) + if rv < 0: + raise _get_error(space, "ioctl") + return space.wrap(rv) try: arg = space.bufferstr_w(w_arg) diff --git a/pypy/module/fcntl/test/test_fcntl.py b/pypy/module/fcntl/test/test_fcntl.py --- a/pypy/module/fcntl/test/test_fcntl.py +++ b/pypy/module/fcntl/test/test_fcntl.py @@ -13,7 +13,7 @@ class AppTestFcntl: def setup_class(cls): - space = gettestobjspace(usemodules=('fcntl', 'array', 'struct')) + space = gettestobjspace(usemodules=('fcntl', 'array', 'struct', 'termios')) cls.space = space tmpprefix = str(udir.ensure('test_fcntl', dir=1).join('tmp_')) cls.w_tmp = space.wrap(tmpprefix) @@ -136,11 +136,10 @@ import array import sys, os - if "linux" in sys.platform: - TIOCGPGRP = 0x540f - elif "darwin" in sys.platform or "freebsd" in sys.platform: - TIOCGPGRP = 0x40047477 - else: + try: + from termios import TIOCGPGRP + import pty + except ImportError: skip("don't know how to test ioctl() on this platform") raises(TypeError, fcntl.ioctl, "foo") @@ -148,28 +147,49 @@ #raises(TypeError, fcntl.ioctl, 0, TIOCGPGRP, float(0)) raises(TypeError, fcntl.ioctl, 0, TIOCGPGRP, 1, "foo") - if not os.isatty(0): - skip("stdin is not a tty") + child_pid, mfd = pty.fork() + if child_pid == 0: + # We're the child + return + try: + buf = array.array('h', [0]) + res = fcntl.ioctl(mfd, TIOCGPGRP, buf, True) + assert res == 0 + assert buf[0] != 0 + expected = buf.tostring() - buf = array.array('h', [0]) - res = fcntl.ioctl(0, TIOCGPGRP, buf, True) - assert res == 0 - assert buf[0] != 0 - expected = buf.tostring() + if '__pypy__' in sys.builtin_module_names or sys.version_info >= (2,5): + buf = array.array('h', [0]) + res = fcntl.ioctl(mfd, TIOCGPGRP, buf) + assert res == 0 + assert buf.tostring() == expected - if '__pypy__' in sys.builtin_module_names or sys.version_info >= (2,5): - buf = array.array('h', [0]) - res = fcntl.ioctl(0, TIOCGPGRP, buf) - assert res == 0 - assert buf.tostring() == expected + res = fcntl.ioctl(mfd, TIOCGPGRP, buf, False) + assert res == expected - res = fcntl.ioctl(0, TIOCGPGRP, buf, False) - assert res == expected + raises(TypeError, fcntl.ioctl, mfd, TIOCGPGRP, "\x00\x00", True) - raises(TypeError, fcntl.ioctl, 0, TIOCGPGRP, "\x00\x00", True) + res = fcntl.ioctl(mfd, TIOCGPGRP, "\x00\x00") + assert res == expected + finally: + os.close(mfd) - res = fcntl.ioctl(0, TIOCGPGRP, "\x00\x00") - assert res == expected + def test_ioctl_int(self): + import os + import fcntl + + try: + from termios import TCFLSH, TCIOFLUSH + import pty + except ImportError: + skip("don't know how to test ioctl() on this platform") + + mfd, sfd = pty.openpty() + try: + assert fcntl.ioctl(mfd, TCFLSH, TCIOFLUSH) == 0 + finally: + os.close(mfd) + os.close(sfd) def test_lockf_with_ex(self): import fcntl diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py @@ -462,6 +462,17 @@ callback = proto(callback) raises(ArgumentError, lambda: callback((1, 2, 3, 4), POINT())) + def test_argument_conversion_and_checks(self): + py.test.skip("XXX currently broken on PyPy, sorry") + strlen = dll.my_strchr + strlen.argtypes = [c_char_p, c_int] + strlen.restype = c_char_p + assert strlen("eggs", ord("g")) == "ggs" + + # Should raise ArgumentError, not segfault + py.test.raises(ArgumentError, strlen, 0, 0) + py.test.raises(ArgumentError, strlen, False, 0) + def test_union_as_passed_value(self): class UN(Union): _fields_ = [("x", c_short), @@ -545,3 +556,5 @@ res = test_errno() n = get_errno() assert (res, n) == (42, 43) + set_errno(0) + assert get_errno() == 0 diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py b/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py @@ -441,6 +441,11 @@ p = pointer(obj) assert p.contents._b_base_ is p + def test_unicode_field_name(self): + # setattr autoconverts field names to bytes + class X(Structure): + _fields_ = [(u"i", c_int)] + class TestPointerMember(BaseCTypesTestChecker): def test_1(self): diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py --- a/pypy/objspace/std/floatobject.py +++ b/pypy/objspace/std/floatobject.py @@ -97,12 +97,13 @@ try: return W_LongObject.fromfloat(space, w_value.floatval) except OverflowError: - if isnan(w_value.floatval): - raise OperationError( - space.w_ValueError, - space.wrap("cannot convert float NaN to integer")) - raise OperationError(space.w_OverflowError, - space.wrap("cannot convert float infinity to long")) + raise OperationError( + space.w_OverflowError, + space.wrap("cannot convert float infinity to integer")) + except ValueError: + raise OperationError(space.w_ValueError, + space.wrap("cannot convert float NaN to integer")) + def trunc__Float(space, w_floatobj): whole = math.modf(w_floatobj.floatval)[1] try: @@ -307,7 +308,7 @@ # Convert to long and use its hash. try: w_lval = W_LongObject.fromfloat(space, v) - except OverflowError: + except (OverflowError, ValueError): # can't convert to long int -- arbitrary if v < 0: return -HASH_INF diff --git a/pypy/objspace/std/test/test_typeobject.py b/pypy/objspace/std/test/test_typeobject.py --- a/pypy/objspace/std/test/test_typeobject.py +++ b/pypy/objspace/std/test/test_typeobject.py @@ -718,6 +718,12 @@ assert repr(property) == "<class 'property'>" assert repr(TypeError) == "<class 'TypeError'>" + def test_repr_issue1292(self): + d = {'object': object} # no __name__ + exec("class A(object): pass\n", d) + assert d['A'].__module__ == 'builtins' # obscure, follows CPython + assert repr(d['A']) == "<class 'A'>" + def test_invalid_mro(self): class A(object): pass diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py --- a/pypy/rlib/rbigint.py +++ b/pypy/rlib/rbigint.py @@ -1,7 +1,7 @@ from pypy.rlib.rarithmetic import LONG_BIT, intmask, longlongmask, r_uint, r_ulonglong, r_longlonglong from pypy.rlib.rarithmetic import ovfcheck, r_longlong, widen, is_valid_int from pypy.rlib.rarithmetic import most_neg_value_of_same_type -from pypy.rlib.rfloat import isfinite +from pypy.rlib.rfloat import isinf, isnan from pypy.rlib.debug import make_sure_not_resized, check_regular_int from pypy.rlib.objectmodel import we_are_translated, specialize from pypy.rlib import jit @@ -207,10 +207,11 @@ def fromfloat(dval): """ Create a new bigint object from a float """ # This function is not marked as pure because it can raise - if isfinite(dval): - return rbigint._fromfloat_finite(dval) - else: - raise OverflowError + if isinf(dval): + raise OverflowError("cannot convert float infinity to integer") + if isnan(dval): + raise ValueError("cannot convert float NaN to integer") + return rbigint._fromfloat_finite(dval) @staticmethod @jit.elidable diff --git a/pypy/rlib/test/test_rbigint.py b/pypy/rlib/test/test_rbigint.py --- a/pypy/rlib/test/test_rbigint.py +++ b/pypy/rlib/test/test_rbigint.py @@ -4,6 +4,7 @@ from random import random, randint, sample from pypy.rlib.rbigint import rbigint, SHIFT, MASK, KARATSUBA_CUTOFF from pypy.rlib.rbigint import _store_digit, _mask_digit +from pypy.rlib.rfloat import NAN from pypy.rlib import rbigint as lobj from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong, intmask from pypy.rpython.test.test_llinterp import interpret @@ -266,6 +267,7 @@ x = 12345.6789e200 x *= x assert raises(OverflowError, rbigint.fromfloat, x) + assert raises(ValueError, rbigint.fromfloat, NAN) # f1 = rbigint.fromfloat(9007199254740991.0) assert f1.tolong() == 9007199254740991 diff --git a/pypy/translator/goal/query.py b/pypy/translator/goal/query.py --- a/pypy/translator/goal/query.py +++ b/pypy/translator/goal/query.py @@ -49,7 +49,7 @@ s_ev = annotator.binding(ev, None) if s_et: if s_et.knowntype == type: - if s_et.__class__ == annmodel.SomeObject: + if s_et.__class__ == annmodel.SomeType: if hasattr(s_et, 'is_type_of') and s_et.is_type_of == [ev]: continue else: _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit