http://therning.org/magnus/archives/344 asks Hoosgot,
Dear lazyweb, I’ve been racking my brain trying to get information out of the following C struct in a nice way when using ctypes: struct Foo { unsigned int length; char name ; }; I wrote a little C function to get instance of the struct easily into python: struct Foo * put_name(char *name) { struct Foo *foo = malloc(sizeof(struct Foo) + strlen(name)); foo->length = strlen(name); memcpy(foo->name, name, foo->length); return(foo); } Now, how do I actually get the full contents of Foo.name in python? The only way I could think of that actually works is to create a dummy-struct type in order to get the length out and then use it to dynamically create a new sub-class of ctypes.Structure, then … Visit the blog to lend your wisdom, or you can comment below.ctypes and flexible (zero-length) arrays
April 9th, 2008 · No Comments
Tags: Uncategorized
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment