The mm_array_push routine I sent is by definition a variable-length
parameter list XS routine because it uses the '...' notation.  This
is a feature of XS that allows perl callers to include as many
parameters at the end of a call as they like.  I'm sure that you have
read the documentation of the XS feature at
http://perldoc.perl.org/perlxs.html#Variable-length-Parameter-Lists

This feature has the same objective as the same notation '...' in C,
but I'm pretyy sure the XS feature was never intended to provide an
automatic interface to C functions that use this notation.  The
latter feature is documented nicely at
http://en.wikipedia.org/wiki/ Variadic_function#Variadic_functions_in_C.2C_Objective-C.2C_C.2B.2B. 2C_and_D

The problem of using the former to interface the latter is discussed at
http://www.perlmonks.org/?node_id=684623
You might find it useful to email the perlmonks correspondent who
started the thread above, to ask if he found a solution he liked.

For any given routine, it would be pretty simple to write an interface
routine that accumulates the variable operands in an array (like my
mm_array_push does).  The other half of the solution would be to
modify the C target routine to receive a pointer to the array as an
operand, and use it rather than an internal 'va_list' as described
in the second link above.  But this is not automatic in the sense
you want.

Best Regards,
cmac


On Mar 2, 2011, at 10:22 AM, Harakiri wrote:

Thank you, but it seems you manually created the XS mm_array_push (array, ...) stub logic and then used to translate it with xsubpp, besides this looks like an array not an var argument list

i only have a simple header file with my function signatures and generic xs where this header is included


--- On Wed, 3/2/11, macke...@animalhead.com <macke...@animalhead.com> wrote:

From: macke...@animalhead.com <macke...@animalhead.com>
Subject: Re: Call variable length argument function from perl -> C using autogenerated code from xsubpp
To: "Harakiri" <harakiri...@yahoo.com>
Cc: perl-xs@perl.org
Date: Wednesday, March 2, 2011, 12:41 PM
var arg lists are supported in perl
-> c.
Here is an interface routine (from a .xs file) that
implements
pushing into an array:

UV
mm_array_push (array, ...)
    mm_array *array
    ALIAS:
        mma_array_push=1
    PREINIT:
        int add_count = items - 1;
        SV *addSVs[add_count];
        int i;
    CODE:
        for (i=0; i < add_count; i++) addSVs[i] = ST(i+1);
        if (!mm_array_splice (array, array->entries, 0, NULL,
            add_count, addSVs, ix) && PL_dowarn && mm_error())
            warn ("IPC::MMA: %s", mm_error());
        RETVAL = array->entries;
    OUTPUT:
        RETVAL

This routine is converted by xsubpp into the one below by
the
following automatic step in the module's 'make' stage:
/usr/bin/perl /usr/local/lib/perl5/5.10.1/ExtUtils/xsubpp
-typemap /usr/local/lib/perl5/5.10.1/ExtUtils/typemap
-typemap typemap  MMA.xs > MMA.xsc && mv
MMA.xsc MMA.c


XS(XS_IPC__MMA_mm_array_push)
{
#ifdef dVAR
    dVAR; dXSARGS;
#else
    dXSARGS;
#endif
    dXSI32;
    if (items < 1)
       croak_xs_usage(cv,
"array, ...");
    {
    mm_array *    array;
#line 1771 "MMA.xs"
        int add_count = items - 1;
        SV *addSVs[add_count];
        int i;
#line 2427 "MMA.c"
    UV    RETVAL;
    dXSTARG;

    if (sv_derived_from(ST(0),
"mm_arrayPtr")) {
        IV tmp =
SvIV((SV*)SvRV(ST(0)));
        array = INT2PTR(mm_array
*,tmp);
    }
    else
        Perl_croak(aTHX_ "%s: %s
is not of type %s",

GvNAME(CvGV(cv)),

"array", "mm_arrayPtr");
#line 1775 "MMA.xs"
        for (i=0; i < add_count;
i++) addSVs[i] = ST(i+1);
        if (!mm_array_splice (array,
array->entries, 0, NULL, add_count, addSVs, ix)
         && PL_dowarn
&& mm_error()) warn ("IPC::MMA: %s", mm_error());
        RETVAL = array->entries;
#line 2444 "MMA.c"
    XSprePUSH; PUSHu((UV)RETVAL);
    }
    XSRETURN(1);
}

On Mar 2, 2011, at 8:19 AM, Harakiri wrote:

Hello,

i've searched the mailing list and found an entry from
2001 that var arg list were not supported in perl -> c :

http://www.mail-archive.com/perl-xs@perl.org/msg00345.html

Has this changed?

Im using the xsubpp util to create my glue cpp
classes.

Example:

static int Random( int Count, ... );

turns into

XS(XS_MyClass_Random)
{
         dXSARGS;
         if (items <
2)

   Perl_croak(aTHX_ "Usage:
MyClass::Random(CLASS, Count, ...)");
         {

   char *
CLASS = (char *)SvPV_nolen(ST(0));

   int
   RETVAL;

   dXSTARG;

   int
   Count = (int)SvIV(ST(1));


   RETVAL = MyClass::Random(Count);

   XSprePUSH; PUSHi((IV)RETVAL);
         }
         XSRETURN(1);
}

as you can see the "..." is not honored, only the
first argument is used. I know i could manually glue this
somehow but i DONT want that because i have alot of method
signatures which always have been converted fine using
xsubpp - i dont want to manually alter the generated file
just for one method.

Is there a way?

Thank you!









Reply via email to