in reply to XS returning undef?

Instead of
dirinfo = newRV_noinc((SV *)newdirinfo);
try:
sv_setsv(dirinfo, sv_2mortal(newRV_noinc((SV *)newdirinfo)));
BTW, I think you should also change
hv_store(newdirinfo, "Errors", 6, newRV((SV *)errs), 0);
to use newRV_noinc() to keep the refcount of errs correct.

Replies are listed 'Best First'.
Re: Re: XS returning undef?
by meetraz (Hermit) on Mar 09, 2003 at 08:13 UTC
    Perfect! This did the trick, ++jand. I guess I should have thought of using sv_setsv(). Why does that work and not directly assigning the pointer?

    As for the newRV() vs. newRV_noinc(), that's what I get for copying code from perlxstut. I noticed in the very latest docs that it was deprecated, but I must have missed that one. Thanks again.

      You cannot swap the actual SV that the SV* in @_ is pointing to, as that SV itself is owned by the caller. @_ contains just *aliases* to the original parameters. Changing the SV*'s in @_ doesn't do anything to the value of the original parameter; they just go away when your function returns. (And since the stack isn't refcounted, you will leak memory too). You can only change the *value* of the SV that is being passed to you.
      Because SV's are C-structs consisting of 3 elements, first of which is a pointer to another struct ... see perlguts,Perl Guts Illustrated.

      update: what jand said. variables in c are pass by value.


      MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
      I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
      ** The Third rule of perl club is a statement of fact: pod is sexy.