Commits

Armin Rigo committed f8d43ec

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

Comments (0)

Files changed (3)

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

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
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.