develooper Front page | perl.perl5.porters | Postings from September 2001

overload.pm hits wall since Perl 5.7.1

Thread Next
From:
Steffen Beyer
Date:
September 30, 2001 09:25
Subject:
overload.pm hits wall since Perl 5.7.1
Message ID:
20010930182301.A26307@engelschall.com
Hi,

since Perl 5.7.1 I have been experiencing failing tests in the test
suite of my module Bit::Vector(::Overload, to be precise) version 6.0
(probably also affects previous versions of my module).

(I reproduced the problem with Perl 5.7.1 and Perl 5.7.2)

This weekend I finally got around to investigate the problem:

Result is, whenever I throw an exception in my module inside the
handler (i.e., method) of an overloaded operator, overload.pm
tries to stringify the object in question, although this is
(at least in my eyes and AFAIK) completely unnecessary, because
my routine already provides the complete error message.

In order to do so, overload.pm re-blesses the object temporarily
into an empty class (overload::Fake).

This is where it hits the wall and fails with "Modification of a
read-only value attempted", because Bit::Vector objects are
write-protected.

This is a necessary measure of precaution, because Bit::Vector
objects are foreign objects, and not Perl data structures.

Therefore Bit::Vector objects are just a blessed scalar containing
a number (actually the pointer returned by malloc) as far as Perl
is concerned.

Because changing this number would be extremely dangerous, I
write-protect the blessed scalar.

(BTW, Data::Dumper (and therefore, the Perl debugger) core dumps
when it hits such a blessed write-protected scalar - maybe some-
thing could be done about that, too? See below for how, maybe!)

I stripped down the problem into a small script (see attachments
"testcase1.pl" and "testcase2.pl") which reproduces the error.

In order to run this script, you will need to install the attached
little module, Internals-1.1.tar.gz - actually just a wrapper around
the XS macros SvREADONLY_on and SvREADONLY_off.

I also enclose a small patch for overload.pm which remedies the
problem, but this might not be more than a workaround for the
much more fundamental question, why is overload.pm all of a sudden
stringifying the object in order to throw an exception??????

This patch needs the same module Internals-1.1.tar.gz to be installed
in order to work.

The patch simply write-enables the object (if it is write-protected)
before blessing it, and write-protects it again (if it was so
before) after the re-blessing into its own class.

Maybe one could do the same thing in Data::Dumper?

I'd be glad to hear your opinions and suggestions!

Best regards,
-- 
    Steffen Beyer <sb@engelschall.com>
    http://www.engelschall.com/u/sb/whoami/ (Who am I)
    http://www.engelschall.com/u/sb/gallery/ (Fotos Brasil, USA, ...)
    http://www.engelschall.com/u/sb/download/ (Free Perl and C Software)

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About