Wrap C function which takes variable lengthed parameters?

Gerhard Häring gh_pythonlist at gmx.de
Fri Dec 14 10:43:00 CET 2001

Le 13/12/01 à 23:57, Just van Rossum écrivit:
> Erik Max Francis wrote:
> > 
> > Courageous wrote:
> > 
> > > Ouch! There's a way to do this, if I recall. Something to do
> > > with generating the varargs and prepping it correctly. Whether
> > > or not you can do this _portably_ is not something that I recall.
> > 
> > Yes.  Varargs can be used to make a va_list and pass that into another
> > function.  Use of varargs and va_list are ANSI compliant.
> But you can't contstruct a va_list and pass it to a _vararg_ function;
> or at least it's not standard, portable, etc. See eg.
>   http://www.eskimo.com/~scs/C-faq/varargs/invvarargs.19920714.html
> Unless I missed something, I think this is what the OP wanted.

*g* I messed with that problem in my pyAda project (for writing Python
extensions in Ada 95). I finally read that section of the C FAQ, too,
but wanted to try nevertheless.

Finally I could come up with a very dirty stack maniupulation hack using
C macros and it worked on gcc/Linux/x86.  I was pretty sure it wouldn't
work on other platforms, and I was correct: as soon as I used doubles,
it went wrong on gcc/Solaris/SPARC.

mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id 86AB43C0
public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))

More information about the Python-list mailing list