in reply to XS-ive Mortality. (or when to use sv_2mortal())

From the perlguts manpage:

       There are some convenience functions available that 
       can help with the destruction of xVs.  These
       functions introduce the concept of "mortality".  An
       xV that is mortal has had its reference count marked
       to be decremented, but not actually decremented,
       until "a short time later".  Generally the term
       "short time later" means a single Perl statement,
       such as a call to an XSUB function.  The actual
       determinant for when mortal xVs have their reference
       count decremented depends on two macros, SAVETMPS and
       FREETMPS.  See perlcall and perlxs for more details
       on these macros.

       "Mortalization" then is at its simplest a deferred
       "SvREFCNT_dec".  However, if you mortalize a variable
       twice, the reference count will later be decremented
       twice.

       "Mortal" SVs are mainly used for SVs that are placed
       on perl's stack.  For example an SV which is created
       just to pass a number to a called sub is made mortal
       to have it cleaned up automatically when it's popped
       off the stack. Similarly, results returned by XSUBs
       (which are pushed on the stack) are often made
       mortal.

Flo

  • Comment on Re: XS-ive Mortality. (or when to use sv_2mortal())

Replies are listed 'Best First'.
Re^2: XS-ive Mortality. (or when to use sv_2mortal())
by BrowserUk (Patriarch) on Mar 13, 2006 at 20:50 UTC

    Yeah. Saw that, but it doesn't help much. The vagueness of

    Similarly, results returned by XSUBs (which are pushed on the stack) are often made mortal.

    leaves me wondering if I should mortalise every SV I return from XS code? What about from Inline C code? How about the RV that you bless and set into the object that you return a reference to when using Inline C OO? Or the reference itself?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.