On Tue, 22 May 101, Tye McQueen wrote:

> dXSARGS is what declares 'targ'.  Since you don't give us
> the full source and I can't find any documentation stating

Ok - I knocked out a noddy example, so all my struct-to-object crud doesn't
get in the way, and I don't reveal anything I'm not supposed to by accident:

[I'm not sure if it's Ok to send attachments to this list, so:]


The XS file:

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

static int
not_here(char *s)
{
    croak("%s not implemented on this architecture", s);
    return -1;
}

static double
constant(char *name, int arg)
{
    errno = 0;
    switch (*name) {
    }
    errno = EINVAL;
    return 0;

not_there:
    errno = ENOENT;
    return 0;
}


MODULE = foo            PACKAGE = foo           


double
constant(name,arg)
        char *          name
        int             arg

void 
foolist(n)
   int n
   PREINIT:
   int i;
   PPCODE:
   EXTEND( SP, (n + 1) );
   for(i = 0; i <= n; n++)
   {
       PUSHi( i );
   }


The generated code in foo.c:

XS(XS_foo_foolist)
{
    dXSARGS;
    if (items != 1)
        croak("Usage: foo::foolist(n)");
    SP -= items;
    {
        int     n = (int)SvIV(ST(0));
#line 39 "foo.xs"
   int i;
#line 65 "foo.c"
#line 41 "foo.xs"
   EXTEND( SP, (n + 1) );
   for(i = 0; i <= n; n++)
   {
       PUSHi( i );
   }
#line 72 "foo.c"
        PUTBACK;
        return;
    }
}

And finally, the cpp'd code [I've added a few newlines, and chopped out
the rest of the functions - let me know if you want the whole thing]:

gcc -I/usr/lib/perl5/5.005/i386-linux/CORE -E - 

void  XS_foo_foolist (CV* cv) 
{
    extern int (*__errno_location ())  ; 
    register SV **sp = PL_stack_sp ; 
    register SV **mark = PL_stack_base + (*PL_markstack_ptr--)  ;
    I32 ax = mark - PL_stack_base + 1;  
    I32 items = sp - mark ;
    if (items != 1)
        Perl_croak ("Usage: foo::foolist(n)");
    sp  -= items;
    {
        int     n = (int)(((   PL_stack_base[ax + ( 0 )]    )->sv_flags  &
0x00010000 )  ? ((XPVIV*)  (   PL_stack_base[ax + ( 0 )]    )->sv_any
)->xiv_iv  : Perl_sv_2iv ( PL_stack_base[ax + ( 0 )]  )) ;
# 38 "foo.xs"

   int i;
# 64 "foo.c"

# 40 "foo.xs"

   (void)(  { if (PL_stack_max -   sp   < (  (n + 1)  )) {
        sp = Perl_stack_grow (sp,  sp  , (int) (  (n + 1)  ));  } } )  ;
   for(i = 0; i <= n; n++)
   {
       (void)(  { Perl_sv_setiv (targ , (IV)(  i  )); (void)(  { (void)(  {
if (((   targ    )->sv_flags  & 0x00004000 ) ) Perl_mg_set ( targ  ); }
)  ; (*++sp = ( targ  )) ; } )  ; } )  ;
   }
# 71 "foo.c"

        PL_stack_sp = sp ;
        return;
    }
}

However, perl -n -e '/\btarg\b/ && print' on the cpp'd file does confirm
that this is the only occurrence of 'targ'.

Does anyone have a known-to-be-working snippet of code that returns a list
from XS? 

The same error occurs on a different machine with  perl v5.6.0 built for
i386-linux, so it's not specific to the version of perl I have.

-- 
Vivek

Reply via email to