On Aug 21, 2004, at 10:42 PM, Sisyphus wrote:
I've struck something similar. I was trying the following (which I thought *should* work, but which prints out a couple of wrong values, then segfaults):
[...]

It looks to me like this is an Inline bug/nonfeature, not a generic C issue. Look at the XS code that Inline produces:


---------------------------------------------------------------------
void wrap1(SV * a, ...) {
     Inline_Stack_Vars;
     int i;
     va_list ap;

     va_start(ap, a);

     for(i = 1; i < Inline_Stack_Items; ++i)
        printf("%#o ", SvIV(va_arg(ap, SV *)));

     va_end(ap);
     printf("\n");
   }



MODULE = va_arg_pl_efc5 PACKAGE = main

PROTOTYPES: DISABLE

void
wrap1 (a, ...)
        SV *    a
        PREINIT:
        I32* temp;
        PPCODE:
        temp = PL_markstack_ptr++;
        wrap1(a);
        if (PL_markstack_ptr != temp) {
          /* truly void, because dXSARGS not invoked */
          PL_markstack_ptr = temp;
          XSRETURN_EMPTY; /* return empty stack */
        }
        /* must have used dXSARGS; list context implied */
        return; /* assume stack size is correct */
---------------------------------------------------------------------


Observe that it's only passing a single argument to the C function wrap1(). If instead of calling wrap1() it just inlined its C code into the XS function, I think it could work fine. The trouble is that the XS code, when converted to C code, doesn't have a variable-length argument list (its prototype is 'void XS_main_wrap1(pTHX_ CV* cv)'), and I'm not really sure how to get around that. Anyone else have ideas?


 -Ken



Reply via email to