crystal-lang / crystal_lib

Automatic binding generator for native libraries in Crystal
138 stars 30 forks source link

Usage of unexposed enums leads to generation of broken bindings #66

Open olbat opened 4 years ago

olbat commented 4 years ago

Unexposed enums in struct fields lead to generation of bindings with Void as field's type. As struct's fields cannot have the Void type, the generated binding is broken.

To reproduce:

$ cat <<'EOF' > /tmp/bug.h
struct st {
    int a;
    enum { x, y } b;
};
struct st *test();
EOF

$ crystal src/main.cr <<'EOF'
@[Include("/tmp/bug.h", prefix: %w(test))]
lib LibTest
end
EOF

lib LibTest
  fun  = test : St*
  struct St
    a : LibC::Int
    b : Void
  end
end

When trying to use the binding, the following error is thrown at compile time: can't use Void as a struct field type.

olbat commented 4 years ago

I've proposed a fix for this in #67.