Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
cpan/Win32API-File/buffers.h#l244 in perl.git

I'm talking about the above. Original author even says its intended to be a replacement for alloca. Also, someone correct me if I'm wrong, but I've read rumors in Perl's source that SVs can "steal" the strings/PVs of other SVs leaving the source SV undefined. I've seen it on defelem 'y' magic SVs that come in on the Perl Stack. The mess in sv_setsv sv.c#l4227 in perl.git does, sometimes, maybe, steal the PV from source to destination SV. I guess some programmers might be intentionally taking advantage of the fact that mortalized SVs can give up their PVs to a destination SV. For example, in an XSUB with C style data return in parameter scalars, if the C func fails, dont touch the value of the parameter Perl Stack SV, let the mortal SV disappear in the return, or in the croak. The author of Win32API::File obviously isn't doing that since the SV * is tossed leaving only the char */PV around. Remember (not to you BrowserUk), croaks in XS and dies in Perl are implemented using a Perl Stack unwinder (will call DESTROY if objs), and a C Stack unwinder (setjmp/longjmp). If you malloc a block (or new anything in C++), callback into Perl without eval protection and the CV dies, you just leaked memory. Using the sv_grow/mortal macro above would give you a croak safe C++ smart pointer in XS, using alloca would too. The magic system can also cause you to run Perl unintentionally in XS. Not sure if the magic system sets up an eval catch or not if the C func or Perl sub croaks/dies in the magic setter/getter. Not sure what else in the XS/C perl api can croak other than magic SVs and callbacks into Perl. The definition of mortal should be "the caller shall delete the SV if the caller shall not need it when the callee returns to the caller". The warnings about needing to return to Perl or ENTER/LEAVE blocks in perlguts or whereever it is still stands, AKA, never make mortal SVs in a non hard coded iteration loop (while(i<10) is good, while(i<runtimes), while(!exit), while(job = oldjob->Next) is very bad). You'll run out of memory/ "C stack overflow" (but its not a C stack overflow, its heap memory you ran out of). Can you think of any other uses of mortal system? :-)

In reply to Re^4: When to (and not to) use sv_2mortal() by patcat88
in thread When to (and not to) use sv_2mortal() by davido

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, 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
  • 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.
  • Log In?

    What's my password?
    Create A New User
    [LanX]: it was just after Trump-ageddon and the Americans thought I'm ridiculing them ;)
    Discipulus was not the title a bit provoking? ;=)
    [LanX]: I have a degree in cynism. ..
    LanX is the PROVO-KING
    [holli]: what's that smell?
    [LanX]: good evening! :)

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (6)
    As of 2017-11-20 19:50 GMT
    Find Nodes?
      Voting Booth?
      In order to be able to say "I know Perl", you must have:

      Results (292 votes). Check out past polls.