Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support recursive structs #103

Closed
ekrich opened this issue Jul 5, 2018 · 2 comments
Closed

Support recursive structs #103

ekrich opened this issue Jul 5, 2018 · 2 comments
Assignees
Labels
bindgen Binding generator
Milestone

Comments

@ekrich
Copy link
Member

ekrich commented Jul 5, 2018

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

@kornilova203
Copy link
Member

@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

@kornilova203 kornilova203 added the bindgen Binding generator label Jul 5, 2018
@jonas jonas added this to the 0.3 milestone Jul 6, 2018
@kornilova203 kornilova203 self-assigned this Jul 11, 2018
@kornilova203
Copy link
Member

Depends on #115

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bindgen Binding generator
Projects
None yet
Development

No branches or pull requests

3 participants