Closed linkmauve closed 1 year ago
We hit this with Linux kernel code like https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/include/linux/maple_tree.h#n75.
I think providing a customizable prefix/suffix or moving the typedef
inside a module with a customizable name would be the best.
I have a potential fix for this but I have a tiny confusion about C semantics here. Let's say we have this
typedef const struct foo {
void *bar;
} *foo_ptr;
struct foo returns_struct();
foo_ptr returns_ptr();
If now we remove the _ptr
prefix we have:
typedef const struct foo {
void *bar;
} *foo;
struct foo returns_struct();
foo returns_ptr();
so, neither gcc
nor clang
complain about this so my question is: does returns_struct
still returns a struct? or a pointer to a struct?
The struct (struct foo
) and the alias (foo
) are in different C name spaces (tag vs. ordinary). returns_struct()
indeed returns the struct in both cases, because using struct
before foo
will make it look for the identifier in the tag name space.
By the way, the Maple tree removed the problematic typedef
s in the kernel, so at the moment we should not be triggering this issue.
Input C/C++ Header
Bindgen Invocation
Actual Results
and/or
Expected Results
I’m not quite sure, as the issue is that
struct *
and*
are two “namespaces” in C, and not in C++ or Rust. One solution would be to rename either the pointer typedef or the struct, another would be to not include the pointer typedef at all (but then people might get confused why it isn’t present, so perhaps emit a warning as well?), or at least reject the input file altogether as the result won’t be well-formed anyway.The project in question uses this hack when built under C++, so for my usecase I could
#define __cplusplus
in order to run bindgen in C++ mode: