develooper Front page | perl.perl5.porters | Postings from June 2008

[perl #51370] length($@)>0 for empty $@ if utf8 is in use

Thread Next
From:
Bram via RT
Date:
June 11, 2008 05:35
Subject:
[perl #51370] length($@)>0 for empty $@ if utf8 is in use
Message ID:
rt-3.6.HEAD-18229-1213179984-1708.51370-15-0@perl.org
On Mon Mar 03 06:41:54 2008, pajas@ufal.mff.cuni.cz wrote:
> 
> Perl seems to cache character length of scalars, but in case of $@
> it does not reset it after a successfull eval. Here is an example.
> 
> The following is reproducible with 5.10.0 and also on 5.8.8 (didn't
> try other releases):
> 
> perl -MCarp -e 'use utf8;  eval { die "\x{10d}"}; length($@); print
> $@; eval { 1 }; print "\$@ is q($@), length(\$@)
> is ".length($@)."\n" '
> 
> The first eval dies and spits a non-ascii character. Then the
> character length of $@ is asked (we are in the scope of the utf8
> pragma).  The returned value (16 in this case) seems to be
> remembered,
> since after a subsequent eval{1} which resets $@ to q(), the
> function
> length($@) still returns 16 (but 0 if asked in the scope of 'use
> byte').
> 
> -----------------------------------------------------------------

Attached are two patches:

errsv_1.txt:
- this patch clears all the magic associated with $@,
- has the test of the bug report
- scrapes the output of Devel::Peek::Dump at the start and compares it 
again after two evals (one that fails and one that succeeds).


errsv_2.txt:

In the thread (Clearing magic) Nicholas said:
<quote>
To my mind, making them all *_mg seems right, as it would trigger any 
set magic on ERRSV.

Although (I think) that this would allow rather sick things like tie $@ 
to work.
</quote>

- this patch changes most of them (not sure if I got them all) into _mg
- has the test of the bug report
- does a tie on $@ and checks if STORE gets called. 


Only one of the two patches has to be applied...


Kind regards,

Bram

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