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

Comments

Projects
None yet
2 participants
@yallop
Member

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

This comment has been minimized.

Show comment
Hide comment
@yallop
Member

yallop commented Feb 17, 2016

@simonjbeaumont

This comment has been minimized.

Show comment
Hide comment
@simonjbeaumont

simonjbeaumont Feb 18, 2016

@yallop thanks for confirming the workaround too :)

simonjbeaumont commented Feb 18, 2016

@yallop thanks for confirming the workaround too :)

@simonjbeaumont

This comment has been minimized.

Show comment
Hide comment
@simonjbeaumont

simonjbeaumont 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/

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

This comment has been minimized.

Show comment
Hide comment
@yallop

yallop Mar 31, 2016

Member

Thanks! These blog posts are extremely useful.

Member

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