Create a ctypes binding to a C function with a variable argument arg

Assuming I have a C function with a list of arguments of variable length:

int some_func(int arg1 , ... ); 

Is it possible (just?) To call this function from python using ctypes?

Update:

Realized cedric offer and working like a charm:

 libc = ctypes.CDLL( "/lib64/libc.so.6" , ctypes.RTLD_GLOBAL ) printf = getattr( libc , "printf") printf("String1:%s int:%d String2:%s double:%lg\n" , "Hello" , 10 , "World" , ctypes.c_double( 3.1415 )) 

The ctypes.c_double () function is the only minor interference. So - it was all easier than me; however, I assume the fxxx option with va_args remains the same.

+4
source share
1 answer

Assuming you can bind the libc printf function, this is a really good example of using va_args, I think you can create a binding to any function.

+2
source

All Articles