Commits

Armin Rigo committed f8d43ec

"Opaque" types, which become just non-filled structs in the backend.
Used for the syntax "typedef ... foo_t;".

  • Participants
  • Parent commits 4bf2208
  • Branches cpy-extension

Comments (0)

Files changed (3)

File cffi/cparser.py

                 if not decl.name:
                     raise api.CDefError("typedef does not declare any name",
                                         decl)
-                self._declare('typedef ' + decl.name,
-                              self._get_type(decl.type))
+                if (isinstance(decl.type.type, pycparser.c_ast.IdentifierType)
+                        and decl.type.type.names == ['__dotdotdot__']):
+                    realtype = model.OpaqueType(decl.name)
+                else:
+                    realtype = self._get_type(decl.type)
+                self._declare('typedef ' + decl.name, realtype)
             else:
                 raise api.CDefError("unrecognized construct", decl)
 

File cffi/model.py

         self.check_not_partial()
         return ffi._backend.new_enum_type(self.name, self.enumerators,
                                           self.enumvalues)
+
+
+class OpaqueType(BaseType):
+    _attrs_ = ('name',)
+
+    def __init__(self, name):
+        self.name = name
+
+    def get_c_name(self, replace_with=''):
+        return self.name + replace_with
+
+    def new_backend_type(self, ffi):
+        return ffi._backend.new_struct_type('$' + self.name)

File testing/test_verify.py

     assert lib.bar(None) == 42
 
 def test_missing_typedef():
-    py.test.skip("in-progress")
     ffi = FFI()
     ffi.cdef("typedef ... foo_t; int bar(foo_t *);")
-    py.test.raises(VerificationMissing, ffi.new, "foo_t")
+    py.test.raises(TypeError, ffi.new, "foo_t")
     lib = ffi.verify("typedef struct foo_s { int x; } foo_t;\n"
                      "int bar(foo_t *f) { return 42; }\n")
-    f = ffi.new("foo_t")
+    py.test.raises(TypeError, ffi.new, "foo_t")
+    f = ffi.cast("foo_t*", 0)
     assert lib.bar(f) == 42