Following the perlxstut, in example 5 I get the following error:

Mytest.c:251:2: error: too few arguments to function 'statfs'

The example creates a module function statfs that is tested like this in t/Mytest.t:

my @a; @a = &Mytest::my_statfs("/blech"); # Test non-existent file/directory ok( scalar(@a) == 1 && $a[0] == 2 ); @a = &Mytest::my_statfs("/"); # Test existing file/directory is ( scalar(@a), 7 );

In other words, the function returns a list.

In Mytest.xs:

#include <sys/vfs.h> ... void statfs(path) char * path INIT: int i; struct statfs buf; PCODE: i = statfs(path, &buf); if (i == 0) { XPUSHs(sv_2mortal(newSVnv(buf.f_bavail))); XPUSHs(sv_2mortal(newSVnv(buf.f_bfree))); XPUSHs(sv_2mortal(newSVnv(buf.f_blocks))); XPUSHs(sv_2mortal(newSVnv(buf.f_bsize))); XPUSHs(sv_2mortal(newSVnv(buf.f_ffree))); XPUSHs(sv_2mortal(newSVnv(buf.f_files))); XPUSHs(sv_2mortal(newSVnv(buf.f_type))); } else { XPUSHs(sv_2mortal(newSVnv(errno))); }

The Makefile.PL generates the following C code:

XS_EUPXS(XS_Mytest_statfs) { dVAR; dXSARGS; if (items != 1) croak_xs_usage(cv, "path"); { char * path = (char *)SvPV_nolen(ST(0)) ; #line 43 "Mytest.xs" int i; struct statfs buf; PCODE: i = statfs(path, &buf); if (i == 0) { XPUSHs(sv_2mortal(newSVnv(buf.f_bavail))); XPUSHs(sv_2mortal(newSVnv(buf.f_bfree))); XPUSHs(sv_2mortal(newSVnv(buf.f_blocks))); XPUSHs(sv_2mortal(newSVnv(buf.f_bsize))); XPUSHs(sv_2mortal(newSVnv(buf.f_ffree))); XPUSHs(sv_2mortal(newSVnv(buf.f_files))); XPUSHs(sv_2mortal(newSVnv(buf.f_type))); } else { XPUSHs(sv_2mortal(newSVnv(errno))); } #line 250 "Mytest.c" statfs(path); } XSRETURN_EMPTY; }

Look near the end of this function. Why is this call to statfs being generated? I have tried to call the module function "my_statfs" instead of "statfs", Then the call near the end of the function becomes my_statfs(buf), while the call to the actual library function statfs remains statfs(path, buf), and the compiler message becomes "undefined reference to `my_statfs'".

Why is this call being generated? What am I doing wrong?

And, is XSRETURN_EMPTY the appropriate macro for a function that returns a non-empty list?


In reply to XS generation error, function returning list by Cacadril

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.