Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Generate C wrappers for functions that pass structs by value #40

Open
kornilova203 opened this issue Jun 7, 2018 · 0 comments
Open
Labels
bindgen Binding generator bug Something isn't working

Comments

@kornilova203
Copy link
Member

Scala code will not compile if there are structs that are passed by value.
Example:

struct MyStruct {
    int a;
};

struct OtherStruct {
    struct MyStruct s;
};

This Scala code will not compile:

@native.link("Lib")
@native.extern
object Lib {
  type struct_MyStruct = native.CStruct1[native.CInt]
  type struct_OtherStruct = native.CStruct1[struct_MyStruct]
}

import Lib._

object LibMembersHelpers {
  implicit class struct_OtherStruct_ops(val p: native.Ptr[struct_OtherStruct]) extends AnyVal {
    def s: struct_MyStruct = !p._1 // error
    def s_=(value: struct_MyStruct):Unit = !p._1 = value // error
  }
}

One possible solution - remove declarations that use structs by value.
Another - generate C code that converts struct to a pointer

@kornilova203 kornilova203 added the bug Something isn't working label Jun 7, 2018
@jonas jonas added the bindgen Binding generator label Jun 25, 2018
@kornilova203 kornilova203 changed the title Do something about structs that are passed by value Generate C wrappers for functions that pass structs by value Jul 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bindgen Binding generator bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants