develooper Front page | perl.perl5.porters | Postings from August 2012

Re: [perl #114410] Substr giving wrong results on $1 with utf8

Thread Previous | Thread Next
Nicholas Clark
August 31, 2012 02:27
Re: [perl #114410] Substr giving wrong results on $1 with utf8
Message ID:
On Thu, Aug 30, 2012 at 06:20:13PM -0700, Father Chrysostomos via RT wrote:
> I've fixed this in commit 7d1328bb7c by reset utf8 caches in mg_get

This seems like a sensible solution. (I can't spot any flaws in the approach)

Historically, if something breaks because of tie, it usually also breaks
with overloading:

$ cat
#!/perl -w
use strict;

package UTF8Toggle;
use strict;

use overload '""' => 'stringify', fallback => 1;

sub new {
    my $class = shift;
    my $value = shift;
    my $state = shift||0;
    return bless [$value, $state], $class;

sub stringify {
    my $self = shift;
    $self->[1] = ! $self->[1];
    if ($self->[1]) {
    } else {

package main;

my $u = UTF8Toggle->new(" \x{c2}7 ");

printf "%d\n", ord substr $u, 1;
printf "%d\n", ord substr $u, 1;

$ ./perl -Ilib     
panic: sv_pos_u2b_cache cache 5 real 4 for  Â7  at line 32.

I'm not sure what the best fix is here. Given that I'd been wondering if the
fix for #114410 was to outlaw caching of tied values, but simply expiring
the cache on the next read works, is the right fix here to trap all points
that call into overload value returning routines and reset the cache?

Nicholas Clark

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