3 # Check that we don't recompile runtime patterns when the pattern hasn't
6 # Works by checking the debugging output of 'use re debug' and, if
7 # available, -Dr. We use both to check that the different code paths
8 # with Perl_foo() verses the my_foo() under ext/re/ don't cause any
19 @INC = ('../lib','.');
21 skip_all_if_miniperl("no dynamic loading on miniperl, no re");
27 my $results = runperl(
28 switches => [ '-Dr' ],
32 my $has_Dr = $results !~ /Recompile perl with -DDEBUGGING/;
34 my $tmpfile = tempfile();
37 # Check that a pattern triggers a regex compilation exactly N times,
38 # using either -Dr or 'use re debug'
39 # This is partially based on _fresh_perl() in test.pl
42 my ($use_Dr, $n, $prog, $desc) = @_;
43 open my $tf, ">$tmpfile" or die "Cannot open $tmpfile: $!";
47 push @$switches, '-Dr';
50 $prog = qq{use re qw(debug);\n$prog};
54 close $tf or die "Cannot close $tmpfile: $!";
55 my $results = runperl(
56 switches => $switches,
63 my $count = () = $results =~ /Final program:/g;
64 if ($count == $n && !$status) {
69 _diag "# COUNT: $count EXPECTED $n\n";
70 _diag "# STATUS: $status\n";
71 _diag "# SWITCHES: @$switches\n";
72 _diag "# PROG: \n$prog\n";
73 # this is verbose; uncomment for debugging
74 #_diag "# OUTPUT:\n------------------\n $results-------------------\n";
78 # Check that a pattern triggers a regex compilation exactly N times,
81 my ($n, $prog, $desc) = @_;
83 _comp_n(1, $n, $prog, "$desc -Dr");
87 skip("-Dr not compiled in");
93 # Check that a pattern triggers a regex compilation exactly once.
100 comp_1(<<'CODE', 'simple');
101 "a" =~ /$_/ for qw(a a a);
104 comp_1(<<'CODE', 'simple qr');
105 "a" =~ qr/$_/ for qw(a a a);
108 comp_1(<<'CODE', 'literal utf8');
109 "a" =~ /$_/ for "\x{100}", "\x{100}", "\x{100}";
112 comp_1(<<'CODE', 'literal utf8 qr');
113 "a" =~ qr/$_/ for "\x{100}", "\x{100}", "\x{100}";
116 comp_1(<<'CODE', 'longjmp literal utf8');
118 "a" =~ /$x$_/ for "\x{100}", "\x{100}", "\x{100}";
121 comp_1(<<'CODE', 'longjmp literal utf8 qr');
123 "a" =~ qr/$x$_/ for "\x{100}", "\x{100}", "\x{100}";
126 comp_1(<<'CODE', 'utf8');
127 "a" =~ /$_/ for '\x{100}', '\x{100}', '\x{100}';
130 comp_1(<<'CODE', 'utf8 qr');
131 "a" =~ qr/$_/ for '\x{100}', '\x{100}', '\x{100}';
134 comp_1(<<'CODE', 'longjmp utf8');
136 "a" =~ /$x$_/ for '\x{100}', '\x{100}', '\x{100}';
139 comp_1(<<'CODE', 'longjmp utf8');
141 "a" =~ qr/$x$_/ for '\x{100}', '\x{100}', '\x{100}';
144 comp_n(3, <<'CODE', 'mixed utf8');
145 "a" =~ /$_/ for "\x{c4}\x{80}", "\x{100}", "\x{c4}\x{80}";
148 comp_n(3, <<'CODE', 'mixed utf8 qr');
149 "a" =~ qr/$_/ for "\x{c4}\x{80}", "\x{100}", "\x{c4}\x{80}";
152 # note that that for runtime code, each pattern is compiled twice; the
153 # second time to allow the parser to see the code.
155 comp_n(6, <<'CODE', 'runtime code');
157 BEGIN { $^H |= 0x00200000 } # lightweight "use re 'eval'"
158 "a" =~ /a$_/ for $x, $x, $x;
161 comp_n(6, <<'CODE', 'runtime code qr');
163 BEGIN { $^H |= 0x00200000 } # lightweight "use re 'eval'"
164 "a" =~ qr/a$_/ for $x, $x, $x;
167 comp_n(4, <<'CODE', 'embedded code');
169 "a" =~ /a$_/ for $x, $x, $x;
172 comp_n(4, <<'CODE', 'embedded code qr');
174 "a" =~ qr/a$_/ for $x, $x, $x;
177 comp_n(7, <<'CODE', 'mixed code');
180 BEGIN { $^H |= 0x00200000 } # lightweight "use re 'eval'"
181 "a" =~ /a$x$_/ for $y, $y, $y;
184 comp_n(7, <<'CODE', 'mixed code qr');
187 BEGIN { $^H |= 0x00200000 } # lightweight "use re 'eval'"
188 "a" =~ qr/a$x$_/ for $y, $y, $y;