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

Can we support passing structs with array members? #113

Open
yallop opened this issue Dec 12, 2013 · 3 comments
Open

Can we support passing structs with array members? #113

yallop opened this issue Dec 12, 2013 · 3 comments

Comments

@yallop
Copy link
Owner

yallop commented Dec 12, 2013

Currently ctypes.foreign doesn't support passing or returning structs with array members, since there's no direct support for adding array members to structs in libffi.

If it's safe to assume that a struct with a member of type T[n] is passed in the same way as a struct with n members of type T, then we can add support by doing the equivalent of this: https://gist.github.com/TooTallNate/3797011.

@aziem
Copy link

aziem commented Feb 28, 2017

Is there a work-around for this issue at the moment? I googled around and couldn't find an answer.
I have a struct with an array member as below for which I am trying to create an equivalent OCaml type:

struct {...void *data[2]...}

Using the following fails:

let _ = field blah "data" (array 2 (ptr void))

I am using the stub generation to generate my bindings and the build fails saying that libffi does not support passing arrays. Is there a solution/work around? The build works if I do:

let _ = field blah "data" (ptr void)

but I don't think this is the correct way to handle this?

@yallop
Copy link
Owner Author

yallop commented Feb 28, 2017

Yes, stub generation supports structs with array members. There's a definition of such a struct in the testsuite:

  type triple
  let triple : triple structure typ = structure "triple"
  let elements = field triple "elements" (array 3 double)
  let () = seal triple

with a corresponding test that calls a C function.

@aziem
Copy link

aziem commented Feb 28, 2017

Sorry for the noise: I had made a silly mistake in my stub generation code and it's working now.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants