Davoud Taghawi-Nejad
Davoud Taghawi-Nejad

Reputation: 16826

cython: how to declare a cdef function that has no return

when I declare a cdef function that returns a double I write cdef double method_name(...). If it does not return something and I just omit it to cdef method_name(...) then cython --annotate marks it yellow. How to declare that the method/function does not return anything?

cdef void method_name(...) crashes with a segmentation fault

cdef None method_name(...) -> 'None' is not a type identifier

Upvotes: 4

Views: 5324

Answers (3)

Davoud Taghawi-Nejad
Davoud Taghawi-Nejad

Reputation: 16826

A bug in Cython version 0.22. Update to 0.23.4 solved it.

Upvotes: 0

paugier
paugier

Reputation: 1878

For me (cython 0.21.1) defining the c function with void works:

# mymod.pyx file

cdef void mycfunc(int* a):
    a[0] = 2

def myfunc():
    cdef int a = 1
    mycfunc(&a)
    print(a)

The c function is not yellow in the annotated html file and

python -c 'from mymod import myfunc; myfunc()'

prints 2 as expected.

Upvotes: 2

Tedil
Tedil

Reputation: 1933

--annotate marks it as yellow as cython assumes the return type to be a python object if you omit the return type annotation (Cython Language Basics).

Specifying void as return type works for me. It's also used in quite some of the official examples, Just make sure not to return anything.

Upvotes: 3

Related Questions