This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
RT#132347: fix building Tk
[perl5.git] / ext / B / t / b.t
CommitLineData
ccc418af
GS
1#!./perl
2
3BEGIN {
74517a3a 4 unshift @INC, 't';
9cd8f857
NC
5 require Config;
6 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
7 print "1..0 # Skip -- Perl configured without B module\n";
8 exit 0;
9 }
ccc418af
GS
10}
11
12$| = 1;
13use warnings;
14use strict;
200b5b4b
DD
15BEGIN {
16 eval { require threads; threads->import; }
17}
f9a20969 18use Test::More;
ccc418af 19
c5f0f3aa 20BEGIN { use_ok( 'B' ); }
ccc418af 21
08c6f5ec 22
87a42246
MS
23package Testing::Symtable;
24use vars qw($This @That %wibble $moo %moo);
25my $not_a_sym = 'moo';
ccc418af 26
87a42246
MS
27sub moo { 42 }
28sub car { 23 }
ccc418af 29
f70490b9 30
87a42246
MS
31package Testing::Symtable::Foo;
32sub yarrow { "Hock" }
f70490b9 33
87a42246
MS
34package Testing::Symtable::Bar;
35sub hock { "yarrow" }
9b86dfa2 36
87a42246
MS
37package main;
38use vars qw(%Subs);
39local %Subs = ();
40B::walksymtable(\%Testing::Symtable::, 'find_syms', sub { $_[0] =~ /Foo/ },
41 'Testing::Symtable::');
ccc418af 42
87a42246
MS
43sub B::GV::find_syms {
44 my($symbol) = @_;
de3f1649 45
87a42246 46 $main::Subs{$symbol->STASH->NAME . '::' . $symbol->NAME}++;
cfe9256d 47}
ccc418af 48
87a42246
MS
49my @syms = map { 'Testing::Symtable::'.$_ } qw(This That wibble moo car
50 BEGIN);
51push @syms, "Testing::Symtable::Foo::yarrow";
ccc418af 52
87a42246 53# Make sure we hit all the expected symbols.
c5f0f3aa 54ok( join('', sort @syms) eq join('', sort keys %Subs), 'all symbols found' );
1e1dbab6 55
87a42246 56# Make sure we only hit them each once.
c5f0f3aa
RGS
57ok( (!grep $_ != 1, values %Subs), '...and found once' );
58
59# Tests for MAGIC / MOREMAGIC
60ok( B::svref_2object(\$.)->MAGIC->TYPE eq "\0", '$. has \0 magic' );
61{
62 my $e = '';
63 local $SIG{__DIE__} = sub { $e = $_[0] };
64 # Used to dump core, bug #16828
65 eval { B::svref_2object(\$.)->MAGIC->MOREMAGIC->TYPE; };
66 like( $e, qr/Can't call method "TYPE" on an undefined value/,
67 '$. has no more magic' );
68}
01b509b0 69
de64752d
NC
70{
71 my $pie = 'Good';
72 # This needs to be a package variable, as vars in the pad have some flags.
73 my $r = B::svref_2object(\$::data2);
74 is($r->FLAGS(), 0, "uninitialised package variable has flags of 0");
75 is($r->SvTYPE(), 0, "uninitialised package variable has type 0");
76 is($r->POK(), 0, "POK false");
77 is($r->ROK(), 0, "ROK false");
78 is($r->MAGICAL(), 0, "MAGICAL false");
79 $::data2 = $pie;
80 isnt($r->FLAGS(), 0, "initialised package variable has nonzero flags");
81 isnt($r->SvTYPE(), 0, "initialised package variable has nonzero type");
82 isnt($r->POK(), 0, "POK true");
83 is($r->ROK(), 0, "ROK false");
84 is($r->MAGICAL(), 0, "MAGICAL false");
85
86 $::data2 = substr $pie, 0, 1;
87 isnt($r->FLAGS(), 0, "initialised package variable has nonzero flags");
88 isnt($r->SvTYPE(), 0, "initialised package variable has nonzero type");
89 isnt($r->POK(), 0, "POK true");
90 is($r->ROK(), 0, "ROK false");
91 is($r->MAGICAL(), 0, "MAGICAL true");
92
93 $::data2 = \$pie;
94 isnt($r->FLAGS(), 0, "initialised package variable has nonzero flags");
95 isnt($r->SvTYPE(), 0, "initialised package variable has nonzero type");
96 is($r->POK(), 0, "POK false");
97 isnt($r->ROK(), 0, "ROK true");
98 is($r->MAGICAL(), 0, "MAGICAL false");
99
100 is($r->REFCNT(), 1, "Reference count is 1");
101 {
102 my $ref = \$::data2;
103 is($r->REFCNT(), 2, "Second reference");
104 }
105 is($r->REFCNT(), 1, "Reference count is 1");
106
107}
108
5c35adbb
NC
109my $r = qr/foo/;
110my $obj = B::svref_2object($r);
111my $regexp = ($] < 5.011) ? $obj->MAGIC : $obj;
112ok($regexp->precomp() eq 'foo', 'Get string from qr//');
113like($regexp->REGEX(), qr/\d+/, "REGEX() returns numeric value");
1f306347 114like($regexp->compflags, qr/^\d+\z/, "compflags returns numeric value");
4a31a506
FC
115is B::svref_2object(qr/(?{time})/)->qr_anoncv->ROOT->first->name, 'qr',
116 'qr_anoncv';
01b509b0
SP
117my $iv = 1;
118my $iv_ref = B::svref_2object(\$iv);
119is(ref $iv_ref, "B::IV", "Test B:IV return from svref_2object");
120is($iv_ref->REFCNT, 1, "Test B::IV->REFCNT");
121# Flag tests are needed still
122#diag $iv_ref->FLAGS();
123my $iv_ret = $iv_ref->object_2svref();
124is(ref $iv_ret, "SCALAR", "Test object_2svref() return is SCALAR");
125is($$iv_ret, $iv, "Test object_2svref()");
126is($iv_ref->int_value, $iv, "Test int_value()");
127is($iv_ref->IV, $iv, "Test IV()");
128is($iv_ref->IVX(), $iv, "Test IVX()");
129is($iv_ref->UVX(), $iv, "Test UVX()");
f046b1bd
NC
130is(eval { $iv_ref->RV() }, undef, 'Test RV() on IV');
131like($@, qr/argument is not SvROK/, 'Test RV() IV');
132$iv = \"Pie";
133my $val = eval { $iv_ref->RV() };
134is(ref $val, 'B::PV', 'Test RV() on a reference');
135is($val->PV(), 'Pie', 'Value expected');
136is($@, '', "Test RV()");
01b509b0
SP
137
138my $pv = "Foo";
139my $pv_ref = B::svref_2object(\$pv);
140is(ref $pv_ref, "B::PV", "Test B::PV return from svref_2object");
141is($pv_ref->REFCNT, 1, "Test B::PV->REFCNT");
142# Flag tests are needed still
143#diag $pv_ref->FLAGS();
144my $pv_ret = $pv_ref->object_2svref();
145is(ref $pv_ret, "SCALAR", "Test object_2svref() return is SCALAR");
146is($$pv_ret, $pv, "Test object_2svref()");
147is($pv_ref->PV(), $pv, "Test PV()");
f046b1bd
NC
148is(eval { $pv_ref->RV() }, undef, 'Test RV() on PV');
149like($@, qr/argument is not SvROK/, 'Test RV() on PV');
01b509b0 150is($pv_ref->PVX(), $pv, "Test PVX()");
f046b1bd
NC
151$pv = \"Pie";
152$val = eval { $pv_ref->RV() };
153is(ref $val, 'B::PV', 'Test RV() on a reference');
154is($val->PV(), 'Pie', 'Value expected');
155is($@, '', "Test RV()");
01b509b0
SP
156
157my $nv = 1.1;
158my $nv_ref = B::svref_2object(\$nv);
159is(ref $nv_ref, "B::NV", "Test B::NV return from svref_2object");
160is($nv_ref->REFCNT, 1, "Test B::NV->REFCNT");
161# Flag tests are needed still
162#diag $nv_ref->FLAGS();
163my $nv_ret = $nv_ref->object_2svref();
164is(ref $nv_ret, "SCALAR", "Test object_2svref() return is SCALAR");
165is($$nv_ret, $nv, "Test object_2svref()");
166is($nv_ref->NV, $nv, "Test NV()");
167is($nv_ref->NVX(), $nv, "Test NVX()");
f046b1bd
NC
168is(eval { $nv_ref->RV() }, undef, 'Test RV() on NV');
169like($@, qr/Can't locate object method "RV" via package "B::NV"/,
170 'Test RV() on NV');
01b509b0
SP
171
172my $null = undef;
173my $null_ref = B::svref_2object(\$null);
174is(ref $null_ref, "B::NULL", "Test B::NULL return from svref_2object");
175is($null_ref->REFCNT, 1, "Test B::NULL->REFCNT");
176# Flag tests are needed still
177#diag $null_ref->FLAGS();
178my $null_ret = $nv_ref->object_2svref();
179is(ref $null_ret, "SCALAR", "Test object_2svref() return is SCALAR");
180is($$null_ret, $nv, "Test object_2svref()");
181
4df7f6af 182my $RV_class = $] >= 5.011 ? 'B::IV' : 'B::RV';
01b509b0
SP
183my $cv = sub{ 1; };
184my $cv_ref = B::svref_2object(\$cv);
4df7f6af
NC
185is($cv_ref->REFCNT, 1, "Test $RV_class->REFCNT");
186is(ref $cv_ref, "$RV_class",
187 "Test $RV_class return from svref_2object - code");
01b509b0
SP
188my $cv_ret = $cv_ref->object_2svref();
189is(ref $cv_ret, "REF", "Test object_2svref() return is REF");
190is($$cv_ret, $cv, "Test object_2svref()");
191
192my $av = [];
193my $av_ref = B::svref_2object(\$av);
4df7f6af
NC
194is(ref $av_ref, "$RV_class",
195 "Test $RV_class return from svref_2object - array");
01b509b0
SP
196
197my $hv = [];
198my $hv_ref = B::svref_2object(\$hv);
4df7f6af
NC
199is(ref $hv_ref, "$RV_class",
200 "Test $RV_class return from svref_2object - hash");
01b509b0
SP
201
202local *gv = *STDOUT;
203my $gv_ref = B::svref_2object(\*gv);
204is(ref $gv_ref, "B::GV", "Test B::GV return from svref_2object");
205ok(! $gv_ref->is_empty(), "Test is_empty()");
711fbbf0 206ok($gv_ref->isGV_with_GP(), "Test isGV_with_GP()");
01b509b0
SP
207is($gv_ref->NAME(), "gv", "Test NAME()");
208is($gv_ref->SAFENAME(), "gv", "Test SAFENAME()");
209like($gv_ref->FILE(), qr/b\.t$/, "Testing FILE()");
de64752d
NC
210is($gv_ref->SvTYPE(), B::SVt_PVGV, "Test SvTYPE()");
211is($gv_ref->FLAGS() & B::SVTYPEMASK, B::SVt_PVGV, "Test SVTYPEMASK");
2da668d2
SP
212
213# The following return B::SPECIALs.
214is(ref B::sv_yes(), "B::SPECIAL", "B::sv_yes()");
215is(ref B::sv_no(), "B::SPECIAL", "B::sv_no()");
216is(ref B::sv_undef(), "B::SPECIAL", "B::sv_undef()");
a462fa00
DD
217SKIP: {
218 skip('no fork', 1)
219 unless ($Config::Config{d_fork} or $Config::Config{d_pseudofork});
220 my $pid;
bdbabc4e 221 pipe my $r, my $w or die "Can't pipe: $!";;
a462fa00 222 if ($pid = fork) {
bdbabc4e
JK
223 close $w;
224 my $type = <$r>;
225 close $r;
a462fa00 226 waitpid($pid,0);
0d16269d 227 is($type, "B::SPECIAL", "special SV table works after pseudofork");
a462fa00
DD
228 }
229 else {
bdbabc4e
JK
230 close $r;
231 $|++;
232 print $w ref B::svref_2object(\(!!0));
233 close $w;
a462fa00
DD
234 exit;
235 }
236}
2da668d2
SP
237
238# More utility functions
239is(B::ppname(0), "pp_null", "Testing ppname (this might break if opnames.h is changed)");
240is(B::opnumber("null"), 0, "Testing opnumber with opname (null)");
241is(B::opnumber("pp_null"), 0, "Testing opnumber with opname (pp_null)");
b45732d6
NC
242{
243 my $hash = B::hash("wibble");
244 like($hash, qr/\A0x[0-9a-f]+\z/, "Testing B::hash(\"wibble\")");
245 unlike($hash, qr/\A0x0+\z/, "Testing B::hash(\"wibble\")");
246
bb1ca2d4
YO
247 SKIP: {
248 skip "Nulls don't hash to the same bucket regardless of length with this PERL_HASH implementation", 20
249 if B::hash("") ne B::hash("\0" x 19);
250 like(B::hash("\0" x $_), qr/\A0x0+\z/, "Testing B::hash(\"0\" x $_)")
251 for 0..19;
252 }
8c5b7c71
NC
253
254 $hash = eval {B::hash(chr 256)};
255 is($hash, undef, "B::hash() refuses non-octets");
256 like($@, qr/^Wide character in subroutine entry/);
257
258 $hash = B::hash(chr 163);
259 my $str = chr(163) . chr 256;
260 chop $str;
261 is(B::hash($str), $hash, 'B::hash() with chr 128-256 is well-behaved');
b45732d6 262}
f9a20969
NC
263{
264 is(B::cstring(undef), '0', "Testing B::cstring(undef)");
265 is(B::perlstring(undef), '0', "Testing B::perlstring(undef)");
266
267 my @common = map {eval $_, $_}
574fde55
NC
268 '"wibble"', '"\""', '"\'"', '"\\\\"', '"\\n\\r\\t\\b\\a\\f"', '"\000"',
269 '"\000\000"', '"\000Bing\000"', ord 'N' == 78 ? '"\\177"' : ();
f9a20969
NC
270
271 my $oct = sprintf "\\%03o", ord '?';
272 my @tests = (@common, '$_', '"$_"', '@_', '"@_"', '??N', qq{"$oct?N"},
273 ord 'N' == 78 ? (chr 11, '"\v"'): ());
274 while (my ($test, $expect) = splice @tests, 0, 2) {
275 is(B::cstring($test), $expect, "B::cstring($expect)");
276 }
277
278 @tests = (@common, '$_', '"\$_"', '@_', '"\@_"', '??N', '"??N"',
279 chr 256, '"\x{100}"', chr 65536, '"\x{10000}"',
280 ord 'N' == 78 ? (chr 11, '"\013"'): ());
281 while (my ($test, $expect) = splice @tests, 0, 2) {
282 is(B::perlstring($test), $expect, "B::perlstring($expect)");
283 utf8::upgrade $test;
4215ab17 284 $expect =~ s/\\b/sprintf("\\x{%x}", utf8::unicode_to_native(8))/eg;
f9a20969
NC
285 $expect =~ s/\\([0-7]{3})/sprintf "\\x\{%x\}", oct $1/eg;
286 is(B::perlstring($test), $expect, "B::perlstring($expect) (Unicode)");
287 }
288}
01c3a485 289{
574fde55
NC
290 my @tests = ((map {eval(qq{"$_"}), $_} '\\n', '\\r', '\\t',
291 '\\b', '\\a', '\\f', '\\000', '\\\'', '?'), '"', '"',
292 ord 'N' == 78 ? (chr 11, '\v', "\177", '\\177') : ());
01c3a485
NC
293
294 while (my ($test, $expect) = splice @tests, 0, 2) {
295 is(B::cchar($test), "'${expect}'", "B::cchar(qq{$expect})");
296 }
297}
298
2da668d2
SP
299is(B::class(bless {}, "Wibble::Bibble"), "Bibble", "Testing B::class()");
300is(B::cast_I32(3.14), 3, "Testing B::cast_I32()");
5012eebe 301is(B::opnumber("chop"), 38, "Testing opnumber with opname (chop)");
5ce57cc0
JJ
302
303{
304 no warnings 'once';
305 my $sg = B::sub_generation();
e1a479c5 306 *UNIVERSAL::hand_waving = sub { };
5ce57cc0
JJ
307 ok( $sg < B::sub_generation, "sub_generation increments" );
308}
309
3aaeec97 310like( B::amagic_generation, qr/^\d+\z/, "amagic_generation" );
f9a20969 311
fdbd1d64
NC
312is(B::svref_2object(sub {})->ROOT->ppaddr, 'PL_ppaddr[OP_LEAVESUB]',
313 'OP->ppaddr');
314
512ba29b
FC
315# This one crashes from perl 5.8.9 to B 1.24 (perl 5.13.6):
316B::svref_2object(sub{y/\x{100}//})->ROOT->first->first->sibling->sv;
317ok 1, 'B knows that UTF trans is a padop in 5.8.9, not an svop';
318
b852bf25 319{
619dadb5
FC
320 my $o = B::svref_2object(sub{0;0})->ROOT->first->first;
321 # Make sure we are testing what we think we are testing. If these two
322 # fail, tweak the test to find a nulled cop a different way.
323 is $o->name, "null", 'first op of sub{0;0} is a null';
324 is B::ppname($o->targ),'pp_nextstate','first op of sub{0;0} was a cop';
325 # Test its class
326 is B::class($o), "COP", 'nulled cops are of class COP';
327}
328
329{
b852bf25
FR
330 format FOO =
331foo
332.
333 my $f = B::svref_2object(*FOO{FORMAT});
334 isa_ok $f, 'B::FM';
335 can_ok $f, 'LINES';
336}
337
d9cd2aeb
FC
338is B::safename("\cLAST_FH"), "^LAST_FH", 'basic safename test';
339
a60c099b 340my $sub1 = sub {die};
99225839
FC
341{ no warnings 'once'; no strict; *Peel:: = *{"Pe\0e\x{142}::"} }
342my $sub2 = eval 'package Peel; sub {die}';
a60c099b 343my $cop = B::svref_2object($sub1)->ROOT->first->first;
99225839 344my $bobby = B::svref_2object($sub2)->ROOT->first->first;
a60c099b
FC
345is $cop->stash->object_2svref, \%main::, 'COP->stash';
346is $cop->stashpv, 'main', 'COP->stashpv';
82aeefe1
DM
347
348SKIP: {
349 skip "no nulls in packages before 5.17", 1 if $] < 5.017;
350 is $bobby->stashpv, "Pe\0e\x{142}", 'COP->stashpv with utf8 and nulls';
351}
352
353SKIP: {
354 skip "no stashoff", 2 if $] < 5.017 || !$Config::Config{useithreads};
99225839
FC
355 like $cop->stashoff, qr/^[1-9]\d*\z/a, 'COP->stashoff';
356 isnt $cop->stashoff, $bobby->stashoff,
357 'different COP->stashoff for different stashes';
a60c099b
FC
358}
359
429ba3b2
FC
360my $pmop = B::svref_2object(sub{ qr/fit/ })->ROOT->first->first->sibling;
361$regexp = $pmop->pmregexp;
362is B::class($regexp), 'REGEXP', 'B::PMOP::pmregexp returns a regexp';
363is $regexp->precomp, 'fit', 'pmregexp returns the right regexp';
364
71324a3b
DM
365
366# Test $B::overlay
367{
368 my $methods = {
369 BINOP => [ qw(last) ],
370 COP => [ qw(arybase cop_seq file filegv hints hints_hash io
371 label line stash stashpv
372 stashoff warnings) ],
373 LISTOP => [ qw(children) ],
374 LOGOP => [ qw(other) ],
375 LOOP => [ qw(lastop nextop redoop) ],
376 OP => [ qw(desc flags name next opt ppaddr private sibling
377 size spare targ type) ],
378 PADOP => [ qw(gv padix sv) ],
379 PMOP => [ qw(code_list pmflags pmoffset pmreplroot pmreplstart pmstash pmstashpv precomp reflags) ],
380 PVOP => [ qw(pv) ],
381 SVOP => [ qw(gv sv) ],
382 UNOP => [ qw(first) ],
383 };
384
385 my $overlay = {};
386 my $op = B::svref_2object(sub { my $x = 1 })->ROOT;
387
388 for my $class (sort keys %$methods) {
389 for my $meth (@{$methods->{$class}}) {
390 my $full = "B::${class}::$meth";
391 die "Duplicate method '$full'\n"
392 if grep $_ eq $full, @{$overlay->{$meth}};
393 push @{$overlay->{$meth}}, "B::${class}::$meth";
394 }
395 }
396
397 {
398 local $B::overlay; # suppress 'used once' warning
399 local $B::overlay = { $$op => $overlay };
400
401 for my $class (sort keys %$methods) {
402 bless $op, "B::$class"; # naughty
403 for my $meth (@{$methods->{$class}}) {
404 if ($op->can($meth)) {
405 my $list = $op->$meth;
406 ok(defined $list
407 && ref($list) eq "ARRAY"
408 && grep($_ eq "B::${class}::$meth", @$list),
409 "overlay: B::$class $meth");
410 }
411 else {
412 pass("overlay: B::$class $meth (skipped; no method)");
413 }
414 }
415 }
416 }
417 # B::overlay should be disabled again here
418 is($op->name, "leavesub", "overlay: orig name");
419}
420
486b1e7f
TC
421{ # [perl #118525]
422 {
423 sub foo {}
424 my $cv = B::svref_2object(\&foo);
425 ok($cv, "make a B::CV from a non-anon sub reference");
426 isa_ok($cv, "B::CV");
427 my $gv = $cv->GV;
428 ok($gv, "we get a GV from a GV on a normal sub");
429 isa_ok($gv, "B::GV");
430 is($gv->NAME, "foo", "check the GV name");
431 SKIP:
432 { # do we need these version checks?
433 skip "no HEK before 5.18", 1 if $] < 5.018;
434 is($cv->NAME_HEK, undef, "no hek for a global sub");
435 }
436 }
437
438SKIP:
439 {
440 skip "no HEK before 5.18", 4 if $] < 5.018;
441 eval <<'EOS'
442 {
443 use feature 'lexical_subs';
444 no warnings 'experimental::lexical_subs';
445 my sub bar {};
446 my $cv = B::svref_2object(\&bar);
447 ok($cv, "make a B::CV from a lexical sub reference");
448 isa_ok($cv, "B::CV");
486b1e7f
TC
449 my $hek = $cv->NAME_HEK;
450 is($hek, "bar", "check the NAME_HEK");
ae77754a
FC
451 my $gv = $cv->GV;
452 isa_ok($gv, "B::GV", "GV on a lexical sub");
486b1e7f
TC
453 }
454 1;
455EOS
456 or die "lexical_subs test failed to compile: $@";
457 }
458}
459
cc54be84 460{ # [perl #120535]
cc54be84
TC
461 my %h = ( "\x{100}" => 1 );
462 my $b = B::svref_2object(\%h);
463 my ($k, $v) = $b->ARRAY;
464 is($k, "\x{100}", "check utf8 preserved by B::HV::ARRAY");
465}
466
29e61fd9
DM
467# test op_parent
468
469SKIP: {
1fafe688 470 unless ($B::OP::does_parent) {
29e61fd9
DM
471 skip "op_parent only present with -DPERL_OP_PARENT builds", 6;
472 }
473 my $lineseq = B::svref_2object(sub{my $x = 1})->ROOT->first;
474 is ($lineseq->type, B::opnumber('lineseq'),
475 'op_parent: top op is lineseq');
476 my $first = $lineseq->first;
477 my $second = $first->sibling;
478 is(ref $second->sibling, "B::NULL", 'op_parent: second sibling is null');
87b5a8b9
DM
479 is($first->moresib, 1 , 'op_parent: first sibling: moresib');
480 is($second->moresib, 0, 'op_parent: second sibling: !moresib');
29e61fd9
DM
481 is($$lineseq, ${$first->parent}, 'op_parent: first sibling okay');
482 is($$lineseq, ${$second->parent}, 'op_parent: second sibling okay');
483}
484
485
3a23d767
DM
486# make sure ->sv, -gv methods do the right thing on threaded builds
487{
488
489 # for some reason B::walkoptree only likes a sub name, not a code ref
490 my ($gv, $sv);
491 sub gvsv_const {
492 # make the early pad slots something unlike a threaded const or
493 # gvsv
494 my ($dummy1, $dummy2, $dummy3, $dummy4) = qw(foo1 foo2 foo3 foo4);
495 my $self = shift;
496 if ($self->name eq 'gvsv') {
497 $gv = $self->gv;
498 }
499 elsif ($self->name eq 'const') {
500 $sv = $self->sv;
501 }
502 };
503
504 B::walkoptree(B::svref_2object(sub {our $x = 1})->ROOT, "::gvsv_const");
505 ok(defined $gv, "gvsv->gv seen");
506 ok(defined $sv, "const->sv seen");
507 if ($Config::Config{useithreads}) {
508 # should get NULLs
509 is(ref($gv), "B::SPECIAL", "gvsv->gv is special");
510 is(ref($sv), "B::SPECIAL", "const->sv is special");
511 is($$gv, 0, "gvsv->gv special is 0 (NULL)");
512 is($$sv, 0, "const->sv special is 0 (NULL)");
513 }
514 else {
515 is(ref($gv), "B::GV", "gvsv->gv is GV");
516 is(ref($sv), "B::IV", "const->sv is IV");
517 pass();
518 pass();
519 }
520
521}
522
523
1d7705d5
FC
524# Some pad tests
525{
526 my $sub = sub { my main $a; CORE::state @b; our %c };
527 my $padlist = B::svref_2object($sub)->PADLIST;
528 is $padlist->MAX, 1, 'padlist MAX';
529 my @array = $padlist->ARRAY;
530 is @array, 2, 'two items from padlist ARRAY';
531 is ${$padlist->ARRAYelt(0)}, ${$array[0]},
532 'ARRAYelt(0) is first item from ARRAY';
533 is ${$padlist->ARRAYelt(1)}, ${$array[1]},
534 'ARRAYelt(1) is second item from ARRAY';
535 is ${$padlist->NAMES}, ${$array[0]},
536 'NAMES is first item from ARRAY';
537 my @names = $array[0]->ARRAY;
538 cmp_ok @names, ">=", 4, 'at least 4 pad names';
539 is join(" ", map($_->PV//"undef",@names[0..3])), 'undef $a @b %c',
540 'pad name PVs';
541
542 my @closures;
543 for (1,2) { push @closures, sub { sub { @closures } } }
544 my $sub1 = B::svref_2object($closures[0]);
545 my $sub2 = B::svref_2object($closures[1]);
546 is $sub2->PADLIST->id, $sub1->PADLIST->id, 'padlist id';
547 $sub1 = B::svref_2object(my $lr = $closures[0]());
548 $sub2 = B::svref_2object(my $lr2= $closures[1]());
549 is $sub2->PADLIST->outid, $sub1->PADLIST->outid, 'padlist outid';
550}
551
552
f9a20969 553done_testing();