Open bew opened 7 years ago
I'm not really sure how this issue should be fixed .but some has to be removed/renamed ... (IMO it's a bad idea to typedef a struct with it's name but I've seen this kind of code in many libs)
Here is another example for the issue:
$ cat <<EOF > /tmp/test.h
struct SomeOpaque;
typedef int SomeOpaque;
SomeOpaque *some_function(struct SomeOpaque);
EOF
$ crystal run src/main.cr <<EOF
@[Include("/tmp/test.h", prefix: ["some"], remove_prefix: false)]
lib Test
end
EOF
lib Test
fun some_function(x0 : SomeOpaque) : SomeOpaque*
alias SomeOpaque = Void
alias SomeOpaque = LibC::Int
end
any updates on this one? it renders crystal_lib unusable for me atm..
Yeah, still problematic
Generates:
I've made a little program to test this (bew/crystal_lib - test.cr):
Outputs:
We can see that the
typedef
generates thealias
, and the function declaration generates thefun
and thetype
.Looking at the code, I've found that the
type
is generated when mapping the function argument: the argument type is parsed as aPointerType to a StructOrUnion
. In the mapping of the pointer, a check is made for an opaque type, succeeds, then creates a new typedef with the same name as thealias
.I'm not sure how we could properly fix this, as I like the way it auto creates a
type
ofPointer(Void)
for opaque types. Maybe we should rename the generatedtype
and addPtr
(or_
) at the end, to ensure there's no conflict. The example would be: