Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r58844:7dd012b14d46 Date: 2012-11-12 19:50 +0100 http://bitbucket.org/pypy/pypy/changeset/7dd012b14d46/
Log: Update to cffi/86564854139f. diff --git a/pypy/module/_cffi_backend/__init__.py b/pypy/module/_cffi_backend/__init__.py --- a/pypy/module/_cffi_backend/__init__.py +++ b/pypy/module/_cffi_backend/__init__.py @@ -9,8 +9,6 @@ interpleveldefs = { '__version__': 'space.wrap("0.4")', - 'nonstandard_integer_types': 'misc.nonstandard_integer_types', - 'load_library': 'libraryobj.load_library', 'new_primitive_type': 'newtype.new_primitive_type', diff --git a/pypy/module/_cffi_backend/misc.py b/pypy/module/_cffi_backend/misc.py --- a/pypy/module/_cffi_backend/misc.py +++ b/pypy/module/_cffi_backend/misc.py @@ -95,35 +95,6 @@ # ____________________________________________________________ - -UNSIGNED = 0x1000 - -TYPES = [ - ("int8_t", 1), - ("uint8_t", 1 | UNSIGNED), - ("int16_t", 2), - ("uint16_t", 2 | UNSIGNED), - ("int32_t", 4), - ("uint32_t", 4 | UNSIGNED), - ("int64_t", 8), - ("uint64_t", 8 | UNSIGNED), - - ("intptr_t", rffi.sizeof(rffi.INTPTR_T)), - ("uintptr_t", rffi.sizeof(rffi.UINTPTR_T) | UNSIGNED), - ("ptrdiff_t", rffi.sizeof(rffi.INTPTR_T)), # XXX can it be different? - ("size_t", rffi.sizeof(rffi.SIZE_T) | UNSIGNED), - ("ssize_t", rffi.sizeof(rffi.SSIZE_T)), -] - - -def nonstandard_integer_types(space): - w_d = space.newdict() - for name, size in TYPES: - space.setitem(w_d, space.wrap(name), space.wrap(size)) - return w_d - -# ____________________________________________________________ - def _is_a_float(space, w_ob): from pypy.module._cffi_backend.cdataobj import W_CData from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveFloat 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 @@ -23,6 +23,14 @@ def eptype(name, TYPE, ctypecls): PRIMITIVE_TYPES[name] = ctypecls, rffi.sizeof(TYPE), alignment(TYPE) +def eptypesize(name, size, ctypecls): + for TYPE in [lltype.Signed, lltype.SignedLongLong, rffi.SIGNEDCHAR, + rffi.SHORT, rffi.INT, rffi.LONG, rffi.LONGLONG]: + if rffi.sizeof(TYPE) == size: + eptype(name, TYPE, ctypecls) + return + raise NotImplementedError("no integer type of size %d??" % size) + eptype("char", lltype.Char, ctypeprim.W_CTypePrimitiveChar) eptype("wchar_t", lltype.UniChar, ctypeprim.W_CTypePrimitiveUniChar) eptype("signed char", rffi.SIGNEDCHAR, ctypeprim.W_CTypePrimitiveSigned) @@ -40,6 +48,21 @@ eptype("long double", rffi.LONGDOUBLE, ctypeprim.W_CTypePrimitiveLongDouble) eptype("_Bool", lltype.Bool, ctypeprim.W_CTypePrimitiveBool) +eptypesize("int8_t", 1, ctypeprim.W_CTypePrimitiveSigned) +eptypesize("uint8_t", 1, ctypeprim.W_CTypePrimitiveUnsigned) +eptypesize("int16_t", 2, ctypeprim.W_CTypePrimitiveSigned) +eptypesize("uint16_t", 2, ctypeprim.W_CTypePrimitiveUnsigned) +eptypesize("int32_t", 4, ctypeprim.W_CTypePrimitiveSigned) +eptypesize("uint32_t", 4, ctypeprim.W_CTypePrimitiveUnsigned) +eptypesize("int64_t", 8, ctypeprim.W_CTypePrimitiveSigned) +eptypesize("uint64_t", 8, ctypeprim.W_CTypePrimitiveUnsigned) + +eptype("intptr_t", rffi.INTPTR_T, ctypeprim.W_CTypePrimitiveSigned) +eptype("uintptr_t", rffi.UINTPTR_T, ctypeprim.W_CTypePrimitiveUnsigned) +eptype("ptrdiff_t", rffi.INTPTR_T, ctypeprim.W_CTypePrimitiveSigned) # <-xxx +eptype("size_t", rffi.SIZE_T, ctypeprim.W_CTypePrimitiveUnsigned) +eptype("ssize_t", rffi.SSIZE_T, ctypeprim.W_CTypePrimitiveSigned) + @unwrap_spec(name=str) def new_primitive_type(space, name): try: 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 @@ -66,13 +66,6 @@ RTLD_NOLOAD RTLD_DEEPBIND -def test_nonstandard_integer_types(): - d = nonstandard_integer_types() - assert type(d) is dict - assert 'char' not in d - assert d['size_t'] in (0x1004, 0x1008) - assert d['size_t'] == d['ssize_t'] + 0x1000 - def test_new_primitive_type(): py.test.raises(KeyError, new_primitive_type, "foo") p = new_primitive_type("signed char") @@ -2499,3 +2492,9 @@ # res = GetLastError() assert res == 42 + +def test_nonstandard_integer_types(): + for typename in ['int8_t', 'uint8_t', 'int16_t', 'uint16_t', 'int32_t', + 'uint32_t', 'int64_t', 'uint64_t', 'intptr_t', + 'uintptr_t', 'ptrdiff_t', 'size_t', 'ssize_t']: + new_primitive_type(typename) # works _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit