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

Support for flexible array members #353

Open
yallop opened this issue Feb 17, 2016 · 4 comments
Open

Support for flexible array members #353

yallop opened this issue Feb 17, 2016 · 4 comments

Comments

@yallop
Copy link
Member

@yallop yallop commented Feb 17, 2016

A common pattern in C libraries is to make the final member of a struct an array whose length is determined at runtime, like this example from the sanlock library:

struct sanlk_resource {
    char lockspace_name[SANLK_NAME_LEN]; /* terminating \0 not required */
    char name[SANLK_NAME_LEN]; /* terminating \0 not required */

       /* ... */

    uint32_t num_disks;
    /* followed by num_disks sanlk_disk structs */
    struct sanlk_disk disks[0];
};

Ctypes doesn't currently offer much/any support for this pattern, but it's sufficiently common that we ought to support it.

@yallop
Copy link
Member Author

@yallop yallop commented Feb 17, 2016

@simonjbeaumont
Copy link

@simonjbeaumont simonjbeaumont commented Feb 18, 2016

@yallop thanks for confirming the workaround too :)

@simonjbeaumont
Copy link

@simonjbeaumont simonjbeaumont commented Mar 31, 2016

I took the time to blog about the current workaround when these are required. http://simonjbeaumont.com/posts/ocaml-ctypes-flexible-array-member/

@yallop
Copy link
Member Author

@yallop yallop commented Mar 31, 2016

Thanks! These blog posts are extremely useful.

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.