I need to convert regexitem *regex to ctype variable, any ideas?
C function expects func(regexitem *regex)
char *regex1Groups[] = { "a","b","x","s" ,NULL};
char *regex2Groups[] = { "l" ,NULL};
regexitem regex[] = {
{"bla", regex1Groups,4 },
{"bla2",regex2Groups,1 }
};
First i defined
class regexitem(Structure):
_fields = ("regex",c_char_p), ("groups",c_char_p*size), ("groupsize",c_int)
and ran into first problem, declaring array of regexitem because size of groups is not known in advance.
Structs can only contain variable-length arrays at their ends, and on top of that when you assign an array variable to something you aren’t copying it, you’re assigning the memory location of the first element of the array. So I’m betting that your
regexitemstruct contains a pointer to the array ofcharpointers rather than containing the array ofcharpointers itself. If that’s the case, this might work:(You can keep the assignment to
_fields_as a tuple of tuples rather than a list of tuples if you want to.)Oh, for your regex groups, it’d be something like this:
And then your array of
regexitems would be like so:Look through the
ctypesdocumentation if you want to know more.http://docs.python.org/library/ctypes.html