2 # Test for malfunctions of utf8 cache
15 skip_without_dynamic_extension("Devel::Peek");
17 my $pid = open CHILD, '-|';
18 die "kablam: $!\n" unless defined $pid;
20 open STDERR, ">&STDOUT";
21 $a = "hello \x{1234}";
23 bar(substr($a, $_, 1));
27 Devel::Peek::Dump($_[0]);
32 { local $/; $_ = <CHILD> }
34 my $utf8magic = qr{ ^ \s+ MAGIC \s = .* \n
35 \s+ MG_VIRTUAL \s = .* \n
36 \s+ MG_TYPE \s = \s PERL_MAGIC_utf8 .* \n
37 \s+ MG_LEN \s = .* \n }xm;
39 unlike($_, qr{ $utf8magic $utf8magic }x);
43 # With bad caching, this code used to go quadratic and take 10s of minutes.
44 # The 'test' in this case is simply that it doesn't hang.
47 local ${^UTF8CACHE} = 1; # enable cache, disable debugging
48 my $x = "\x{100}" x 1000000;
52 pass("quadratic pos");
55 # Get-magic can reallocate the PV. Check that the cache is reset in
62 is ord substr($1, 1, 1), 0x100, 'get-magic resets utf8cache on match vars';
66 my $l = \substr $x, 0;
67 () = substr $$l, 1, 1;
68 substr $x, 0, 1, = "\x{100}";
69 is ord substr($$l, 1, 1), 0x100, 'get-magic resets utf8cache on LVALUEs';
75 () = ord substr $_[0], 1, 1;
77 is ord substr($_[0], 1, 1), 0x100,
78 'get-magic resets uf8cache on defelems';
82 # Overloading can also reallocate the PV.
85 use overload '""' => 'stringify', fallback => 1;
91 return bless [$value, $state], $class;
96 $self->[1] = ! $self->[1];
98 utf8::downgrade($self->[0]);
100 utf8::upgrade($self->[0]);
105 my $u = UTF8Toggle->new(" \x{c2}7 ");
108 is pos $u, 2, 'pos on overloaded utf8 toggler';
109 () = "$u"; # flip flag
111 is pos $u, 2, 'pos on overloaded utf8 toggler (again)'