I am attempting to use Cython to wrap an external C library which has several functions which use the ellipsis (...) as part of the signature. The code here provides a partial solution to the problem. The relevant portion for my question is
cdef int foo(int n, ...):
// Print the variable number of arguments
def call_foo():
foo(1, 2, 3, 0)
foo(1, 2, 0)
This will output 1, 2, 3
and 1, 2
which is fine, as far as it goes. However, what I need to be able to do is pass the variable arguments through Python. Something like
def call_foo(*args):
foo(args)
call_foo(1,0)
call_foo(1,2,3,4,0)
However, while the above code will compile, upon execution I get a TypeError:
File "cytest.pyx", line 31, in cytest.call_foo (cytest.cpp:915)
foo(args)
TypeError: an integer is required
An alternate form,
def call_foo(*args):
foo(args[0],args[1:])
call_foo(1,0)
call_foo(1,2,3,4,0)
results in a compile error:
cytest.pyx:30:24: Python object cannot be passed as a varargs parameter
Is there any way to accomplish this using Cython, or will I have to rewrite the C functions?