List Info

Thread: Re: overload "0+" doesn't handle integer results




Re: overload "0+" doesn't handle integer results
user name
2007-10-07 14:59:25
Rafael Garcia-Suarez via RT wrote:
>According to our records, your request regarding 
>  "overload "0+" doesn't handle integer
results" 
>has been resolved. 

I looked up the patch that was posted to perl5-porters, and
it solves
this issue only for int().  There's an equivalent bug still
there for
other operations:

$ perl -lwe '{ package t0; sub mynum 
use overload "0+" => &mynum, fallback
=> 1; } printf "%dn", 0+t0::mynum; printf
"%dn", 0+bless({}, "t0")'

It works OK for plain printf "%d", but not for
addition.  Also doesn't
work for subtraction, negation, multiplication, division,
remainder.
Does work for bit shift and bitwise OR.  Perhaps some code
factoring is
called for.

-zefram

Re: overload "0+" doesn't handle integer results
user name
2007-10-07 21:37:01
On Oct 07 2007, Zefram wrote:
> I looked up the patch that was posted to perl5-porters,
and it solves
> this issue only for int().  There's an equivalent bug
still there for
> other operations:
> 
> $ perl -lwe '{ package t0; sub mynum  use overload "0+" =>
&mynum, fallback => 1; } printf "%dn",
0+t0::mynum; printf "%dn", 0+bless({},
"t0")'

I wish you'd mentioned that before.

> It works OK for plain printf "%d", but not
for addition.  Also doesn't
> work for subtraction, negation, multiplication,
division, remainder.
> Does work for bit shift and bitwise OR.  Perhaps some
code factoring is
> called for.

Undoubtedly.  In the meantime here is another patch to fix a
segfault
introduced by the first.

-- 
Rick Delaney
rickbort.ca

  
overload "0+" doesn't handle integer results
user name
2007-10-08 09:47:57
Zefram wrote:
> It works OK for plain printf "%d", but not
for addition.
> Also doesn't work for subtraction, negation,
> multiplication, division, remainder.  Does work for
bit
> shift and bitwise OR.  Perhaps some code factoring is
> called for.

The attached patch adds tests for these to lib/overload.t.
The tests are skipped if not using 64-bit ints.
The following tests (which fail for me) are set as TODO:
    0+ (addition)
    subtraction
    multiplication
    division
    modulo (%)
    exponentiation (**)
    abs()

  
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )