Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: xs modifying passed value

by Festus Hagen (Novice)
on Nov 17, 2012 at 22:22 UTC ( #1004355=note: print w/ replies, xml ) Need Help??


in reply to Re: xs modifying passed value
in thread xs modifying passed value

I originally had it as "$passfail" (and just tried again), then reading up led me to passing by reference and led to that.
I've been hacking/reading on this for a few hours now ... So I've tried a few different angles, Apparently all wrong!

I'm swimming in all this Sv SV PV Pv Rv RV blah blah ... :(

Simple is my pleasure, I'll complicate it as my mind expands, hopefully before it explodes!

Just noticed I forgot the proto for mylib strToInt in my OP, Here it is:
int strToInt(bool *ok) const;

I do have stepping capabilities on each side of the fence, Perl and C, Just not across.
Qt Creator w/dbg on the C/C++ side and of course Perldbg on the Perl side.
I have many times ran them together to see both sides of the fence, nothing jumps out at me other then the passed value between Perl and XS doesn't get modified, Between XS and my Lib does as shown by the printf(...)'s in the XS.

I do have many other functions that work fine, though none of them require a passed argument modification and were for the most part simple. (looking back :))

Shoot, I figured out without asking for help how to do the new() that has variable arguments as well as several different argument types and got it all to work, so far perf!, but this stupid modified passed argument has me stumped. Arrrrgggg!

Thanks

-Enjoy
fh : )_~


Comment on Re^2: xs modifying passed value
Download Code
Re^3: xs modifying passed value
by bulk88 (Priest) on Nov 17, 2012 at 22:55 UTC
    I don't really know C++, that is C++ code. Can you post the function from the .c file that xsubpp generates from your XS syntax func?

    I suggest you use Devel::Peek's Dump function. You can also call it from XS/C as dump.c#l2139 in perl.git as "void sv_dump(SV *sv)" It will need a SV *, I think that ST(1) is the passfail param as a SV *, since ST(0) will be your THIS pointer in a SV * I think from Script land. Using sv_dump with your code unmodified is impossible as written since the setting of SV * that matches passfail is after your CODE: section (again look at the .c file produced), so you would need to
    int MyLib::strToInt(passfailSV) SV* passfailSV PREINIT: bool passfail; CODE: foo(&passfail); SvSetMagicSV(passfailSV, passfail ? &PL_sv_yes : &PL_sv_no); OUTPUT: RETVAL
    I think there is a bug in the typemap,
    T_BOOL $arg = boolSV($var);
    That is from the default typemap. But look at boolSV.
    /* =for apidoc Am|SV *|boolSV|bool b Returns a true SV if C<b> is a true value, or a false SV if C<b> is 0. See also C<PL_sv_yes> and C<PL_sv_no>. =cut */ #define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
    We assigned a SV * to a SV *, but if this is a in parameter and not an out parameter, you can't just change the SV * to another SV *, you have to change the SV * you got from the caller (return/result's of XSUBs are *usually* brand new SV *s you created and mortalized, then boolSV would work, it won't work to change the inside value of an existing scalar). BTW, you never need to mortal in SV *s you get through the param list (AKA ST(123456) macros), your caller owns the param list SV *s. Also never mortal &PL_sv_yes, &PL_sv_no, &PL_sv_undef, they are process globals/statics.

    I probably should go file a bug report with ExtUtils::ParseXS but I dont have the time.

    update: bug filed
      Well blow my doors off ...

      Bulk88 snaps thy fingers and poof it works!

      Thank you!

      following your lead (pretty near exact cut and paste), Impressive!.

      int MyLib::strToInt(passfailSV) SV* passfailSV PREINIT: bool passfail; CODE: RETVAL = THIS->strToInt(&passfail); SvSetMagicSV(passfailSV, passfail ? &PL_sv_yes : &PL_sv_no); OUTPUT: RETVAL

      I have been so over thinking this ...

      Much Thanks

      -Enjoy
      fh : )_~

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004355]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2014-07-26 20:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (179 votes), past polls