我对Cython比较陌生,所以如果这个问题看起来很基本的话,我很抱歉。在
有一个可并行化的regex匹配块,我想用Cython和nogil
来运行它。为了避免使用Python对象,我的计划是导入regex.h
。在
以下导入段编译:
cdef extern from "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
但是一旦我使用了regex_t
或它的任何函数,我就会得到一个错误:contentMatchPatternCython.pyx:10:16: Variable type 'regex_t' is incomplete
如果我删除空的ctypedef
,代码不会编译为regex_t
未定义。显然,我认为/希望有一种方法可以避免重复Cython中的结构定义。在
我使用的是python2.7.2和cython0.22。如有任何建议,我们将不胜感激。在
http://docs.cython.org/src/userguide/external_C_code.html
要直接引用文档:
使用哪一个取决于您是匹配读取}的C代码。在
struct A {}
还是{相关问题 更多 >
编程相关推荐