scala-native / scala-native-bindgen

Scala Native Binding Generator

Home Page:https://scala-native.github.io/scala-native-bindgen/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support recursive structs

ekrich opened this issue · comments

Currently, a recursive struct causes an error message and does not get generated but other code generates which is good. Example error follows:

Error: struct___darwin_pthread_handler_rec is cyclic
struct___darwin_pthread_handler_rec
    Unit
    struct___darwin_pthread_handler_rec
    void (void *)
1

Scala Native does not support this feature directly as far as I know so I believe that that the inner struct would have to be a Ptr[Byte] and casting by the client code is needed to access the field.

Related: #77

@ekrich, thanks!
For recursive pointers bindgen generates pointer to CArray that has the same size as structure:

struct node {
    struct node *next;
    int value;
};
type struct_node = native.CStruct2[native.Ptr[native.CArray[Byte, native.Nat.Digit[native.Nat._1, native.Nat._6]]], native.CInt]

But it is too complicated and can be simplified to:

type struct_node = native.CStruct2[native.Ptr[Byte], native.CInt]

Also we can modify helper setters and getters such that they will cast pointers.

In #77 structs are not recursive so CStruct... type may be used there.

Similar Scala Native issue scala-native/scala-native#634

Depends on #115