python - Cython and regex.h -


i relatively new cython, apologies if question seems basic.

there parallelizable block of regex matching, , i'd run cython , nogil. avoid using python objects, plan import regex.h.

the following import segment compiles:

cdef extern "regex.h" nogil:    ctypedef struct regoff_t    ctypedef struct regex_t    ctypedef struct regmatch_t    int regcomp(regex_t* preg, const char* regex, int cflags)    int regexec(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags)  def matchpatterns(str pagecontent, str regex):    cdef set matchingpatterns = set()    return matchingpatterns 

but make use of regex_t or of functions, error: contentmatchpatterncython.pyx:10:16: variable type 'regex_t' incomplete

if remove empty ctypedefs, code not compile regex_t undefined. obviously, think/hope there's way forward without duplicating struct definition in cython.

i'm using python 2.7.2 , cython 0.22. pointers received gratitude.

http://docs.cython.org/src/userguide/external_c_code.html

to directly quote documentation:

if header file declares big struct , want use few members, need declare members you’re interested in. leaving rest out doesn’t harm, because c compiler use full definition header file.

in cases, might not need of struct’s members, in case can put pass in body of struct declaration, e.g.:

cdef extern "foo.h":     struct a:         pass     # or (i've added bit - not in documentation directly...)     ctypedef struct b:         pass 

which of these use depends if you're matching c code reads struct {} or typedef struct {} b.


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -