Here's how the SVs are created: (slimmed down version)

SV * newSVObj(void *object, char * classname) { SV * result; if (!object) return newSVsv(&PL_sv_undef); HV * h = newHV(); hv_store(h, "ETK", 3, newSViv((long)object), 0); result = newRV((SV*)h); sv_bless(result, gv_stashpv(classname, FALSE)); SvREFCNT_dec(h); return result; }

As you can see, the SV is a hashref storing only a pointer to the original object, and through the class I keep track of the type of the object, so the typemap calls functions like:

SV * newSVEtkButtonPtr(Etk_Button *o) { return newSVObj(o, "Etk::Button"); }

And when these SVs are passed around as data, the get wrapped into a new SV that is made mortal, for example, the code passing data to the callback function: (cbd being a certain struct that hold relevant information to the callback)

PUSHMARK(SP) ; XPUSHs(sv_2mortal(newSVsv(cbd->perl_object))); // self XPUSHs(sv_2mortal(newSVsv(cbd->perl_data))); // data PUTBACK ; call_sv(cbd->perl_callback, G_DISCARD);
--
Leviathan.

In reply to Re^2: Scope, Reference Counting, Mortality... a question about Object Caching by Leviathan
in thread Scope, Reference Counting, Mortality... a question about Object Caching by Leviathan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.