Re: Call variable length argument function from perl -> C using autogenerated code from xsubpp

[email protected] (Harakiri)
Newsgroups perl.xs
Message-ID <[email protected]>
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, [email protected] <[email protected]> wrote:

> From: [email protected] <[email protected]>
> Subject: Re: Call variable length argument function from perl -> C using autogenerated code from xsubpp
> To: "Harakiri" <[email protected]>
> Cc: [email protected]
> 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/[email protected]/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!
> > 
> > 
> > 
> 
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.