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() versus the my_foo() under ext/re/ don't cause any
16 set_up_inc( '../lib', '.' );
17 skip_all_if_miniperl("no dynamic loading on miniperl, no re");
25 my $results = runperl(
26 switches => [ '-Dr' ],
30 my $has_Dr = $results !~ /Recompile perl with -DDEBUGGING/;
32 my $tmpfile = tempfile();
35 # Check that a pattern triggers a regex compilation exactly N times,
36 # using either -Dr or 'use re debug'
37 # This is partially based on _fresh_perl() in test.pl
40 my ($use_Dr, $n, $prog, $desc) = @_;
41 open my $tf, ">$tmpfile" or die "Cannot open $tmpfile: $!";
45 push @$switches, '-Dr';
48 $prog = qq{use re qw(debug);\n$prog};
52 close $tf or die "Cannot close $tmpfile: $!";
53 my $results = runperl(
54 switches => $switches,
61 my $count = () = $results =~ /Final program:/g;
62 if ($count == $n && !$status) {
67 _diag "# COUNT: $count EXPECTED $n\n";
68 _diag "# STATUS: $status\n";
69 _diag "# SWITCHES: @$switches\n";
70 _diag "# PROG: \n$prog\n";
71 # this is verbose; uncomment for debugging
72 #_diag "# OUTPUT:\n------------------\n $results-------------------\n";
76 # Check that a pattern triggers a regex compilation exactly N times,
79 my ($n, $prog, $desc) = @_;
81 _comp_n(1, $n, $prog, "$desc -Dr");
85 skip("-Dr not compiled in");
91 # Check that a pattern triggers a regex compilation exactly once.
98 comp_1(<<'CODE', 'simple');
99 "a" =~ /$_/ for qw(a a a);
102 comp_1(<<'CODE', 'simple qr');
103 "a" =~ qr/$_/ for qw(a a a);
106 comp_1(<<'CODE', 'literal utf8');
107 "a" =~ /$_/ for "\x{100}", "\x{100}", "\x{100}";
110 comp_1(<<'CODE', 'literal utf8 qr');
111 "a" =~ qr/$_/ for "\x{100}", "\x{100}", "\x{100}";
114 comp_1(<<'CODE', 'longjmp literal utf8');
116 "a" =~ /$x$_/ for "\x{100}", "\x{100}", "\x{100}";
119 comp_1(<<'CODE', 'longjmp literal utf8 qr');
121 "a" =~ qr/$x$_/ for "\x{100}", "\x{100}", "\x{100}";
124 comp_1(<<'CODE', 'utf8');
125 "a" =~ /$_/ for '\x{100}', '\x{100}', '\x{100}';
128 comp_1(<<'CODE', 'utf8 qr');
129 "a" =~ qr/$_/ for '\x{100}', '\x{100}', '\x{100}';
132 comp_1(<<'CODE', 'longjmp utf8');
134 "a" =~ /$x$_/ for '\x{100}', '\x{100}', '\x{100}';
137 comp_1(<<'CODE', 'longjmp utf8');
139 "a" =~ qr/$x$_/ for '\x{100}', '\x{100}', '\x{100}';
142 comp_n(3, <<'CODE', 'mixed utf8');
143 "a" =~ /$_/ for "\x{c4}\x{80}", "\x{100}", "\x{c4}\x{80}";
146 comp_n(3, <<'CODE', 'mixed utf8 qr');
147 "a" =~ qr/$_/ for "\x{c4}\x{80}", "\x{100}", "\x{c4}\x{80}";
150 # note that for runtime code, each pattern is compiled twice; the
151 # second time to allow the parser to see the code.
153 comp_n(6, <<'CODE', 'runtime code');
155 BEGIN { $^H |= 0x00200000 } # lightweight "use re 'eval'"
156 "a" =~ /a$_/ for $x, $x, $x;
159 comp_n(6, <<'CODE', 'runtime code qr');
161 BEGIN { $^H |= 0x00200000 } # lightweight "use re 'eval'"
162 "a" =~ qr/a$_/ for $x, $x, $x;
165 comp_n(4, <<'CODE', 'embedded code');
167 "a" =~ /a$_/ for $x, $x, $x;
170 comp_n(4, <<'CODE', 'embedded code qr');
172 "a" =~ qr/a$_/ for $x, $x, $x;
175 comp_n(7, <<'CODE', 'mixed code');
178 BEGIN { $^H |= 0x00200000 } # lightweight "use re 'eval'"
179 "a" =~ /a$x$_/ for $y, $y, $y;
182 comp_n(7, <<'CODE', 'mixed code qr');
185 BEGIN { $^H |= 0x00200000 } # lightweight "use re 'eval'"
186 "a" =~ qr/a$x$_/ for $y, $y, $y;
189 comp_n(6, <<'CODE', 'embedded code qr');
192 "a" =~ qr/a$_/ for $x, $y, $x, $y;
195 comp_n(2, <<'CODE', '(??{"constant"})');
196 "bb" =~ /(??{"abc"})/;
199 comp_n(2, <<'CODE', '(??{"folded"."constant"})');
200 "bb" =~ /(??{"ab"."c"})/;
203 comp_n(2, <<'CODE', '(??{$preused_scalar})');
208 comp_n(2, <<'CODE', '(??{number})');
212 comp_n(2, <<'CODE', '(??{$pvlv_regexp})');
215 "bb" =~ /(??{$_[0]})/;