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

Is there a good way to specify struct return types for CEnv c_func_defs? #6

Closed
jordan-schneider opened this issue Jul 27, 2021 · 1 comment

Comments

@jordan-schneider
Copy link

I want to add a function to a CEnv environment that returns a struct.

cffi exposes the ffi.new() (doc) function to allow array and struct types to be defined. Otherwise, ffi.cdef won't understand the struct type in the function signature. Is there some good way to pass the struct name to CEnv so that it will be loaded in time for the ffi.cdef of the function signature to catch it?

@jordan-schneider
Copy link
Author

I apologize, I was misunderstanding how cffi works. In order to define a custom struct you need to make a cdef call defining the full struct ahead of time.

super.__init__(
  ...,
  c_func_defs=["struct s {int a; float b;};", "struct s func();"]
)

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

1 participant