Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r57965:565fa280208d Date: 2012-10-10 11:20 +0200 http://bitbucket.org/pypy/pypy/changeset/565fa280208d/
Log: Update from cffi. diff --git a/pypy/module/_cffi_backend/newtype.py b/pypy/module/_cffi_backend/newtype.py --- a/pypy/module/_cffi_backend/newtype.py +++ b/pypy/module/_cffi_backend/newtype.py @@ -248,7 +248,17 @@ raise OperationError(space.w_ValueError, space.wrap("tuple args must have the same size")) enumerators = [space.str_w(w) for w in enumerators_w] - enumvalues = [space.int_w(w) for w in enumvalues_w] + enumvalues = [] + try: + for w in enumvalues_w: + enumvalues.append(space.c_int_w(w)) + except OperationError, e: + if not e.match(space, space.w_OverflowError): + raise + i = len(enumvalues) + raise operationerrfmt(space.w_OverflowError, + "enum '%s' declaration for '%s' does not fit an int", + name, enumerators[i]) ctype = ctypeenum.W_CTypeEnum(space, name, enumerators, enumvalues) return ctype 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 @@ -1156,6 +1156,13 @@ e = py.test.raises(TypeError, newp, BStructPtr, [None]) assert "must be a str or int, not NoneType" in str(e.value) +def test_enum_overflow(): + for ovf in (2**63, -2**63-1, 2**31, -2**31-1): + e = py.test.raises(OverflowError, new_enum_type, "foo", ('a', 'b'), + (5, ovf)) + assert str(e.value) == ( + "enum 'foo' declaration for 'b' does not fit an int") + def test_callback_returning_enum(): BInt = new_primitive_type("int") BEnum = new_enum_type("foo", ('def', 'c', 'ab'), (0, 1, -20)) @@ -2123,9 +2130,9 @@ py.test.raises(OverflowError, newp, BBoolP, 2) py.test.raises(OverflowError, newp, BBoolP, -1) BCharP = new_pointer_type(new_primitive_type("char")) - p = newp(BCharP, 'X') + p = newp(BCharP, b'X') q = cast(BBoolP, p) - assert q[0] == ord('X') + assert q[0] == ord(b'X') py.test.raises(TypeError, string, cast(BBool, False)) BDouble = new_primitive_type("double") assert int(cast(BBool, cast(BDouble, 0.1))) == 1 _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit