NotImplementedError on anonymous union of a structure containing "..." in its definition
Created originally on Bitbucket by vsergeev (Ivan Sergeev)
This issue is specific to using the "..." fill-in in the API mode of CFFI.
Example 1:
ffi.set_source("test", """
#define BUF_SIZE 8
struct foo {
uint8_t buf[BUF_SIZE];
};
struct bar {
union {
struct foo f;
int x;
} data;
};
""")
ffi.cdef("""
struct foo {
uint8_t buf[...];
};
struct bar {
union {
struct foo f;
int x;
} data;
};
""")
Traceback (most recent call last):
File "test.py", line 30, in <module>
""")
File "/usr/lib/python3.4/site-packages/cffi/api.py", line 107, in cdef
self._parser.parse(csource, override=override, packed=packed)
File "/usr/lib/python3.4/site-packages/cffi/cparser.py", line 167, in parse
self._internal_parse(csource)
File "/usr/lib/python3.4/site-packages/cffi/cparser.py", line 186, in _internal_parse
self._parse_decl(decl)
File "/usr/lib/python3.4/site-packages/cffi/cparser.py", line 260, in _parse_decl
self._get_struct_union_enum_type('struct', node)
File "/usr/lib/python3.4/site-packages/cffi/cparser.py", line 543, in _get_struct_union_enum_type
type = self._get_type(decl.type, partial_length_ok=True)
File "/usr/lib/python3.4/site-packages/cffi/cparser.py", line 390, in _get_type
return self._get_struct_union_enum_type('union', type, name)
File "/usr/lib/python3.4/site-packages/cffi/cparser.py", line 547, in _get_struct_union_enum_type
self._make_partial(tp, nested)
File "/usr/lib/python3.4/site-packages/cffi/cparser.py", line 568, in _make_partial
raise NotImplementedError("%s is partial but has no C name" %(tp,))
NotImplementedError: <union $1> is partial but has no C name
Example 2, a named union (union zzz
) works:
ffi.set_source("test", """
#define BUF_SIZE 8
struct foo {
uint8_t buf[BUF_SIZE];
};
struct bar {
union zzz {
struct foo f;
int x;
} data;
};
""")
ffi.cdef("""
struct foo {
uint8_t buf[...];
};
struct bar {
union zzz {
struct foo f;
int x;
} data;
};
""")
Example 3, using the anonymous union but providing the size of buf
explicitly with buf[8]
instead of buf[...]
works:
ffi.set_source("test", """
#define BUF_SIZE 8
struct foo {
uint8_t buf[BUF_SIZE];
};
struct bar {
union {
struct foo f;
int x;
} data;
};
""")
ffi.cdef("""
struct foo {
uint8_t buf[8];
};
struct bar {
union {
struct foo f;
int x;
} data;
};
""")
I am guessing this might be an issue of cdef()
of not knowing the exact size struct foo
when forming the union type in example 1, but being able to defer to it later in example 2 via the union name.
I'm not sure if this is easy to resolve, but I figured I would document it in an issue here in case others encounter this and are looking for workarounds.