develooper Front page | perl.perl5.porters | Postings from September 2001 hits wall since Perl 5.7.1

Thread Next
Steffen Beyer
September 30, 2001 09:25
Subject: hits wall since Perl 5.7.1
Message ID:

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,
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, 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

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
"" and "") 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 which remedies the
problem, but this might not be more than a workaround for the
much more fundamental question, why is 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 <> (Who am I) (Fotos Brasil, USA, ...) (Free Perl and C Software)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About