I have a function wrapped in Cython:
cdef extern from "myheader.h":
int c_my_func (const_char *a, const_char* b)
And a function exposed to Python:
def my_func(a, b):
c_my_func(a, b)
The function c_my_func accepts NULL for parameters a and b. When I call it from the interpreter:
my_func(None, None)
it throws the exception:
TypeError: expected string or Unicode object, NoneType found
How do I make this function accept the None and pass NULL to the c_my_func ? I don’t want to manually check for the None and then pass NULL. I also tried using default parameters on the cdef of the c_my_func and it doesn’t worked.
You can find the answer in the Cython FAQ.
The solution is to manually check for
Noneand pass NULL, as you write.