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

Hi Monks,

I am facing a problem to execute code on Windows 2000 using ActiveState Perl v5.8.3 (build 809). Here is my scenario. I have a sample programme written in .xs file say a.xs and I am testing few functions from another .pl file say b.pl. To generate dll file I have a Makefile.PL. This Makefile.PL is running fine on Perl v5.6.1 and build the dll file but when I tried to build on Perl v5.8.3 using this Makefile.PL, I received error. Then I removed objXSUB.h header file from Makefile.PL and then the code compiled successfully and generated the dll file. But this dll file is not giving expected behaviour. e.g. I have following checking in a.xs file to check the validity of input parameters

if( !SvROK(ST(1)) ) { printf("\nDEBUG: second parameter not found.\n"); XSRETURN_IV(1); } printf("\nDEBUG: second parameter found.\n");
I am always getting the output as DEBUG: second parameter found.. Can anyone please tell me what I am doing wrong?
Thanks in advance.
Regards
-Pijush

Replies are listed 'Best First'.
Re: Help needed for XS on Perl v5.8.3
by Velaki (Chaplain) on Oct 04, 2004 at 13:33 UTC

    SvROK (scalar value reference OK/true) will tell you if your SV is a reference; not whether is simply exists - in this case, the value returned by ST(1), which should be the second value off the stack.

    You might want to look at the actually type of reference SvROK thinks is coming back from the ST(1) call.

    That can be done with:

    /* if SvROK(ST(1) is true, i.e. it's a reference */ printf("\nDEBUG: Type is %d\n",SvTYPE(SvRV(ST(1)));
    Take a look in sv.h for specifics on the meaning of the individual return value.

    See also: perlguts, perlxs, perlxstut

    Hope that helped,
    -v
    "Perl. There is no substitute."
      Thanks for reply.
      But this approach does not solve my problem. On further investigation I have found out a clue that why this is behaving like this with Perl v5.8.3, but can not find the solution.
      I have already metioned I have xs file, a.xs where the xs code is present. I have also a .map file say c.map file in c.map file I have written following code (the code has been taken from Advanced Perl Programming book)
      TYPEMAP const char * T_PV test_class * ANY OBJECT OUTPUT ANY OBJECT sv_setref_pv($arg, CLASS, (void *) $var); INPUT ANY OBJECT $var = ($type) SvIV((SV*)SvRV($arg));
      Now when Perl v5.6.1 generates .c file from .xs file following code was generated
      XS(XS_Test_TestMethod) { dXSARGS; if (items != 2) Perl_croak(aTHX_ "Usage: Test::TestMethod(CLASS, param1)"); { char* CLASS = (char *)SvPV(ST(0),PL_na); pstruct * param1;
      On the other hand Perl v5.8.3 generated following code
      XS(XS_Test_TestMethod) { dXSARGS; if (items != 2) Perl_croak(aTHX_ "Usage: Test::TestMethod(CLASS, param1)"); { char* CLASS = (char *)SvPV_nolen(ST(0)); pstruct * param1 = (pstruct *) SvIV((SV*)SvRV(ST(1)));
      Can anybody please tell me why code generation is different for Perl v5.6.1 and Perl v5.8.3? I also doubt that code generated by Perl v5.8.3 may cause problem in my script when no valid reference address passed to the TestMethod. Can anybody kindly give me any pointers to overcome this problem?
      Thanks in advance.
      Regards
      -Pijush