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

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

Thread Next
Bram via RT
June 11, 2008 05:35
[perl #51370] length($@)>0 for empty $@ if utf8 is in use
Message ID:
On Mon Mar 03 06:41:54 2008, 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:

- 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).


In the thread (Clearing magic) Nicholas said:
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.

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


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