withSV * overload_add_eq (a, b, third) SV * a SV * b SV * third CODE: RETVAL = overload_add_eq (aTHX_ a, b, third); OUTPUT: RETVAL
And in the top section of the file I have replaced:void overload_add_eq (a, b, third) SV * a SV * b SV * third CODE: overload_add_eq (aTHX_ a, b, third); XSRETURN_EMPTY; /* return empty stack */
withSV * overload_add_eq(pTHX_ SV * a, SV * b, SV * third) { /* lengthy code snipped */ }
This means that we're always adding SvUV(b) to a, irrrespective of what b actually is.void overload_add_eq(pTHX_ SV * a, SV * b, SV * third) { PERL_UNUSED_ARG(third); /* UPDATE: This line can be removed as ir +relevant */ mpz_add_ui(*(INT2PTR(mpz_t *, SvIVX(SvRV(a)))), *(INT2PTR(mpz_t * +, SvIVX(SvRV(a)))), SvUV(b)); }
As you can see from that, the Math::GMPz object ($x) has been well and truly clobbered by the '+=' overloading.> perl -Mblib -MMath::GMPz -MDevel::Peek -wle "$x = Math::GMPz->new(12 +34); $x++;print $x; $x += 15; print $x; Dump($x);" 1235 Use of uninitialized value $x in print at -e line 1. SV = PVIV(0x1abd93865e0) at 0x1abdad3ae48 REFCNT = 1 FLAGS = () IV = 1837594613288 PV = 0
UPDATE 3: Also, if I remove the '+=' overloading (by commenting out the appropriate line in GMPz.pm), then the '+=' overloading (which then uses the '+' overloading) works fine:> perl -Mblib -MMath::GMPz -MDevel::Peek -wle "$x = Math::GMPz->new(12 +34); $x++; print $x; Math::GMPz::overload_add_eq($x, 15, 0); print $x +;" 1235 1250
Cheers,> perl -Mblib -MMath::GMPz -MDevel::Peek -wle "$x = Math::GMPz->new(12 +34); $x++;print $x; $x += 15; print $x; Dump($x);" 1235 1250 SV = IV(0x2bfffa61b78) at 0x2bfffa61b88 REFCNT = 1 FLAGS = (ROK) RV = 0x2bfff38aac8 SV = PVMG(0x2bfffa24a58) at 0x2bfff38aac8 REFCNT = 1 FLAGS = (OBJECT,IOK,READONLY,pIOK) IV = 3023652457216 NV = 0 PV = 0 STASH = 0x2bfffa5e5e8 "Math::GMPz"
In reply to Re^5: Puzzled by value of $overload::ops{binary}
by syphilis
in thread Puzzled by value of $overload::ops{binary}
by syphilis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |