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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||