Mailing List Archive

Bug in Double-Typed SV's
After a week of debugging I could trace a bug, that eventually
corrupts the memory, down to double typed SV's. I tried to use an
SV as a blessed reference and as an integer value, using the
following code:

rv=sv_2mortal(newSViv((IV)obj));
SvRV(rv)=hv;
SvROK_on(rv);
sv_bless(rv,stash);
(void)SvIOK_on(rv);

To make debugging almost impossible, hv in the above example is a
reference to a hash tied to another blessed sv (using magic). I also
used OVERLOAD on the resulting object (rv in the above code). For a
while everything worked just fine, but with growing testcode I run
into serious problems with corrupted memory. Debugging was a
nightmare, since with every change in code the problem would appear
at another place or not at all. Removing the double typing finally
seems to have taken care of the problem (fingers crossed).

I am sorry that I can not give a more detailed description (eg where
the problem exactly is), but most of the perl code is still beyond
me...

But maybe somebody has an idea as to where the problem might be.

Gerd Knops
Re: Bug in Double-Typed SV's [ In reply to ]
Gerd Knops writes:
>
> After a week of debugging I could trace a bug, that eventually
> corrupts the memory, down to double typed SV's. I tried to use an
> SV as a blessed reference and as an integer value, using the
> following code:
>
> rv=sv_2mortal(newSViv((IV)obj));
> SvRV(rv)=hv;
> SvROK_on(rv);
> sv_bless(rv,stash);
> (void)SvIOK_on(rv);
>

I had the same idea to speed up Overloaded integers, but the
difference was that I look through perl code first. Currently you
cannot have something that is ROK and IOK simultaneously. The only
good combinations are POK and [NI]OK.

I agree that it would be nice to have this possibility, though the
point is somewhat moot: obviously you cannot have ROK and POK
simultaneously.

Ilya