Herkum has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to learn XS and I am trying to do Example 5 from PerlXSut on a Windows 7 machine using dmake, The example is,

SV * paths INIT: AV * results; I32 numpaths = 0; int i, n; struct statfs buf; if ((!SvROK(paths)) || (SvTYPE(SvRV(paths)) != SVt_PVAV) || ((numpaths = av_len((AV *)SvRV(paths))) < 0)) { XSRETURN_UNDEF; } results = (AV *)sv_2mortal((SV *)newAV()); CODE: for (n = 0; n <= numpaths; n++) { HV * rh; STRLEN l; char * fn = SvPV(*av_fetch((AV *)SvRV(paths), n, 0), l); i = statfs(fn, &buf); if (i != 0) { av_push(results, newSVnv(errno)); continue; } rh = (HV *)sv_2mortal((SV *)newHV()); hv_store(rh, "f_bavail", 8, newSVnv(buf.f_bavail), 0); hv_store(rh, "f_bfree", 7, newSVnv(buf.f_bfree), 0); hv_store(rh, "f_blocks", 8, newSVnv(buf.f_blocks), 0); hv_store(rh, "f_bsize", 7, newSVnv(buf.f_bsize), 0); hv_store(rh, "f_ffree", 7, newSVnv(buf.f_ffree), 0); hv_store(rh, "f_files", 7, newSVnv(buf.f_files), 0); hv_store(rh, "f_type", 6, newSVnv(buf.f_type), 0); av_push(results, newRV((SV *)rh)); } RETVAL = newRV((SV *)results); OUTPUT: RETVAL

The problem is when I run 'dmake' I keep seeing this error, I am unsure what to do, any suggestions?

MyTest.xs:45: error: storage size of 'buf' isn't known

Replies are listed 'Best First'.
Re: Learning XS dmake problem
by almut (Canon) on Sep 25, 2009 at 22:22 UTC

    As noted in perlxstut, this particular example would only work on Unix as is:

    This extension is very Unix-oriented (struct statfs and the statfs +system call). If you are not running on a Unix system, you can substitute for statfs any other f +unction that returns multiple values, you can hard-code values to be returned to the caller (alth +ough this will be a bit harder to test the error case), or you can simply not do this example.

    In other words, the storage size of buf cannot be determined because the struct statfs is not known on Windows (it's defined in sys/vfs.h on Unix).

      Ah, I figured the examples would be general enough to work on most systems without problem.

      I guess part of the problem is I am not very familiar with C and the syntax for XS is specialized as well. So it makes it easy to miss details, especially when I am just trying to make progress on learning something.