It pushes a value on the return stack

Yeaaah ... it pushes a value onto the stack ... but does that mean it returns a value ? (It's also pushing onto the stack something that's already on the stack, isn't it ? .... which doesn't do much to help the intellectually impaired :-) I thought there would have to be an XSRETURN() before anything was returned ... or a RETVAL ....

We see (in INLINE.h):
#define Inline_Stack_Push(x) XPUSHs(x)
Also:
#define Inline_Stack_Return(x) XSRETURN(x)
In Inline::C, we have to Inline_Stack_Return(x) if we wish to return anything from a 'void' function. Since Inline::C and XS are essentially one and the same thing, I expected that we would have to explicitly XSRETURN(x) from an XSub (if we wanted to return anything).

Let's concentrate (for the moment, anyway) on how to rewrite my 'overload_add_eq' in such a way that the refcount increase is not needed. I tried:
void overload_add_eq(SV * obj, SV * addon, SV * third) { dXSARGS; Card* c = (Card *)SvIV(SvRV(obj)); c->value += SvIV(addon); XPUSHs(obj); }
but still got the same failure with the '+=" operator. (Again, when explicitly calling overload_add_eq($obj, $addon, 0); there's no problem.)

Shit!! ... but hang on ... I also tried:
void overload_add_eq(SV * obj, SV * addon, SV * third) { dXSARGS; Card* c = (Card *)SvIV(SvRV(obj)); c->value += SvIV(addon); XPUSHs(obj); XSRETURN(1); }
and that worked fine with the '+=' overloading ... and no increase to the refcount !!! It also worked fine when I explicitly called overload_add_eq($obj, $addon, 0);(This might even constitute "progress".)

So ... I guess one remaining question is "how come I have to call both dXSARGS and XSRETURN (whereas Robert Hyde's GMP code didn't have to do that) ?"

Another question is "Has anything been achieved by rewriting 'overload_add_eq' ?". I guess the answer to that question will be "no" ... the proof will be in the benchmarking.

Thanks for the feedback, Anno. Please don't take my questions/objections/refutations as anything other than the ramblings of one who is both ill-informed and a little dim :-)

Cheers,
Rob

In reply to Re^4: Overload '+=' with XSub by syphilis
in thread Overload '+=' with XSub by syphilis

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.