Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: SV creation inside XS

by patcat88 (Deacon)
on Nov 07, 2011 at 01:45 UTC ( #936380=note: print w/ replies, xml ) Need Help??


in reply to SV creation inside XS

HV* hv = newHV(); RETVAL = newSVrv((SV*)hv, NULL);
As said before, newSVrv is wrong. Make sure you use newRV_noinc since newHV has a ref count of 1 already. If you bring HV to 2 and return the RV to Perl land, the HV is now memory leaked because when the RV is garbage collected, the HV will stay forever. HV and AVs must be returned in RVs to Perl land. If you try to return a HV or AV without it being in an RV, you will get the "bizarre copy" die the next time a perl op sees it. Remember, RETVALed or OUTPUTed SV* get mortalized behind the scenes (look at your .c file), so they should be left by you with refcount 1, and NOT mortalized. As I recall, perl gets very noisy (can't remember if it is a warning or fatal) if your double mortaled SV * or derivative appears. perl will try to delete the SV twice. perl will catch the double mortaled SV because perl will be freeing something already freed and returned by perl to the SV arena/free SV struct cache. Freed SVs have special patterns in them, like refcount in the 2 billions.


Comment on Re: SV creation inside XS
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (14)
As of 2014-08-21 14:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (136 votes), past polls