It's a bit hard to read your code as presented. Please use <code>...</code> around your code to make it render as a code block.

I'm not sure that your code is actually sound, as you seem to have objects stored in the result array, but then copy pointers to Perl space (via sv_setpv) and also call delete [] on them, if I understand the C++ code correctly. But that leaves the memory in a very bad state, because delete [] will also have called the destructor on the object referenced by result[i], and you still have a pointer to that memory location stored in ST(argvi+i). This will result in memory corruption and many things can happen there.

{ int i = 0; while (result[i]) { if(i+1>items){ EXTEND(sp,1); } ST(argvi+i) = sv_newmortal(); sv_setpv((SV *)ST(argvi+i),result[i]); # Abort is happening +this point delete [] result[i]; i++; } argvi+=i; delete [] result; }

My suggestion would be to remove all calls to delete until you get things working and then add the delete [] result; back, maybe. But even then you need to make sure that the contents of result themselves are not removed, because they are now referenced from Perl space.


In reply to Re: sv_setpv aborts when the SV (perl output array)have more than 127 size by Corion
in thread sv_setpv aborts when the SV (perl output array)have more than 127 size by Thiyagu

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.