Buzz Moschetti <[EMAIL PROTECTED]> writes: >I had worked up something for HPUX and SunOS some years back. I will post >if folks are interested. Thought this might be a standard in the XS arena >by now.
Saddly this is very hard. You say HPUX and SunOS, but you probably mean HP PA/SPARC. What C's ... does is CPU architecture specific not OS related. (See GCC's <stdarg.h> support to see the mess from the other side.) On some machines it is impossible to fake a ... call from C e.g. those where 1st few args are always passed in machine regs. Other machines where ... forces all args to be passed on C call stack are a little easier. You can usually fake a va_list so if the is a vffedit(char *fmt, va_list ap) available then with some pain and a lot of processors specific hackery you can build an ap and call that. There is package ffcall which has done most of the hard work. > >-----Original Message----- >From: Dirk Koopman [mailto:[EMAIL PROTECTED] >Sent: Friday, October 03, 2003 8:37 AM >To: Perl XS Mailing List >Subject: interfacing to (v)sprintf type things that expect varargs > > >Subject says it all really. > >I have a number of vararg based routines that accept a number of >optional arguments. > >Given that I know how to get these values from the stack (fortunately >[most of the time] I know what they are), do you have any suggestions as >to how I can reassemble the actual program stack from the perl stack so >that I can call these routines in C. > >For example the perl XS prototype:- > >int >ffedit(fmt,...) > char *fmt; > > >That needs to translate to the C function: int ffedit(char *fmt, ...) in >real life. If ffedit's behaviour is similar to printf's then same technique as used in perl core for print can be used. This is (roughly): Incrementally parse fmt string your self to find out a type. Convert one perl arg to the required type in a switch() on type. In each case: of the switch call C routine with fragment of fmt string and one arg. Loop till you get to the end of the fmt string. > >Dirk > > >*********************************************************************** >Bear Stearns is not responsible for any recommendation, solicitation, >offer or agreement or any information about any transaction, customer >account or account activity contained in this communication. >***********************************************************************
