This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
is_utf8_char_slow(): Make constistent, correct docs.
[perl5.git] / ext / Devel-Peek / t / Peek.t
CommitLineData
99331854 1#!./perl -T
9ec58fb7
JH
2
3BEGIN {
9ec58fb7 4 require Config; import Config;
e7ecf62c 5 if ($Config{'extensions'} !~ /\bDevel\/Peek\b/) {
9ec58fb7
JH
6 print "1..0 # Skip: Devel::Peek was not built\n";
7 exit 0;
8 }
9}
10
06a5cade 11use Test::More;
e7ecf62c 12
9248c45a
JH
13use Devel::Peek;
14
9248c45a 15our $DEBUG = 0;
277ddfaf 16open(SAVERR, ">&STDERR") or die "Can't dup STDERR: $!";
9248c45a 17
bfe27a58
NC
18# If I reference any lexicals in this, I get the entire outer subroutine (or
19# MAIN) dumped too, which isn't really what I want, as it's a lot of faff to
20# maintain that.
21format PIE =
22Pie @<<<<<
23$::type
24Good @>>>>>
25$::mmmm
26.
27
bad4ae38
FC
28use constant thr => $Config{useithreads};
29
9248c45a 30sub do_test {
000fd473
NC
31 my $todo = $_[3];
32 my $repeat_todo = $_[4];
33 my $pattern = $_[2];
277ddfaf
GS
34 if (open(OUT,">peek$$")) {
35 open(STDERR, ">&OUT") or die "Can't dup OUT: $!";
9248c45a 36 Dump($_[1]);
e9569a7a
GG
37 print STDERR "*****\n";
38 Dump($_[1]); # second dump to compare with the first to make sure nothing changed.
277ddfaf
GS
39 open(STDERR, ">&SAVERR") or die "Can't restore STDERR: $!";
40 close(OUT);
9248c45a
JH
41 if (open(IN, "peek$$")) {
42 local $/;
43 $pattern =~ s/\$ADDR/0x[[:xdigit:]]+/g;
8aacddc1 44 $pattern =~ s/\$FLOAT/(?:\\d*\\.\\d+(?:e[-+]\\d+)?|\\d+)/g;
fd0854ff 45 # handle DEBUG_LEAKING_SCALARS prefix
d94a5950 46 $pattern =~ s/^(\s*)(SV =.* at )/(?:$1ALLOCATED at .*?\n)?$1$2/mg;
bf53b3a5 47
000fd473
NC
48 # Need some clear generic mechanism to eliminate (or add) lines
49 # of dump output dependant on perl version. The (previous) use of
50 # things like $IVNV gave the illusion that the string passed in was
51 # a regexp into which variables were interpolated, but this wasn't
52 # actually true as those 'variables' actually also ate the
b7b1e41b 53 # whitespace on the line. So it seems better to mark lines that
000fd473
NC
54 # need to be eliminated. I considered (?# ... ) and (?{ ... }),
55 # but whilst embedded code or comment syntax would keep it as a
56 # legitimate regexp, it still isn't true. Seems easier and clearer
57 # things that look like comments.
58
59 # Could do this is in a s///mge but seems clearer like this:
60 $pattern = join '', map {
61 # If we identify the version condition, take *it* out whatever
bad4ae38 62 s/\s*# (\$].*)$//
000fd473
NC
63 ? (eval $1 ? $_ : '')
64 : $_ # Didn't match, so this line is in
65 } split /^/, $pattern;
66
67 $pattern =~ s/\$PADMY/
68 ($] < 5.009) ? 'PADBUSY,PADMY' : 'PADMY';
69 /mge;
70 $pattern =~ s/\$PADTMP/
71 ($] < 5.009) ? 'PADBUSY,PADTMP' : 'PADTMP';
72 /mge;
2b631c93
NC
73 $pattern =~ s/\$RV/
74 ($] < 5.011) ? 'RV' : 'IV';
75 /mge;
d04ba589 76
9248c45a 77 print $pattern, "\n" if $DEBUG;
e9569a7a 78 my ($dump, $dump2) = split m/\*\*\*\*\*\n/, scalar <IN>;
9248c45a 79 print $dump, "\n" if $DEBUG;
06a5cade
NC
80 like( $dump, qr/\A$pattern\Z/ms, $_[0])
81 or note("line " . (caller)[2]);
e9569a7a 82
000fd473 83 local $TODO = $repeat_todo;
06a5cade
NC
84 is($dump2, $dump, "$_[0] (unchanged by dump)")
85 or note("line " . (caller)[2]);
e9569a7a 86
9248c45a 87 close(IN);
e9569a7a 88
59d8ce62 89 return $1;
9248c45a
JH
90 } else {
91 die "$0: failed to open peek$$: !\n";
92 }
93 } else {
94 die "$0: failed to create peek$$: $!\n";
95 }
96}
97
98our $a;
99our $b;
100my $c;
208edb77 101local $d = 0;
9248c45a 102
e7ecf62c
RGS
103END {
104 1 while unlink("peek$$");
105}
bf53b3a5 106
06a5cade 107do_test('assignment of immediate constant (string)',
9248c45a
JH
108 $a = "foo",
109'SV = PV\\($ADDR\\) at $ADDR
110 REFCNT = 1
111 FLAGS = \\(POK,pPOK\\)
112 PV = $ADDR "foo"\\\0
113 CUR = 3
1badabf5 114 LEN = \\d+'
9248c45a
JH
115 );
116
06a5cade 117do_test('immediate constant (string)',
9248c45a
JH
118 "bar",
119'SV = PV\\($ADDR\\) at $ADDR
120 REFCNT = 1
7766e686 121 FLAGS = \\(.*POK,READONLY,pPOK\\)
9248c45a
JH
122 PV = $ADDR "bar"\\\0
123 CUR = 3
1badabf5 124 LEN = \\d+');
9248c45a 125
b7b1e41b 126do_test('assignment of immediate constant (integer)',
9248c45a
JH
127 $b = 123,
128'SV = IV\\($ADDR\\) at $ADDR
129 REFCNT = 1
130 FLAGS = \\(IOK,pIOK\\)
131 IV = 123');
132
06a5cade 133do_test('immediate constant (integer)',
9248c45a
JH
134 456,
135'SV = IV\\($ADDR\\) at $ADDR
136 REFCNT = 1
7766e686 137 FLAGS = \\(.*IOK,READONLY,pIOK\\)
9248c45a
JH
138 IV = 456');
139
06a5cade 140do_test('assignment of immediate constant (integer)',
9248c45a
JH
141 $c = 456,
142'SV = IV\\($ADDR\\) at $ADDR
143 REFCNT = 1
000fd473 144 FLAGS = \\($PADMY,IOK,pIOK\\)
9248c45a
JH
145 IV = 456');
146
59d8ce62
NC
147# If perl is built with PERL_PRESERVE_IVUV then maths is done as integers
148# where possible and this scalar will be an IV. If NO_PERL_PRESERVE_IVUV then
149# maths is done in floating point always, and this scalar will be an NV.
150# ([NI]) captures the type, referred to by \1 in this regexp and $type for
151# building subsequent regexps.
06a5cade 152my $type = do_test('result of addition',
9248c45a 153 $c + $d,
59d8ce62 154'SV = ([NI])V\\($ADDR\\) at $ADDR
9248c45a 155 REFCNT = 1
59d8ce62
NC
156 FLAGS = \\(PADTMP,\1OK,p\1OK\\)
157 \1V = 456');
9248c45a
JH
158
159($d = "789") += 0.1;
160
06a5cade 161do_test('floating point value',
9248c45a
JH
162 $d,
163'SV = PVNV\\($ADDR\\) at $ADDR
164 REFCNT = 1
165 FLAGS = \\(NOK,pNOK\\)
78d00c47 166 IV = \d+
ac634a9a 167 NV = 789\\.(?:1(?:000+\d+)?|0999+\d+)
9248c45a
JH
168 PV = $ADDR "789"\\\0
169 CUR = 3
1badabf5 170 LEN = \\d+');
9248c45a 171
06a5cade 172do_test('integer constant',
9248c45a
JH
173 0xabcd,
174'SV = IV\\($ADDR\\) at $ADDR
175 REFCNT = 1
28e5dec8
JH
176 FLAGS = \\(.*IOK,READONLY,pIOK\\)
177 IV = 43981');
9248c45a 178
06a5cade 179do_test('undef',
9248c45a
JH
180 undef,
181'SV = NULL\\(0x0\\) at $ADDR
182 REFCNT = 1
183 FLAGS = \\(\\)');
184
06a5cade 185do_test('reference to scalar',
9248c45a 186 \$a,
4df7f6af 187'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
188 REFCNT = 1
189 FLAGS = \\(ROK\\)
190 RV = $ADDR
191 SV = PV\\($ADDR\\) at $ADDR
192 REFCNT = 2
193 FLAGS = \\(POK,pPOK\\)
194 PV = $ADDR "foo"\\\0
195 CUR = 3
1badabf5 196 LEN = \\d+');
9248c45a 197
59d8ce62
NC
198my $c_pattern;
199if ($type eq 'N') {
200 $c_pattern = '
201 SV = PVNV\\($ADDR\\) at $ADDR
202 REFCNT = 1
203 FLAGS = \\(IOK,NOK,pIOK,pNOK\\)
204 IV = 456
205 NV = 456
206 PV = 0';
207} else {
208 $c_pattern = '
209 SV = IV\\($ADDR\\) at $ADDR
210 REFCNT = 1
211 FLAGS = \\(IOK,pIOK\\)
212 IV = 456';
213}
06a5cade 214do_test('reference to array',
9248c45a 215 [$b,$c],
4df7f6af 216'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
217 REFCNT = 1
218 FLAGS = \\(ROK\\)
219 RV = $ADDR
220 SV = PVAV\\($ADDR\\) at $ADDR
78c72037 221 REFCNT = 1
9248c45a 222 FLAGS = \\(\\)
1bcecb77
NC
223 IV = 0 # $] < 5.009
224 NV = 0 # $] < 5.009
9248c45a
JH
225 ARRAY = $ADDR
226 FILL = 1
227 MAX = 1
228 ARYLEN = 0x0
229 FLAGS = \\(REAL\\)
230 Elt No. 0
231 SV = IV\\($ADDR\\) at $ADDR
232 REFCNT = 1
233 FLAGS = \\(IOK,pIOK\\)
234 IV = 123
59d8ce62 235 Elt No. 1' . $c_pattern);
9248c45a 236
06a5cade 237do_test('reference to hash',
9248c45a 238 {$b=>$c},
4df7f6af 239'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
240 REFCNT = 1
241 FLAGS = \\(ROK\\)
242 RV = $ADDR
243 SV = PVHV\\($ADDR\\) at $ADDR
78c72037 244 REFCNT = 1
9248c45a 245 FLAGS = \\(SHAREKEYS\\)
1bcecb77
NC
246 IV = 1 # $] < 5.009
247 NV = $FLOAT # $] < 5.009
9248c45a 248 ARRAY = $ADDR \\(0:7, 1:1\\)
b8fa94d8 249 hash quality = 100.0%
9248c45a
JH
250 KEYS = 1
251 FILL = 1
252 MAX = 7
253 RITER = -1
254 EITER = 0x0
000fd473
NC
255 Elt "123" HASH = $ADDR' . $c_pattern,
256 '',
f3ce8053
FC
257 $] > 5.009 && $] < 5.015
258 && 'The hash iterator used in dump.c sets the OOK flag');
9248c45a 259
06a5cade 260do_test('reference to anon sub with empty prototype',
9248c45a 261 sub(){@_},
4df7f6af 262'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
263 REFCNT = 1
264 FLAGS = \\(ROK\\)
265 RV = $ADDR
266 SV = PVCV\\($ADDR\\) at $ADDR
267 REFCNT = 2
bad4ae38
FC
268 FLAGS = \\($PADMY,POK,pPOK,ANON,WEAKOUTSIDE,CVGV_RC\\) # $] < 5.015 || !thr
269 FLAGS = \\($PADMY,POK,pPOK,ANON,WEAKOUTSIDE,CVGV_RC,DYNFILE\\) # $] >= 5.015 && thr
1bcecb77
NC
270 IV = 0 # $] < 5.009
271 NV = 0 # $] < 5.009
9248c45a
JH
272 PROTOTYPE = ""
273 COMP_STASH = $ADDR\\t"main"
274 START = $ADDR ===> \\d+
275 ROOT = $ADDR
1bcecb77
NC
276 XSUB = 0x0 # $] < 5.009
277 XSUBANY = 0 # $] < 5.009
208edb77 278 GVGV::GV = $ADDR\\t"main" :: "__ANON__[^"]*"
084d946d 279 FILE = ".*\\b(?i:peek\\.t)"
000fd473
NC
280 DEPTH = 0(?:
281 MUTEXP = $ADDR
282 OWNER = $ADDR)?
1bcecb77 283 FLAGS = 0x404 # $] < 5.009
bad4ae38
FC
284 FLAGS = 0x490 # $] >= 5.009 && ($] < 5.015 || !thr)
285 FLAGS = 0x1490 # $] >= 5.015 && thr
a3985cdc 286 OUTSIDE_SEQ = \\d+
9248c45a 287 PADLIST = $ADDR
dd2155a4 288 PADNAME = $ADDR\\($ADDR\\) PAD = $ADDR\\($ADDR\\)
9248c45a
JH
289 OUTSIDE = $ADDR \\(MAIN\\)');
290
06a5cade 291do_test('reference to named subroutine without prototype',
9248c45a 292 \&do_test,
4df7f6af 293'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
294 REFCNT = 1
295 FLAGS = \\(ROK\\)
296 RV = $ADDR
297 SV = PVCV\\($ADDR\\) at $ADDR
9856a127 298 REFCNT = (3|4)
bad4ae38
FC
299 FLAGS = \\(\\) # $] < 5.015 || !thr
300 FLAGS = \\(DYNFILE\\) # $] >= 5.015 && thr
1bcecb77
NC
301 IV = 0 # $] < 5.009
302 NV = 0 # $] < 5.009
9248c45a
JH
303 COMP_STASH = $ADDR\\t"main"
304 START = $ADDR ===> \\d+
305 ROOT = $ADDR
1bcecb77
NC
306 XSUB = 0x0 # $] < 5.009
307 XSUBANY = 0 # $] < 5.009
9248c45a 308 GVGV::GV = $ADDR\\t"main" :: "do_test"
084d946d 309 FILE = ".*\\b(?i:peek\\.t)"
bad4ae38
FC
310 DEPTH = 1(?:
311 MUTEXP = $ADDR
312 OWNER = $ADDR)?
313 FLAGS = 0x0 # $] < 5.015 || !thr
314 FLAGS = 0x1000 # $] >= 5.015 && thr
a3985cdc 315 OUTSIDE_SEQ = \\d+
9248c45a 316 PADLIST = $ADDR
dd2155a4 317 PADNAME = $ADDR\\($ADDR\\) PAD = $ADDR\\($ADDR\\)
000fd473
NC
318 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$todo"
319 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$repeat_todo"
ee6cee0c 320 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$pattern"
000fd473
NC
321 \\d+\\. $ADDR<\\d+> FAKE "\\$DEBUG" # $] < 5.009
322 \\d+\\. $ADDR<\\d+> FAKE "\\$DEBUG" flags=0x0 index=0 # $] >= 5.009
ee6cee0c 323 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$dump"
e9569a7a 324 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$dump2"
9248c45a
JH
325 OUTSIDE = $ADDR \\(MAIN\\)');
326
3ce3ed55 327if ($] >= 5.011) {
06a5cade 328do_test('reference to regexp',
3ce3ed55
NC
329 qr(tic),
330'SV = $RV\\($ADDR\\) at $ADDR
331 REFCNT = 1
332 FLAGS = \\(ROK\\)
333 RV = $ADDR
5c35adbb 334 SV = REGEXP\\($ADDR\\) at $ADDR
c2123ae3 335 REFCNT = 1
b9ad13ac 336 FLAGS = \\(OBJECT,POK,FAKE,pPOK\\)
fb85c044
KW
337 PV = $ADDR "\\(\\?\\^:tic\\)"
338 CUR = 8
c2123ae3 339 LEN = 0
d63e6659
DM
340 STASH = $ADDR\\t"Regexp"'
341. ($] < 5.013 ? '' :
342'
343 EXTFLAGS = 0x680000 \(CHECK_ALL,USE_INTUIT_NOML,USE_INTUIT_ML\)
344 INTFLAGS = 0x0
345 NPARENS = 0
346 LASTPAREN = 0
347 LASTCLOSEPAREN = 0
348 MINLEN = 3
349 MINLENRET = 3
350 GOFS = 0
351 PRE_PREFIX = 4
352 SEEN_EVALS = 0
353 SUBLEN = 0
354 SUBBEG = 0x0
355 ENGINE = $ADDR
356 MOTHER_RE = $ADDR
357 PAREN_NAMES = 0x0
358 SUBSTRS = $ADDR
359 PPRIVATE = $ADDR
360 OFFS = $ADDR'
361));
3ce3ed55 362} else {
06a5cade 363do_test('reference to regexp',
9248c45a 364 qr(tic),
4df7f6af 365'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
366 REFCNT = 1
367 FLAGS = \\(ROK\\)
368 RV = $ADDR
369 SV = PVMG\\($ADDR\\) at $ADDR
370 REFCNT = 1
faf82a0b 371 FLAGS = \\(OBJECT,SMG\\)
9248c45a
JH
372 IV = 0
373 NV = 0
374 PV = 0
375 MAGIC = $ADDR
376 MG_VIRTUAL = $ADDR
14befaf4 377 MG_TYPE = PERL_MAGIC_qr\(r\)
9248c45a 378 MG_OBJ = $ADDR
fb85c044 379 PAT = "\(\?^:tic\)" # $] >= 5.009
1bcecb77 380 REFCNT = 2 # $] >= 5.009
9248c45a 381 STASH = $ADDR\\t"Regexp"');
3ce3ed55 382}
9248c45a 383
06a5cade 384do_test('reference to blessed hash',
9248c45a 385 (bless {}, "Tac"),
4df7f6af 386'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
387 REFCNT = 1
388 FLAGS = \\(ROK\\)
389 RV = $ADDR
390 SV = PVHV\\($ADDR\\) at $ADDR
78c72037 391 REFCNT = 1
9248c45a 392 FLAGS = \\(OBJECT,SHAREKEYS\\)
1bcecb77
NC
393 IV = 0 # $] < 5.009
394 NV = 0 # $] < 5.009
9248c45a
JH
395 STASH = $ADDR\\t"Tac"
396 ARRAY = 0x0
397 KEYS = 0
398 FILL = 0
399 MAX = 7
400 RITER = -1
000fd473 401 EITER = 0x0', '',
f3ce8053
FC
402 $] > 5.009
403 ? $] >= 5.015
404 ? 0
405 : 'The hash iterator used in dump.c sets the OOK flag'
000fd473 406 : "Something causes the HV's array to become allocated");
9248c45a 407
06a5cade 408do_test('typeglob',
9248c45a
JH
409 *a,
410'SV = PVGV\\($ADDR\\) at $ADDR
411 REFCNT = 5
000fd473
NC
412 FLAGS = \\(MULTI(?:,IN_PAD)?\\) # $] >= 5.009
413 FLAGS = \\(GMG,SMG,MULTI(?:,IN_PAD)?\\) # $] < 5.009
414 IV = 0 # $] < 5.009
415 NV = 0 # $] < 5.009
416 PV = 0 # $] < 5.009
417 MAGIC = $ADDR # $] < 5.009
418 MG_VIRTUAL = &PL_vtbl_glob # $] < 5.009
419 MG_TYPE = PERL_MAGIC_glob\(\*\) # $] < 5.009
420 MG_OBJ = $ADDR # $] < 5.009
9248c45a
JH
421 NAME = "a"
422 NAMELEN = 1
423 GvSTASH = $ADDR\\t"main"
424 GP = $ADDR
425 SV = $ADDR
426 REFCNT = 1
427 IO = 0x0
428 FORM = 0x0
429 AV = 0x0
430 HV = 0x0
431 CV = 0x0
432 CVGEN = 0x0
000fd473 433 GPFLAGS = 0x0 # $] < 5.009
9ec58fb7 434 LINE = \\d+
084d946d 435 FILE = ".*\\b(?i:peek\\.t)"
e39917cc 436 FLAGS = $ADDR
9248c45a
JH
437 EGV = $ADDR\\t"a"');
438
cdb2dd7b 439if (ord('A') == 193) {
06a5cade 440do_test('string with Unicode',
cdb2dd7b
JH
441 chr(256).chr(0).chr(512),
442'SV = PV\\($ADDR\\) at $ADDR
443 REFCNT = 1
000fd473 444 FLAGS = \\((?:$PADTMP,)?POK,READONLY,pPOK,UTF8\\)
cdb2dd7b
JH
445 PV = $ADDR "\\\214\\\101\\\0\\\235\\\101"\\\0 \[UTF8 "\\\x\{100\}\\\x\{0\}\\\x\{200\}"\]
446 CUR = 5
1badabf5 447 LEN = \\d+');
cdb2dd7b 448} else {
06a5cade 449do_test('string with Unicode',
e6abe6d8
JH
450 chr(256).chr(0).chr(512),
451'SV = PV\\($ADDR\\) at $ADDR
452 REFCNT = 1
000fd473 453 FLAGS = \\((?:$PADTMP,)?POK,READONLY,pPOK,UTF8\\)
98c991d1 454 PV = $ADDR "\\\304\\\200\\\0\\\310\\\200"\\\0 \[UTF8 "\\\x\{100\}\\\x\{0\}\\\x\{200\}"\]
e6abe6d8 455 CUR = 5
1badabf5 456 LEN = \\d+');
cdb2dd7b 457}
e6abe6d8 458
cdb2dd7b 459if (ord('A') == 193) {
06a5cade 460do_test('reference to hash containing Unicode',
cdb2dd7b 461 {chr(256)=>chr(512)},
4df7f6af 462'SV = $RV\\($ADDR\\) at $ADDR
cdb2dd7b
JH
463 REFCNT = 1
464 FLAGS = \\(ROK\\)
465 RV = $ADDR
466 SV = PVHV\\($ADDR\\) at $ADDR
78c72037 467 REFCNT = 1
b2caaddd 468 FLAGS = \\(SHAREKEYS,HASKFLAGS\\)
1bcecb77
NC
469 UV = 1 # $] < 5.009
470 NV = $FLOAT # $] < 5.009
cdb2dd7b
JH
471 ARRAY = $ADDR \\(0:7, 1:1\\)
472 hash quality = 100.0%
473 KEYS = 1
474 FILL = 1
475 MAX = 7
476 RITER = -1
477 EITER = $ADDR
6cbfa5b4 478 Elt "\\\214\\\101" \[UTF8 "\\\x\{100\}"\] HASH = $ADDR
cdb2dd7b
JH
479 SV = PV\\($ADDR\\) at $ADDR
480 REFCNT = 1
481 FLAGS = \\(POK,pPOK,UTF8\\)
482 PV = $ADDR "\\\235\\\101"\\\0 \[UTF8 "\\\x\{200\}"\]
483 CUR = 2
000fd473 484 LEN = \\d+',
f3ce8053
FC
485 $] > 5.009
486 ? $] >= 5.015
487 ? 0
488 : 'The hash iterator used in dump.c sets the OOK flag'
000fd473 489 : 'sv_length has been called on the element, and cached the result in MAGIC');
cdb2dd7b 490} else {
06a5cade 491do_test('reference to hash containing Unicode',
98c991d1 492 {chr(256)=>chr(512)},
4df7f6af 493'SV = $RV\\($ADDR\\) at $ADDR
98c991d1
JH
494 REFCNT = 1
495 FLAGS = \\(ROK\\)
496 RV = $ADDR
497 SV = PVHV\\($ADDR\\) at $ADDR
78c72037 498 REFCNT = 1
19692e8d 499 FLAGS = \\(SHAREKEYS,HASKFLAGS\\)
1bcecb77
NC
500 UV = 1 # $] < 5.009
501 NV = 0 # $] < 5.009
98c991d1
JH
502 ARRAY = $ADDR \\(0:7, 1:1\\)
503 hash quality = 100.0%
504 KEYS = 1
505 FILL = 1
506 MAX = 7
507 RITER = -1
508 EITER = $ADDR
509 Elt "\\\304\\\200" \[UTF8 "\\\x\{100\}"\] HASH = $ADDR
510 SV = PV\\($ADDR\\) at $ADDR
511 REFCNT = 1
512 FLAGS = \\(POK,pPOK,UTF8\\)
513 PV = $ADDR "\\\310\\\200"\\\0 \[UTF8 "\\\x\{200\}"\]
514 CUR = 2
000fd473 515 LEN = \\d+', '',
f3ce8053
FC
516 $] > 5.009
517 ? $] >= 5.015
518 ? 0
519 : 'The hash iterator used in dump.c sets the OOK flag'
000fd473 520 : 'sv_length has been called on the element, and cached the result in MAGIC');
cdb2dd7b 521}
98c991d1 522
99331854
YST
523my $x="";
524$x=~/.??/g;
06a5cade 525do_test('scalar with pos magic',
99331854
YST
526 $x,
527'SV = PVMG\\($ADDR\\) at $ADDR
528 REFCNT = 1
000fd473 529 FLAGS = \\($PADMY,SMG,POK,pPOK\\)
99331854
YST
530 IV = 0
531 NV = 0
532 PV = $ADDR ""\\\0
533 CUR = 0
1936d2a7 534 LEN = \d+
99331854
YST
535 MAGIC = $ADDR
536 MG_VIRTUAL = &PL_vtbl_mglob
537 MG_TYPE = PERL_MAGIC_regex_global\\(g\\)
538 MG_FLAGS = 0x01
539 MINMATCH');
540
f24fdb76
HS
541#
542# TAINTEDDIR is not set on: OS2, AMIGAOS, WIN32, MSDOS
543# environment variables may be invisibly case-forced, hence the (?i:PATH)
5e836f43 544# C<scalar(@ARGV)> is turned into an IV on VMS hence the (?:IV)?
d9baf692
JM
545# VMS is setting FAKE and READONLY flags. What VMS uses for storing
546# ENV hashes is also not always null terminated.
f24fdb76 547#
06a5cade 548do_test('tainted value in %ENV',
99331854
YST
549 $ENV{PATH}=@ARGV, # scalar(@ARGV) is a handy known tainted value
550'SV = PVMG\\($ADDR\\) at $ADDR
551 REFCNT = 1
552 FLAGS = \\(GMG,SMG,RMG,pIOK,pPOK\\)
553 IV = 0
554 NV = 0
555 PV = $ADDR "0"\\\0
556 CUR = 1
557 LEN = \d+
558 MAGIC = $ADDR
559 MG_VIRTUAL = &PL_vtbl_envelem
560 MG_TYPE = PERL_MAGIC_envelem\\(e\\)
d25a523c 561(?: MG_FLAGS = 0x01
99331854 562 TAINTEDDIR
143a3e5e
CB
563)? MG_LEN = -?\d+
564 MG_PTR = $ADDR (?:"(?i:PATH)"|=> HEf_SVKEY
5e836f43 565 SV = PV(?:IV)?\\($ADDR\\) at $ADDR
143a3e5e 566 REFCNT = \d+
11e2783c 567 FLAGS = \\(TEMP,POK,(?:FAKE,READONLY,)?pPOK\\)
f0fabfd7 568(?: IV = 0
d9baf692 569)? PV = $ADDR "(?i:PATH)"(?:\\\0)?
143a3e5e
CB
570 CUR = \d+
571 LEN = \d+)
99331854
YST
572 MAGIC = $ADDR
573 MG_VIRTUAL = &PL_vtbl_taint
574 MG_TYPE = PERL_MAGIC_taint\\(t\\)');
575
06a5cade 576do_test('blessed reference',
6bf47b08 577 bless(\\undef, 'Foobar'),
4df7f6af 578'SV = $RV\\($ADDR\\) at $ADDR
6bf47b08
SR
579 REFCNT = 1
580 FLAGS = \\(ROK\\)
581 RV = $ADDR
582 SV = PVMG\\($ADDR\\) at $ADDR
583 REFCNT = 2
584 FLAGS = \\(OBJECT,ROK\\)
7957ad98
MB
585 IV = -?\d+
586 NV = $FLOAT
6bf47b08
SR
587 RV = $ADDR
588 SV = NULL\\(0x0\\) at $ADDR
589 REFCNT = \d+
590 FLAGS = \\(READONLY\\)
591 PV = $ADDR ""
592 CUR = 0
593 LEN = 0
594 STASH = $ADDR\s+"Foobar"');
b1886099 595
b1886099
NC
596sub const () {
597 "Perl rules";
598}
599
06a5cade 600do_test('constant subroutine',
b1886099 601 \&const,
4df7f6af 602'SV = $RV\\($ADDR\\) at $ADDR
b1886099
NC
603 REFCNT = 1
604 FLAGS = \\(ROK\\)
605 RV = $ADDR
606 SV = PVCV\\($ADDR\\) at $ADDR
607 REFCNT = (2)
bad4ae38
FC
608 FLAGS = \\(POK,pPOK,CONST,ISXSUB\\) # $] < 5.015
609 FLAGS = \\(POK,pPOK,CONST,DYNFILE,ISXSUB\\) # $] >= 5.015
1bcecb77
NC
610 IV = 0 # $] < 5.009
611 NV = 0 # $] < 5.009
b1886099
NC
612 PROTOTYPE = ""
613 COMP_STASH = 0x0
1bcecb77 614 ROOT = 0x0 # $] < 5.009
b1886099
NC
615 XSUB = $ADDR
616 XSUBANY = $ADDR \\(CONST SV\\)
617 SV = PV\\($ADDR\\) at $ADDR
618 REFCNT = 1
619 FLAGS = \\(.*POK,READONLY,pPOK\\)
620 PV = $ADDR "Perl rules"\\\0
621 CUR = 10
622 LEN = \\d+
623 GVGV::GV = $ADDR\\t"main" :: "const"
624 FILE = ".*\\b(?i:peek\\.t)"
000fd473
NC
625 DEPTH = 0(?:
626 MUTEXP = $ADDR
627 OWNER = $ADDR)?
1bcecb77 628 FLAGS = 0x200 # $] < 5.009
c2485e0c 629 FLAGS = 0xc00 # $] >= 5.009 && $] < 5.013
bad4ae38
FC
630 FLAGS = 0xc # $] >= 5.013 && $] < 5.015
631 FLAGS = 0x100c # $] >= 5.015
b1886099
NC
632 OUTSIDE_SEQ = 0
633 PADLIST = 0x0
634 OUTSIDE = 0x0 \\(null\\)');
2e94196c 635
06a5cade 636do_test('isUV should show on PVMG',
2e94196c
NC
637 do { my $v = $1; $v = ~0; $v },
638'SV = PVMG\\($ADDR\\) at $ADDR
639 REFCNT = 1
640 FLAGS = \\(IOK,pIOK,IsUV\\)
641 UV = \d+
642 NV = 0
643 PV = 0');
c0a413d1 644
06a5cade 645do_test('IO',
c0a413d1
NC
646 *STDOUT{IO},
647'SV = $RV\\($ADDR\\) at $ADDR
648 REFCNT = 1
649 FLAGS = \\(ROK\\)
650 RV = $ADDR
651 SV = PVIO\\($ADDR\\) at $ADDR
652 REFCNT = 3
653 FLAGS = \\(OBJECT\\)
3cf51070 654 IV = 0 # $] < 5.011
1bcecb77 655 NV = 0 # $] < 5.011
d963bf01 656 STASH = $ADDR\s+"IO::File"
c0a413d1
NC
657 IFP = $ADDR
658 OFP = $ADDR
659 DIRP = 0x0
660 LINES = 0
661 PAGE = 0
662 PAGE_LEN = 60
663 LINES_LEFT = 0
664 TOP_GV = 0x0
665 FMT_GV = 0x0
666 BOTTOM_GV = 0x0
1bcecb77 667 SUBPROCESS = 0 # $] < 5.009
c0a413d1 668 TYPE = \'>\'
50a9fad1 669 FLAGS = 0x4');
bfe27a58 670
06a5cade 671do_test('FORMAT',
bfe27a58
NC
672 *PIE{FORMAT},
673'SV = $RV\\($ADDR\\) at $ADDR
674 REFCNT = 1
675 FLAGS = \\(ROK\\)
676 RV = $ADDR
677 SV = PVFM\\($ADDR\\) at $ADDR
678 REFCNT = 2
bad4ae38
FC
679 FLAGS = \\(\\) # $] < 5.015 || !thr
680 FLAGS = \\(DYNFILE\\) # $] >= 5.015 && thr
30ec677d 681 IV = 0 # $] < 5.009
bfe27a58 682 NV = 0 # $] < 5.009
251a4af1
DM
683(?: PV = 0
684)? COMP_STASH = 0x0
bfe27a58
NC
685 START = $ADDR ===> \\d+
686 ROOT = $ADDR
687 XSUB = 0x0 # $] < 5.009
688 XSUBANY = 0 # $] < 5.009
689 GVGV::GV = $ADDR\\t"main" :: "PIE"
bad4ae38
FC
690 FILE = ".*\\b(?i:peek\\.t)"(?:
691 DEPTH = 0
c12100a4 692 MUTEXP = $ADDR
bad4ae38
FC
693 OWNER = $ADDR)?
694 FLAGS = 0x0 # $] < 5.015 || !thr
695 FLAGS = 0x1000 # $] >= 5.015 && thr
bfe27a58
NC
696 OUTSIDE_SEQ = \\d+
697 LINES = 0
698 PADLIST = $ADDR
699 PADNAME = $ADDR\\($ADDR\\) PAD = $ADDR\\($ADDR\\)
700 OUTSIDE = $ADDR \\(MAIN\\)');
d7d51f4b 701
b7b1e41b 702do_test('blessing to a class with embedded NUL characters',
d7d51f4b
YO
703 (bless {}, "\0::foo::\n::baz::\t::\0"),
704'SV = $RV\\($ADDR\\) at $ADDR
705 REFCNT = 1
706 FLAGS = \\(ROK\\)
707 RV = $ADDR
708 SV = PVHV\\($ADDR\\) at $ADDR
709 REFCNT = 1
710 FLAGS = \\(OBJECT,SHAREKEYS\\)
711 IV = 0 # $] < 5.009
712 NV = 0 # $] < 5.009
713 STASH = $ADDR\\t"\\\\0::foo::\\\\n::baz::\\\\t::\\\\0"
714 ARRAY = $ADDR
715 KEYS = 0
716 FILL = 0
717 MAX = 7
718 RITER = -1
719 EITER = 0x0', '',
f3ce8053
FC
720 $] > 5.009
721 ? $] >= 5.015
722 ? 0
723 : 'The hash iterator used in dump.c sets the OOK flag'
d7d51f4b
YO
724 : "Something causes the HV's array to become allocated");
725
bed53064
NC
726do_test('ENAME on a stash',
727 \%RWOM::,
728'SV = $RV\\($ADDR\\) at $ADDR
729 REFCNT = 1
730 FLAGS = \\(ROK\\)
731 RV = $ADDR
732 SV = PVHV\\($ADDR\\) at $ADDR
733 REFCNT = 2
734 FLAGS = \\(OOK,SHAREKEYS\\)
735 IV = 1 # $] < 5.009
736 NV = $FLOAT # $] < 5.009
737 ARRAY = $ADDR
738 KEYS = 0
739 FILL = 0
740 MAX = 7
741 RITER = -1
742 EITER = 0x0
743 NAME = "RWOM"
744 ENAME = "RWOM" # $] > 5.012
745');
746
747*KLANK:: = \%RWOM::;
748
749do_test('ENAMEs on a stash',
750 \%RWOM::,
751'SV = $RV\\($ADDR\\) at $ADDR
752 REFCNT = 1
753 FLAGS = \\(ROK\\)
754 RV = $ADDR
755 SV = PVHV\\($ADDR\\) at $ADDR
756 REFCNT = 3
757 FLAGS = \\(OOK,SHAREKEYS\\)
758 IV = 1 # $] < 5.009
759 NV = $FLOAT # $] < 5.009
760 ARRAY = $ADDR
761 KEYS = 0
762 FILL = 0
763 MAX = 7
764 RITER = -1
765 EITER = 0x0
766 NAME = "RWOM"
767 NAMECOUNT = 2 # $] > 5.012
768 ENAME = "RWOM", "KLANK" # $] > 5.012
769');
770
771undef %RWOM::;
772
773do_test('ENAMEs on a stash with no NAME',
774 \%RWOM::,
775'SV = $RV\\($ADDR\\) at $ADDR
776 REFCNT = 1
777 FLAGS = \\(ROK\\)
778 RV = $ADDR
779 SV = PVHV\\($ADDR\\) at $ADDR
780 REFCNT = 3
781 FLAGS = \\(OOK,SHAREKEYS\\)
782 IV = 1 # $] < 5.009
783 NV = $FLOAT # $] < 5.009
784 ARRAY = $ADDR
785 KEYS = 0
786 FILL = 0
787 MAX = 7
788 RITER = -1
789 EITER = 0x0
790 NAMECOUNT = -3 # $] > 5.012
791 ENAME = "RWOM", "KLANK" # $] > 5.012
792');
793
4ab5bd5f
FC
794SKIP: {
795 skip "Not built with usemymalloc", 1
796 unless $Config{usemymalloc} eq 'y';
797 my $x = __PACKAGE__;
798 ok eval { fill_mstats($x); 1 }, 'fill_mstats on COW scalar'
799 or diag $@;
800}
801
bc9a5256
NC
802# This is more a test of fbm_compile/pp_study (non) interaction than dumping
803# prowess, but short of duplicating all the gubbins of this file, I can't see
804# a way to make a better place for it:
805
ccbcbb3d
NC
806use constant {
807 perl => 'rules',
808 beer => 'foamy',
809};
0a0c4b76
NC
810
811unless ($Config{useithreads}) {
812 # These end up as copies in pads under ithreads, which rather defeats the
813 # the point of what we're trying to test here.
814
815 do_test('regular string constant', perl,
816'SV = PV\\($ADDR\\) at $ADDR
bc9a5256 817 REFCNT = 5
0a0c4b76
NC
818 FLAGS = \\(PADMY,POK,READONLY,pPOK\\)
819 PV = $ADDR "rules"\\\0
820 CUR = 5
821 LEN = \d+
822');
823
824 eval 'index "", perl';
825
826 # FIXME - really this shouldn't say EVALED. It's a false posistive on
827 # 0x40000000 being used for several things, not a flag for "I'm in a string
828 # eval"
829
830 do_test('string constant now an FBM', perl,
c13a5c80 831'SV = PVMG\\($ADDR\\) at $ADDR
bc9a5256
NC
832 REFCNT = 5
833 FLAGS = \\(PADMY,SMG,POK,READONLY,pPOK,VALID,EVALED\\)
834 PV = $ADDR "rules"\\\0
835 CUR = 5
836 LEN = \d+
837 MAGIC = $ADDR
b76b0bf9 838 MG_VIRTUAL = &PL_vtbl_regexp
bc9a5256 839 MG_TYPE = PERL_MAGIC_bm\\(B\\)
2bda37ba
NC
840 MG_LEN = 256
841 MG_PTR = $ADDR "(?:\\\\\d){256}"
bc9a5256
NC
842 RARE = \d+
843 PREVIOUS = 1
844 USEFUL = 100
845');
846
847 is(study perl, '', "Not allowed to study an FBM");
848
849 do_test('string constant still an FBM', perl,
c13a5c80 850'SV = PVMG\\($ADDR\\) at $ADDR
bc9a5256 851 REFCNT = 5
0a0c4b76
NC
852 FLAGS = \\(PADMY,SMG,POK,READONLY,pPOK,VALID,EVALED\\)
853 PV = $ADDR "rules"\\\0
854 CUR = 5
855 LEN = \d+
856 MAGIC = $ADDR
b76b0bf9 857 MG_VIRTUAL = &PL_vtbl_regexp
0a0c4b76 858 MG_TYPE = PERL_MAGIC_bm\\(B\\)
2bda37ba
NC
859 MG_LEN = 256
860 MG_PTR = $ADDR "(?:\\\\\d){256}"
0a0c4b76
NC
861 RARE = \d+
862 PREVIOUS = 1
863 USEFUL = 100
864');
ccbcbb3d
NC
865
866 do_test('regular string constant', beer,
867'SV = PV\\($ADDR\\) at $ADDR
4185c919 868 REFCNT = 6
ccbcbb3d
NC
869 FLAGS = \\(PADMY,POK,READONLY,pPOK\\)
870 PV = $ADDR "foamy"\\\0
871 CUR = 5
872 LEN = \d+
873');
874
4185c919 875 my $want = 'SV = PVMG\\($ADDR\\) at $ADDR
4265b45d
NC
876 REFCNT = 6
877 FLAGS = \\(PADMY,SMG,POK,READONLY,pPOK,SCREAM\\)
878 IV = 0
879 NV = 0
880 PV = $ADDR "foamy"\\\0
881 CUR = 5
882 LEN = \d+
883 MAGIC = $ADDR
0177730e 884 MG_VIRTUAL = &PL_vtbl_regexp
72de20cd 885 MG_PRIVATE = 1
0177730e 886 MG_TYPE = PERL_MAGIC_study\\(G\\)
72de20cd
NC
887 MG_LEN = 261
888 MG_PTR = $ADDR "\\\\377.*"
4185c919
NC
889';
890
891 is(study beer, 1, "Our studies were successful");
892
893 do_test('string constant now studied', beer, $want);
4265b45d
NC
894
895 is (eval 'index "not too foamy", beer', 8, 'correct index');
896
4185c919
NC
897 do_test('string constant still studied', beer, $want);
898
899 my $pie = 'good';
900
901 is(study $pie, 1, "Our studies were successful");
902
903 do_test('string constant still studied', beer, $want);
904
905 do_test('second string also studied', $pie, 'SV = PVMG\\($ADDR\\) at $ADDR
906 REFCNT = 1
907 FLAGS = \\(PADMY,SMG,POK,pPOK,SCREAM\\)
ccbcbb3d
NC
908 IV = 0
909 NV = 0
4185c919
NC
910 PV = $ADDR "good"\\\0
911 CUR = 4
ccbcbb3d
NC
912 LEN = \d+
913 MAGIC = $ADDR
0177730e 914 MG_VIRTUAL = &PL_vtbl_regexp
72de20cd 915 MG_PRIVATE = 1
0177730e 916 MG_TYPE = PERL_MAGIC_study\\(G\\)
72de20cd
NC
917 MG_LEN = 260
918 MG_PTR = $ADDR "\\\\377.*"
ccbcbb3d 919');
0a0c4b76
NC
920}
921
72de20cd
NC
922{
923 my %z;
924 foreach (1, 254, 255, 65534, 65535) {
925 $z{$_} = "\0" x $_;
926 study $z{$_};
927 }
928 do_test('short studied representation', $z{1},
929'SV = PVMG\\($ADDR\\) at $ADDR
930 REFCNT = 1
931 FLAGS = \\(SMG,POK,pPOK,SCREAM\\)
932 IV = 0
933 NV = 0
934 PV = $ADDR "\\\\0"\\\0
935 CUR = 1
936 LEN = \d+
937 MAGIC = $ADDR
938 MG_VIRTUAL = &PL_vtbl_regexp
939 MG_PRIVATE = 1
940 MG_TYPE = PERL_MAGIC_study\\(G\\)
941 MG_LEN = 257
942 MG_PTR = $ADDR "\\\\0(?:\\\\377){256}"
943');
944
945 foreach ([254, 1], [255, 2], [65534, 2], [65535, 4]
946 ) {
947 my ($length, $bytes) = @$_;
948 my $quant = $length <= 32766 ? "{$length}" : '*';
949 do_test("studied representation for length $length", $z{$length},
950 sprintf
951'SV = PVMG\\($ADDR\\) at $ADDR
952 REFCNT = 1
953 FLAGS = \\(SMG,POK,pPOK,SCREAM\\)
954 IV = 0
955 NV = 0
956 PV = $ADDR "(?:\\\\0)%s"\\\0
957 CUR = %d
958 LEN = \d+
959 MAGIC = $ADDR
960 MG_VIRTUAL = &PL_vtbl_regexp
961 MG_PRIVATE = %d
962 MG_TYPE = PERL_MAGIC_study\\(G\\)
963 MG_LEN = %d
964 MG_PTR = $ADDR "\\\\0.*\\\\377"
965', $quant, $length, $bytes, (256 + $length) * $bytes);
966 }
967}
968
06a5cade 969done_testing();