crystal-lang / crystal_lib

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

Weird typedef struct is translated incorrectly #12

Open aladagemre opened 8 years ago

aladagemre commented 8 years ago

When generating binding for igraph see

https://github.com/igraph/igraph/blob/a98fccd3fb2a9f67551a09d4159ef268ee62c658/include/igraph_datatype.h

typedef struct igraph_s {
  igraph_integer_t n;
  igraph_bool_t directed;
  igraph_vector_t from;
  igraph_vector_t to;
  igraph_vector_t oi;
  igraph_vector_t ii;
  igraph_vector_t os;
  igraph_vector_t is;
  void *attr;
} igraph_t;

This code is translated into

struct S
  n : IntegerT
  directed : BoolT
  from : VectorT
  to : VectorT
  oi : VectorT
  ii : VectorT
  os : VectorT
  is : VectorT
  attr : Void*
end
type T = S

And then uses T* whenever functions indeed expect S. When we replace all T with S*, the code works.

aladagemre commented 8 years ago

https://github.com/aladagemre/crystal-igraph/blob/0ce58a79bdeab565af3dca6e19bcfbf2285b9b9c/lib_igraph.cr

asterite commented 8 years ago

I'm not sure what's the issue. Is it that T is used instead of T*? The type declaration seems fine, although maybe in those cases declaring the struct as struct T (without declaring S) should be good?

aladagemre commented 8 years ago

when I use T.new, it says T doesn't have method new. When I try to cast T to S, it says S can't be casted to T.

I don't know what's the reason for this.