Closed vsergeev closed 4 years ago
the problem here is slightly different than you think it is; note how you don't need bar_t
definition at all to raise the same error
cffi
never takes contents of anon structs into account when choosing a name for them, and it never considers contents for redefinitions (only name); the problem here is that when foo_t
is anonymous, and its inner struct is anonymous, by the time the inner struct is parsed the outer struct is not committed into the storage yet, and the name for anonymous structs is chosen like "take the number of structs already in storage, and use that". Which means, both of those structures get named struct 0
.
Ah, OK, I see. Yeah, I was able to simplify the test case to the first definition as you said:
ffi.cdef[[
typedef struct {
struct {
uint32_t a;
} inner1;
} foo_t;
]] -- expected: no error, get: input:1: 'struct 0' redefined
cffi-lua raises an error when redefining a nested anonymous struct within an anonymous struct. This is problematic in a codebase where two typedef anonymous structures happen to share a nested anonymous structure by sheer coincidence.
Note, however, redefinition of the nested anonymous structure is OK if the parent structure is named: