Python 如何将指向struct的指针与NULL进行比较?

Python 如何将指向struct的指针与NULL进行比较?,python,null,cython,Python,Null,Cython,我在Cython有这个: cdef extern from "lib/bindings.h": ctypedef struct parser: yyscan_t yyscanner ... 和相关的C代码: typedef struct { yyscan_t yyscanner; ... } _parser, *parser; 现在,当我尝试: cdef parser p = ... if p != NULL: ... 并获得

我在Cython有这个:

cdef extern from "lib/bindings.h":
    ctypedef struct parser:
        yyscan_t yyscanner
        ...
和相关的C代码:

typedef struct {
    yyscan_t yyscanner;
    ...
} _parser, *parser;
现在,当我尝试:

cdef parser p = ...
if p != NULL:
    ...
并获得:

Invalid types for '!=' (parser, void *)

为什么??Cython是否曲解了解析器的声明?似乎它不“理解”解析器是指针类型。

Cython根本不读取您的C代码-它只是盲目地包含相关文件,并使用Cython
ctypedef
来理解发生了什么。由于您没有在Cython代码中显示指针,因此无法知道
解析器
是指针类型

正确的声明应该是

cdef extern from "lib/bindings.h":
    ctypedef struct _parser:
        yyscan_t yyscanner
        # ...
    ctypedef _parser* parser