Wrap C function which takes variable lengthed parameters?

{-- Rot13 - Hateme ungrzr2 at ubatxbat.pbz
Fri Dec 14 22:49:33 EST 2001


"{-- Rot13 - Hateme" <ungrzr2 at ubatxbat.pbz> wrote in 
news:Xns91785CD91CF46YouAreNotMeYouKnow at 218.102.23.34:
> 
> I try to find a standard way to build a va_list at runtime.
> Or maybe there some way for python C API which can pass me
> a va_list from python code(not really feasible, I think.)

After some more searching, it seems impossible to 
create a va_list or call a varidic function at runtime
in C.

So there is no easy way to write python wrappers for
functions which takes variable length arguments.

A possible way is to use the libffi from redhat
http://sources.redhat.com/libffi/
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libffi/README?rev=1.8
&content-type=text/x-cvsweb-markup&cvsroot=libffi

and create a cif(call interface) dynamically.
Then call the function with the cif. Though in
the README, it said libffi does not support varargs
functions yet. I take that it means the number of
arguments have to be known at the time the cif is
created.

I have no actually test the libffi route, hopefully
it might work with my case.

Thank for everyone that helped.
And I really hope python will provide some way to ease
the wrapping on varargs functions some day. But it is 
hard.



More information about the Python-list mailing list