Commits

Armin Rigo committed 7dd012b

Update to cffi/86564854139f.

  • Participants
  • Parent commits b5e5638

Comments (0)

Files changed (4)

File pypy/module/_cffi_backend/__init__.py

     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',

File pypy/module/_cffi_backend/misc.py

 
 # ____________________________________________________________
 
-
-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

File pypy/module/_cffi_backend/newtype.py

 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)
 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:

File pypy/module/_cffi_backend/test/_backend_test_c.py

         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")
     #
     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