in reply to Help needed for XS on Perl v5.8.3

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."

Replies are listed 'Best First'.
Re^2: Help needed for XS on Perl v5.8.3
by pijush (Scribe) on Oct 05, 2004 at 09:47 UTC
    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