This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Perl_do_sv_dump: move stub REGEXP code
[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
9248c45a 28sub do_test {
000fd473
NC
29 my $todo = $_[3];
30 my $repeat_todo = $_[4];
31 my $pattern = $_[2];
277ddfaf
GS
32 if (open(OUT,">peek$$")) {
33 open(STDERR, ">&OUT") or die "Can't dup OUT: $!";
9248c45a 34 Dump($_[1]);
e9569a7a
GG
35 print STDERR "*****\n";
36 Dump($_[1]); # second dump to compare with the first to make sure nothing changed.
277ddfaf
GS
37 open(STDERR, ">&SAVERR") or die "Can't restore STDERR: $!";
38 close(OUT);
9248c45a
JH
39 if (open(IN, "peek$$")) {
40 local $/;
41 $pattern =~ s/\$ADDR/0x[[:xdigit:]]+/g;
8aacddc1 42 $pattern =~ s/\$FLOAT/(?:\\d*\\.\\d+(?:e[-+]\\d+)?|\\d+)/g;
fd0854ff 43 # handle DEBUG_LEAKING_SCALARS prefix
d94a5950 44 $pattern =~ s/^(\s*)(SV =.* at )/(?:$1ALLOCATED at .*?\n)?$1$2/mg;
bf53b3a5 45
000fd473
NC
46 # Need some clear generic mechanism to eliminate (or add) lines
47 # of dump output dependant on perl version. The (previous) use of
48 # things like $IVNV gave the illusion that the string passed in was
49 # a regexp into which variables were interpolated, but this wasn't
50 # actually true as those 'variables' actually also ate the
b7b1e41b 51 # whitespace on the line. So it seems better to mark lines that
000fd473
NC
52 # need to be eliminated. I considered (?# ... ) and (?{ ... }),
53 # but whilst embedded code or comment syntax would keep it as a
54 # legitimate regexp, it still isn't true. Seems easier and clearer
55 # things that look like comments.
56
c2485e0c 57 my $version_condition = qr/\$] [<>]=? 5\.\d\d\d/;
000fd473
NC
58 # Could do this is in a s///mge but seems clearer like this:
59 $pattern = join '', map {
60 # If we identify the version condition, take *it* out whatever
c2485e0c 61 s/\s*# ($version_condition(?: && $version_condition)?)$//
000fd473
NC
62 ? (eval $1 ? $_ : '')
63 : $_ # Didn't match, so this line is in
64 } split /^/, $pattern;
65
66 $pattern =~ s/\$PADMY/
67 ($] < 5.009) ? 'PADBUSY,PADMY' : 'PADMY';
68 /mge;
69 $pattern =~ s/\$PADTMP/
70 ($] < 5.009) ? 'PADBUSY,PADTMP' : 'PADTMP';
71 /mge;
2b631c93
NC
72 $pattern =~ s/\$RV/
73 ($] < 5.011) ? 'RV' : 'IV';
74 /mge;
d04ba589 75
9248c45a 76 print $pattern, "\n" if $DEBUG;
e9569a7a 77 my ($dump, $dump2) = split m/\*\*\*\*\*\n/, scalar <IN>;
9248c45a 78 print $dump, "\n" if $DEBUG;
06a5cade
NC
79 like( $dump, qr/\A$pattern\Z/ms, $_[0])
80 or note("line " . (caller)[2]);
e9569a7a 81
000fd473 82 local $TODO = $repeat_todo;
06a5cade
NC
83 is($dump2, $dump, "$_[0] (unchanged by dump)")
84 or note("line " . (caller)[2]);
e9569a7a 85
9248c45a 86 close(IN);
e9569a7a 87
59d8ce62 88 return $1;
9248c45a
JH
89 } else {
90 die "$0: failed to open peek$$: !\n";
91 }
92 } else {
93 die "$0: failed to create peek$$: $!\n";
94 }
95}
96
97our $a;
98our $b;
99my $c;
208edb77 100local $d = 0;
9248c45a 101
e7ecf62c
RGS
102END {
103 1 while unlink("peek$$");
104}
bf53b3a5 105
06a5cade 106do_test('assignment of immediate constant (string)',
9248c45a
JH
107 $a = "foo",
108'SV = PV\\($ADDR\\) at $ADDR
109 REFCNT = 1
110 FLAGS = \\(POK,pPOK\\)
111 PV = $ADDR "foo"\\\0
112 CUR = 3
1badabf5 113 LEN = \\d+'
9248c45a
JH
114 );
115
06a5cade 116do_test('immediate constant (string)',
9248c45a
JH
117 "bar",
118'SV = PV\\($ADDR\\) at $ADDR
119 REFCNT = 1
7766e686 120 FLAGS = \\(.*POK,READONLY,pPOK\\)
9248c45a
JH
121 PV = $ADDR "bar"\\\0
122 CUR = 3
1badabf5 123 LEN = \\d+');
9248c45a 124
b7b1e41b 125do_test('assignment of immediate constant (integer)',
9248c45a
JH
126 $b = 123,
127'SV = IV\\($ADDR\\) at $ADDR
128 REFCNT = 1
129 FLAGS = \\(IOK,pIOK\\)
130 IV = 123');
131
06a5cade 132do_test('immediate constant (integer)',
9248c45a
JH
133 456,
134'SV = IV\\($ADDR\\) at $ADDR
135 REFCNT = 1
7766e686 136 FLAGS = \\(.*IOK,READONLY,pIOK\\)
9248c45a
JH
137 IV = 456');
138
06a5cade 139do_test('assignment of immediate constant (integer)',
9248c45a
JH
140 $c = 456,
141'SV = IV\\($ADDR\\) at $ADDR
142 REFCNT = 1
000fd473 143 FLAGS = \\($PADMY,IOK,pIOK\\)
9248c45a
JH
144 IV = 456');
145
59d8ce62
NC
146# If perl is built with PERL_PRESERVE_IVUV then maths is done as integers
147# where possible and this scalar will be an IV. If NO_PERL_PRESERVE_IVUV then
148# maths is done in floating point always, and this scalar will be an NV.
149# ([NI]) captures the type, referred to by \1 in this regexp and $type for
150# building subsequent regexps.
06a5cade 151my $type = do_test('result of addition',
9248c45a 152 $c + $d,
59d8ce62 153'SV = ([NI])V\\($ADDR\\) at $ADDR
9248c45a 154 REFCNT = 1
59d8ce62
NC
155 FLAGS = \\(PADTMP,\1OK,p\1OK\\)
156 \1V = 456');
9248c45a
JH
157
158($d = "789") += 0.1;
159
06a5cade 160do_test('floating point value',
9248c45a
JH
161 $d,
162'SV = PVNV\\($ADDR\\) at $ADDR
163 REFCNT = 1
164 FLAGS = \\(NOK,pNOK\\)
78d00c47 165 IV = \d+
ac634a9a 166 NV = 789\\.(?:1(?:000+\d+)?|0999+\d+)
9248c45a
JH
167 PV = $ADDR "789"\\\0
168 CUR = 3
1badabf5 169 LEN = \\d+');
9248c45a 170
06a5cade 171do_test('integer constant',
9248c45a
JH
172 0xabcd,
173'SV = IV\\($ADDR\\) at $ADDR
174 REFCNT = 1
28e5dec8
JH
175 FLAGS = \\(.*IOK,READONLY,pIOK\\)
176 IV = 43981');
9248c45a 177
06a5cade 178do_test('undef',
9248c45a
JH
179 undef,
180'SV = NULL\\(0x0\\) at $ADDR
181 REFCNT = 1
182 FLAGS = \\(\\)');
183
06a5cade 184do_test('reference to scalar',
9248c45a 185 \$a,
4df7f6af 186'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
187 REFCNT = 1
188 FLAGS = \\(ROK\\)
189 RV = $ADDR
190 SV = PV\\($ADDR\\) at $ADDR
191 REFCNT = 2
192 FLAGS = \\(POK,pPOK\\)
193 PV = $ADDR "foo"\\\0
194 CUR = 3
1badabf5 195 LEN = \\d+');
9248c45a 196
59d8ce62
NC
197my $c_pattern;
198if ($type eq 'N') {
199 $c_pattern = '
200 SV = PVNV\\($ADDR\\) at $ADDR
201 REFCNT = 1
202 FLAGS = \\(IOK,NOK,pIOK,pNOK\\)
203 IV = 456
204 NV = 456
205 PV = 0';
206} else {
207 $c_pattern = '
208 SV = IV\\($ADDR\\) at $ADDR
209 REFCNT = 1
210 FLAGS = \\(IOK,pIOK\\)
211 IV = 456';
212}
06a5cade 213do_test('reference to array',
9248c45a 214 [$b,$c],
4df7f6af 215'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
216 REFCNT = 1
217 FLAGS = \\(ROK\\)
218 RV = $ADDR
219 SV = PVAV\\($ADDR\\) at $ADDR
78c72037 220 REFCNT = 1
9248c45a 221 FLAGS = \\(\\)
1bcecb77
NC
222 IV = 0 # $] < 5.009
223 NV = 0 # $] < 5.009
9248c45a
JH
224 ARRAY = $ADDR
225 FILL = 1
226 MAX = 1
227 ARYLEN = 0x0
228 FLAGS = \\(REAL\\)
229 Elt No. 0
230 SV = IV\\($ADDR\\) at $ADDR
231 REFCNT = 1
232 FLAGS = \\(IOK,pIOK\\)
233 IV = 123
59d8ce62 234 Elt No. 1' . $c_pattern);
9248c45a 235
06a5cade 236do_test('reference to hash',
9248c45a 237 {$b=>$c},
4df7f6af 238'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
239 REFCNT = 1
240 FLAGS = \\(ROK\\)
241 RV = $ADDR
242 SV = PVHV\\($ADDR\\) at $ADDR
78c72037 243 REFCNT = 1
9248c45a 244 FLAGS = \\(SHAREKEYS\\)
1bcecb77
NC
245 IV = 1 # $] < 5.009
246 NV = $FLOAT # $] < 5.009
9248c45a 247 ARRAY = $ADDR \\(0:7, 1:1\\)
b8fa94d8 248 hash quality = 100.0%
9248c45a
JH
249 KEYS = 1
250 FILL = 1
251 MAX = 7
252 RITER = -1
253 EITER = 0x0
000fd473
NC
254 Elt "123" HASH = $ADDR' . $c_pattern,
255 '',
256 $] > 5.009 && 'The hash iterator used in dump.c sets the OOK flag');
9248c45a 257
06a5cade 258do_test('reference to anon sub with empty prototype',
9248c45a 259 sub(){@_},
4df7f6af 260'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
261 REFCNT = 1
262 FLAGS = \\(ROK\\)
263 RV = $ADDR
264 SV = PVCV\\($ADDR\\) at $ADDR
265 REFCNT = 2
cfc1e951 266 FLAGS = \\($PADMY,POK,pPOK,ANON,WEAKOUTSIDE,CVGV_RC\\)
1bcecb77
NC
267 IV = 0 # $] < 5.009
268 NV = 0 # $] < 5.009
9248c45a
JH
269 PROTOTYPE = ""
270 COMP_STASH = $ADDR\\t"main"
271 START = $ADDR ===> \\d+
272 ROOT = $ADDR
1bcecb77
NC
273 XSUB = 0x0 # $] < 5.009
274 XSUBANY = 0 # $] < 5.009
208edb77 275 GVGV::GV = $ADDR\\t"main" :: "__ANON__[^"]*"
084d946d 276 FILE = ".*\\b(?i:peek\\.t)"
000fd473
NC
277 DEPTH = 0(?:
278 MUTEXP = $ADDR
279 OWNER = $ADDR)?
1bcecb77 280 FLAGS = 0x404 # $] < 5.009
cfc1e951 281 FLAGS = 0x490 # $] >= 5.009
a3985cdc 282 OUTSIDE_SEQ = \\d+
9248c45a 283 PADLIST = $ADDR
dd2155a4 284 PADNAME = $ADDR\\($ADDR\\) PAD = $ADDR\\($ADDR\\)
9248c45a
JH
285 OUTSIDE = $ADDR \\(MAIN\\)');
286
06a5cade 287do_test('reference to named subroutine without prototype',
9248c45a 288 \&do_test,
4df7f6af 289'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
290 REFCNT = 1
291 FLAGS = \\(ROK\\)
292 RV = $ADDR
293 SV = PVCV\\($ADDR\\) at $ADDR
9856a127 294 REFCNT = (3|4)
9248c45a 295 FLAGS = \\(\\)
1bcecb77
NC
296 IV = 0 # $] < 5.009
297 NV = 0 # $] < 5.009
9248c45a
JH
298 COMP_STASH = $ADDR\\t"main"
299 START = $ADDR ===> \\d+
300 ROOT = $ADDR
1bcecb77
NC
301 XSUB = 0x0 # $] < 5.009
302 XSUBANY = 0 # $] < 5.009
9248c45a 303 GVGV::GV = $ADDR\\t"main" :: "do_test"
084d946d 304 FILE = ".*\\b(?i:peek\\.t)"
9248c45a 305 DEPTH = 1
9856a127 306(?: MUTEXP = $ADDR
208edb77
MG
307 OWNER = $ADDR
308)? FLAGS = 0x0
a3985cdc 309 OUTSIDE_SEQ = \\d+
9248c45a 310 PADLIST = $ADDR
dd2155a4 311 PADNAME = $ADDR\\($ADDR\\) PAD = $ADDR\\($ADDR\\)
000fd473
NC
312 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$todo"
313 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$repeat_todo"
ee6cee0c 314 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$pattern"
c2485e0c 315 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$version_condition"
000fd473
NC
316 \\d+\\. $ADDR<\\d+> FAKE "\\$DEBUG" # $] < 5.009
317 \\d+\\. $ADDR<\\d+> FAKE "\\$DEBUG" flags=0x0 index=0 # $] >= 5.009
ee6cee0c 318 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$dump"
e9569a7a 319 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$dump2"
9248c45a
JH
320 OUTSIDE = $ADDR \\(MAIN\\)');
321
3ce3ed55 322if ($] >= 5.011) {
06a5cade 323do_test('reference to regexp',
3ce3ed55
NC
324 qr(tic),
325'SV = $RV\\($ADDR\\) at $ADDR
326 REFCNT = 1
327 FLAGS = \\(ROK\\)
328 RV = $ADDR
5c35adbb 329 SV = REGEXP\\($ADDR\\) at $ADDR
c2123ae3 330 REFCNT = 1
b9ad13ac 331 FLAGS = \\(OBJECT,POK,FAKE,pPOK\\)
fb85c044
KW
332 PV = $ADDR "\\(\\?\\^:tic\\)"
333 CUR = 8
c2123ae3 334 LEN = 0
0fc92fc6 335 STASH = $ADDR\\t"Regexp"');
3ce3ed55 336} else {
06a5cade 337do_test('reference to regexp',
9248c45a 338 qr(tic),
4df7f6af 339'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
340 REFCNT = 1
341 FLAGS = \\(ROK\\)
342 RV = $ADDR
343 SV = PVMG\\($ADDR\\) at $ADDR
344 REFCNT = 1
faf82a0b 345 FLAGS = \\(OBJECT,SMG\\)
9248c45a
JH
346 IV = 0
347 NV = 0
348 PV = 0
349 MAGIC = $ADDR
350 MG_VIRTUAL = $ADDR
14befaf4 351 MG_TYPE = PERL_MAGIC_qr\(r\)
9248c45a 352 MG_OBJ = $ADDR
fb85c044 353 PAT = "\(\?^:tic\)" # $] >= 5.009
1bcecb77 354 REFCNT = 2 # $] >= 5.009
9248c45a 355 STASH = $ADDR\\t"Regexp"');
3ce3ed55 356}
9248c45a 357
06a5cade 358do_test('reference to blessed hash',
9248c45a 359 (bless {}, "Tac"),
4df7f6af 360'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
361 REFCNT = 1
362 FLAGS = \\(ROK\\)
363 RV = $ADDR
364 SV = PVHV\\($ADDR\\) at $ADDR
78c72037 365 REFCNT = 1
9248c45a 366 FLAGS = \\(OBJECT,SHAREKEYS\\)
1bcecb77
NC
367 IV = 0 # $] < 5.009
368 NV = 0 # $] < 5.009
9248c45a
JH
369 STASH = $ADDR\\t"Tac"
370 ARRAY = 0x0
371 KEYS = 0
372 FILL = 0
373 MAX = 7
374 RITER = -1
000fd473
NC
375 EITER = 0x0', '',
376 $] > 5.009 ? 'The hash iterator used in dump.c sets the OOK flag'
377 : "Something causes the HV's array to become allocated");
9248c45a 378
06a5cade 379do_test('typeglob',
9248c45a
JH
380 *a,
381'SV = PVGV\\($ADDR\\) at $ADDR
382 REFCNT = 5
000fd473
NC
383 FLAGS = \\(MULTI(?:,IN_PAD)?\\) # $] >= 5.009
384 FLAGS = \\(GMG,SMG,MULTI(?:,IN_PAD)?\\) # $] < 5.009
385 IV = 0 # $] < 5.009
386 NV = 0 # $] < 5.009
387 PV = 0 # $] < 5.009
388 MAGIC = $ADDR # $] < 5.009
389 MG_VIRTUAL = &PL_vtbl_glob # $] < 5.009
390 MG_TYPE = PERL_MAGIC_glob\(\*\) # $] < 5.009
391 MG_OBJ = $ADDR # $] < 5.009
9248c45a
JH
392 NAME = "a"
393 NAMELEN = 1
394 GvSTASH = $ADDR\\t"main"
395 GP = $ADDR
396 SV = $ADDR
397 REFCNT = 1
398 IO = 0x0
399 FORM = 0x0
400 AV = 0x0
401 HV = 0x0
402 CV = 0x0
403 CVGEN = 0x0
000fd473 404 GPFLAGS = 0x0 # $] < 5.009
9ec58fb7 405 LINE = \\d+
084d946d 406 FILE = ".*\\b(?i:peek\\.t)"
e39917cc 407 FLAGS = $ADDR
9248c45a
JH
408 EGV = $ADDR\\t"a"');
409
cdb2dd7b 410if (ord('A') == 193) {
06a5cade 411do_test('string with Unicode',
cdb2dd7b
JH
412 chr(256).chr(0).chr(512),
413'SV = PV\\($ADDR\\) at $ADDR
414 REFCNT = 1
000fd473 415 FLAGS = \\((?:$PADTMP,)?POK,READONLY,pPOK,UTF8\\)
cdb2dd7b
JH
416 PV = $ADDR "\\\214\\\101\\\0\\\235\\\101"\\\0 \[UTF8 "\\\x\{100\}\\\x\{0\}\\\x\{200\}"\]
417 CUR = 5
1badabf5 418 LEN = \\d+');
cdb2dd7b 419} else {
06a5cade 420do_test('string with Unicode',
e6abe6d8
JH
421 chr(256).chr(0).chr(512),
422'SV = PV\\($ADDR\\) at $ADDR
423 REFCNT = 1
000fd473 424 FLAGS = \\((?:$PADTMP,)?POK,READONLY,pPOK,UTF8\\)
98c991d1 425 PV = $ADDR "\\\304\\\200\\\0\\\310\\\200"\\\0 \[UTF8 "\\\x\{100\}\\\x\{0\}\\\x\{200\}"\]
e6abe6d8 426 CUR = 5
1badabf5 427 LEN = \\d+');
cdb2dd7b 428}
e6abe6d8 429
cdb2dd7b 430if (ord('A') == 193) {
06a5cade 431do_test('reference to hash containing Unicode',
cdb2dd7b 432 {chr(256)=>chr(512)},
4df7f6af 433'SV = $RV\\($ADDR\\) at $ADDR
cdb2dd7b
JH
434 REFCNT = 1
435 FLAGS = \\(ROK\\)
436 RV = $ADDR
437 SV = PVHV\\($ADDR\\) at $ADDR
78c72037 438 REFCNT = 1
b2caaddd 439 FLAGS = \\(SHAREKEYS,HASKFLAGS\\)
1bcecb77
NC
440 UV = 1 # $] < 5.009
441 NV = $FLOAT # $] < 5.009
cdb2dd7b
JH
442 ARRAY = $ADDR \\(0:7, 1:1\\)
443 hash quality = 100.0%
444 KEYS = 1
445 FILL = 1
446 MAX = 7
447 RITER = -1
448 EITER = $ADDR
6cbfa5b4 449 Elt "\\\214\\\101" \[UTF8 "\\\x\{100\}"\] HASH = $ADDR
cdb2dd7b
JH
450 SV = PV\\($ADDR\\) at $ADDR
451 REFCNT = 1
452 FLAGS = \\(POK,pPOK,UTF8\\)
453 PV = $ADDR "\\\235\\\101"\\\0 \[UTF8 "\\\x\{200\}"\]
454 CUR = 2
000fd473
NC
455 LEN = \\d+',
456 $] > 5.009 ? 'The hash iterator used in dump.c sets the OOK flag'
457 : 'sv_length has been called on the element, and cached the result in MAGIC');
cdb2dd7b 458} else {
06a5cade 459do_test('reference to hash containing Unicode',
98c991d1 460 {chr(256)=>chr(512)},
4df7f6af 461'SV = $RV\\($ADDR\\) at $ADDR
98c991d1
JH
462 REFCNT = 1
463 FLAGS = \\(ROK\\)
464 RV = $ADDR
465 SV = PVHV\\($ADDR\\) at $ADDR
78c72037 466 REFCNT = 1
19692e8d 467 FLAGS = \\(SHAREKEYS,HASKFLAGS\\)
1bcecb77
NC
468 UV = 1 # $] < 5.009
469 NV = 0 # $] < 5.009
98c991d1
JH
470 ARRAY = $ADDR \\(0:7, 1:1\\)
471 hash quality = 100.0%
472 KEYS = 1
473 FILL = 1
474 MAX = 7
475 RITER = -1
476 EITER = $ADDR
477 Elt "\\\304\\\200" \[UTF8 "\\\x\{100\}"\] HASH = $ADDR
478 SV = PV\\($ADDR\\) at $ADDR
479 REFCNT = 1
480 FLAGS = \\(POK,pPOK,UTF8\\)
481 PV = $ADDR "\\\310\\\200"\\\0 \[UTF8 "\\\x\{200\}"\]
482 CUR = 2
000fd473
NC
483 LEN = \\d+', '',
484 $] > 5.009 ? 'The hash iterator used in dump.c sets the OOK flag'
485 : 'sv_length has been called on the element, and cached the result in MAGIC');
cdb2dd7b 486}
98c991d1 487
99331854
YST
488my $x="";
489$x=~/.??/g;
06a5cade 490do_test('scalar with pos magic',
99331854
YST
491 $x,
492'SV = PVMG\\($ADDR\\) at $ADDR
493 REFCNT = 1
000fd473 494 FLAGS = \\($PADMY,SMG,POK,pPOK\\)
99331854
YST
495 IV = 0
496 NV = 0
497 PV = $ADDR ""\\\0
498 CUR = 0
1936d2a7 499 LEN = \d+
99331854
YST
500 MAGIC = $ADDR
501 MG_VIRTUAL = &PL_vtbl_mglob
502 MG_TYPE = PERL_MAGIC_regex_global\\(g\\)
503 MG_FLAGS = 0x01
504 MINMATCH');
505
f24fdb76
HS
506#
507# TAINTEDDIR is not set on: OS2, AMIGAOS, WIN32, MSDOS
508# environment variables may be invisibly case-forced, hence the (?i:PATH)
5e836f43 509# C<scalar(@ARGV)> is turned into an IV on VMS hence the (?:IV)?
d9baf692
JM
510# VMS is setting FAKE and READONLY flags. What VMS uses for storing
511# ENV hashes is also not always null terminated.
f24fdb76 512#
06a5cade 513do_test('tainted value in %ENV',
99331854
YST
514 $ENV{PATH}=@ARGV, # scalar(@ARGV) is a handy known tainted value
515'SV = PVMG\\($ADDR\\) at $ADDR
516 REFCNT = 1
517 FLAGS = \\(GMG,SMG,RMG,pIOK,pPOK\\)
518 IV = 0
519 NV = 0
520 PV = $ADDR "0"\\\0
521 CUR = 1
522 LEN = \d+
523 MAGIC = $ADDR
524 MG_VIRTUAL = &PL_vtbl_envelem
525 MG_TYPE = PERL_MAGIC_envelem\\(e\\)
d25a523c 526(?: MG_FLAGS = 0x01
99331854 527 TAINTEDDIR
143a3e5e
CB
528)? MG_LEN = -?\d+
529 MG_PTR = $ADDR (?:"(?i:PATH)"|=> HEf_SVKEY
5e836f43 530 SV = PV(?:IV)?\\($ADDR\\) at $ADDR
143a3e5e 531 REFCNT = \d+
11e2783c 532 FLAGS = \\(TEMP,POK,(?:FAKE,READONLY,)?pPOK\\)
f0fabfd7 533(?: IV = 0
d9baf692 534)? PV = $ADDR "(?i:PATH)"(?:\\\0)?
143a3e5e
CB
535 CUR = \d+
536 LEN = \d+)
99331854
YST
537 MAGIC = $ADDR
538 MG_VIRTUAL = &PL_vtbl_taint
539 MG_TYPE = PERL_MAGIC_taint\\(t\\)');
540
06a5cade 541do_test('blessed reference',
6bf47b08 542 bless(\\undef, 'Foobar'),
4df7f6af 543'SV = $RV\\($ADDR\\) at $ADDR
6bf47b08
SR
544 REFCNT = 1
545 FLAGS = \\(ROK\\)
546 RV = $ADDR
547 SV = PVMG\\($ADDR\\) at $ADDR
548 REFCNT = 2
549 FLAGS = \\(OBJECT,ROK\\)
7957ad98
MB
550 IV = -?\d+
551 NV = $FLOAT
6bf47b08
SR
552 RV = $ADDR
553 SV = NULL\\(0x0\\) at $ADDR
554 REFCNT = \d+
555 FLAGS = \\(READONLY\\)
556 PV = $ADDR ""
557 CUR = 0
558 LEN = 0
559 STASH = $ADDR\s+"Foobar"');
b1886099 560
b1886099
NC
561sub const () {
562 "Perl rules";
563}
564
06a5cade 565do_test('constant subroutine',
b1886099 566 \&const,
4df7f6af 567'SV = $RV\\($ADDR\\) at $ADDR
b1886099
NC
568 REFCNT = 1
569 FLAGS = \\(ROK\\)
570 RV = $ADDR
571 SV = PVCV\\($ADDR\\) at $ADDR
572 REFCNT = (2)
31d45e0c 573 FLAGS = \\(POK,pPOK,CONST,ISXSUB\\)
1bcecb77
NC
574 IV = 0 # $] < 5.009
575 NV = 0 # $] < 5.009
b1886099
NC
576 PROTOTYPE = ""
577 COMP_STASH = 0x0
1bcecb77 578 ROOT = 0x0 # $] < 5.009
b1886099
NC
579 XSUB = $ADDR
580 XSUBANY = $ADDR \\(CONST SV\\)
581 SV = PV\\($ADDR\\) at $ADDR
582 REFCNT = 1
583 FLAGS = \\(.*POK,READONLY,pPOK\\)
584 PV = $ADDR "Perl rules"\\\0
585 CUR = 10
586 LEN = \\d+
587 GVGV::GV = $ADDR\\t"main" :: "const"
588 FILE = ".*\\b(?i:peek\\.t)"
000fd473
NC
589 DEPTH = 0(?:
590 MUTEXP = $ADDR
591 OWNER = $ADDR)?
1bcecb77 592 FLAGS = 0x200 # $] < 5.009
c2485e0c
NC
593 FLAGS = 0xc00 # $] >= 5.009 && $] < 5.013
594 FLAGS = 0xc # $] >= 5.013
b1886099
NC
595 OUTSIDE_SEQ = 0
596 PADLIST = 0x0
597 OUTSIDE = 0x0 \\(null\\)');
2e94196c 598
06a5cade 599do_test('isUV should show on PVMG',
2e94196c
NC
600 do { my $v = $1; $v = ~0; $v },
601'SV = PVMG\\($ADDR\\) at $ADDR
602 REFCNT = 1
603 FLAGS = \\(IOK,pIOK,IsUV\\)
604 UV = \d+
605 NV = 0
606 PV = 0');
c0a413d1 607
06a5cade 608do_test('IO',
c0a413d1
NC
609 *STDOUT{IO},
610'SV = $RV\\($ADDR\\) at $ADDR
611 REFCNT = 1
612 FLAGS = \\(ROK\\)
613 RV = $ADDR
614 SV = PVIO\\($ADDR\\) at $ADDR
615 REFCNT = 3
616 FLAGS = \\(OBJECT\\)
3cf51070 617 IV = 0 # $] < 5.011
1bcecb77 618 NV = 0 # $] < 5.011
d963bf01 619 STASH = $ADDR\s+"IO::File"
c0a413d1
NC
620 IFP = $ADDR
621 OFP = $ADDR
622 DIRP = 0x0
623 LINES = 0
624 PAGE = 0
625 PAGE_LEN = 60
626 LINES_LEFT = 0
627 TOP_GV = 0x0
628 FMT_GV = 0x0
629 BOTTOM_GV = 0x0
1bcecb77 630 SUBPROCESS = 0 # $] < 5.009
c0a413d1 631 TYPE = \'>\'
50a9fad1 632 FLAGS = 0x4');
bfe27a58 633
06a5cade 634do_test('FORMAT',
bfe27a58
NC
635 *PIE{FORMAT},
636'SV = $RV\\($ADDR\\) at $ADDR
637 REFCNT = 1
638 FLAGS = \\(ROK\\)
639 RV = $ADDR
640 SV = PVFM\\($ADDR\\) at $ADDR
641 REFCNT = 2
642 FLAGS = \\(\\)
30ec677d 643 IV = 0 # $] < 5.009
bfe27a58 644 NV = 0 # $] < 5.009
251a4af1
DM
645(?: PV = 0
646)? COMP_STASH = 0x0
bfe27a58
NC
647 START = $ADDR ===> \\d+
648 ROOT = $ADDR
649 XSUB = 0x0 # $] < 5.009
650 XSUBANY = 0 # $] < 5.009
651 GVGV::GV = $ADDR\\t"main" :: "PIE"
652 FILE = ".*\\b(?i:peek\\.t)"
c12100a4
DM
653(?: DEPTH = 0
654 MUTEXP = $ADDR
bfe27a58
NC
655 OWNER = $ADDR
656)? FLAGS = 0x0
657 OUTSIDE_SEQ = \\d+
658 LINES = 0
659 PADLIST = $ADDR
660 PADNAME = $ADDR\\($ADDR\\) PAD = $ADDR\\($ADDR\\)
661 OUTSIDE = $ADDR \\(MAIN\\)');
d7d51f4b 662
b7b1e41b 663do_test('blessing to a class with embedded NUL characters',
d7d51f4b
YO
664 (bless {}, "\0::foo::\n::baz::\t::\0"),
665'SV = $RV\\($ADDR\\) at $ADDR
666 REFCNT = 1
667 FLAGS = \\(ROK\\)
668 RV = $ADDR
669 SV = PVHV\\($ADDR\\) at $ADDR
670 REFCNT = 1
671 FLAGS = \\(OBJECT,SHAREKEYS\\)
672 IV = 0 # $] < 5.009
673 NV = 0 # $] < 5.009
674 STASH = $ADDR\\t"\\\\0::foo::\\\\n::baz::\\\\t::\\\\0"
675 ARRAY = $ADDR
676 KEYS = 0
677 FILL = 0
678 MAX = 7
679 RITER = -1
680 EITER = 0x0', '',
681 $] > 5.009 ? 'The hash iterator used in dump.c sets the OOK flag'
682 : "Something causes the HV's array to become allocated");
683
bed53064
NC
684do_test('ENAME on a stash',
685 \%RWOM::,
686'SV = $RV\\($ADDR\\) at $ADDR
687 REFCNT = 1
688 FLAGS = \\(ROK\\)
689 RV = $ADDR
690 SV = PVHV\\($ADDR\\) at $ADDR
691 REFCNT = 2
692 FLAGS = \\(OOK,SHAREKEYS\\)
693 IV = 1 # $] < 5.009
694 NV = $FLOAT # $] < 5.009
695 ARRAY = $ADDR
696 KEYS = 0
697 FILL = 0
698 MAX = 7
699 RITER = -1
700 EITER = 0x0
701 NAME = "RWOM"
702 ENAME = "RWOM" # $] > 5.012
703');
704
705*KLANK:: = \%RWOM::;
706
707do_test('ENAMEs on a stash',
708 \%RWOM::,
709'SV = $RV\\($ADDR\\) at $ADDR
710 REFCNT = 1
711 FLAGS = \\(ROK\\)
712 RV = $ADDR
713 SV = PVHV\\($ADDR\\) at $ADDR
714 REFCNT = 3
715 FLAGS = \\(OOK,SHAREKEYS\\)
716 IV = 1 # $] < 5.009
717 NV = $FLOAT # $] < 5.009
718 ARRAY = $ADDR
719 KEYS = 0
720 FILL = 0
721 MAX = 7
722 RITER = -1
723 EITER = 0x0
724 NAME = "RWOM"
725 NAMECOUNT = 2 # $] > 5.012
726 ENAME = "RWOM", "KLANK" # $] > 5.012
727');
728
729undef %RWOM::;
730
731do_test('ENAMEs on a stash with no NAME',
732 \%RWOM::,
733'SV = $RV\\($ADDR\\) at $ADDR
734 REFCNT = 1
735 FLAGS = \\(ROK\\)
736 RV = $ADDR
737 SV = PVHV\\($ADDR\\) at $ADDR
738 REFCNT = 3
739 FLAGS = \\(OOK,SHAREKEYS\\)
740 IV = 1 # $] < 5.009
741 NV = $FLOAT # $] < 5.009
742 ARRAY = $ADDR
743 KEYS = 0
744 FILL = 0
745 MAX = 7
746 RITER = -1
747 EITER = 0x0
748 NAMECOUNT = -3 # $] > 5.012
749 ENAME = "RWOM", "KLANK" # $] > 5.012
750');
751
06a5cade 752done_testing();