开发者

Create ctypes binding to C function with variable length arg list

Assuming I have C function with variable length argument list:

int some_func(int arg1 , ... );

Is it possible (easy?) to call this function from python using ctypes?

Update:

Implemented suggestion开发者_Go百科 from cedric and that worked like 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 ))

With the ctypes.c_double( ) function as the only minor nuisance. So - all in all this was easier than I though; however I guess the possiblity to fxxx up with va_args remains the same.


Assuming you can bind the libc printf function, that is a really good example of va_args using, I think you'll be able to create a binding with any function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜