6 set_up_inc( qw(. ../lib) );
9 use strict qw(refs subs);
13 # Test this first before we extend the stack with other operations.
14 # This caused an asan failure due to a bad write past the end of the stack.
15 eval { die 1..127, $_=\() };
17 # Test glob operations.
46 # Test fake references.
54 # Test real references.
61 # Test references to real arrays.
63 my $test = curr_test();
64 @ary = ($test,$test+1,$test+2,$test+3);
70 push(@{$ref[$i]}, "ok $ary[$i]\n");
81 # Test references to references.
85 is ($$$refref, 'Good');
87 # Test nested anonymous arrays.
89 $ref = [[],2,[3,4,5,]];
92 is (${$$ref[2]}[2], 5);
93 is (scalar @{$$ref[0]}, 0);
96 is ($ref->[2]->[0], 3);
98 # Test references to hashes of references.
100 $refref = \%whatever;
101 $refref->{"key"} = $ref;
102 is ($refref->{"key"}->[2]->[0], 3);
104 # Test to see if anonymous subarrays spring into existence.
106 $spring[5]->[0] = 123;
107 $spring[5]->[1] = 456;
108 push(@{$spring[5]}, 789);
109 is (join(':',@{$spring[5]}), "123:456:789");
111 # Test to see if anonymous subhashes spring into existence.
113 @{$spring2{"foo"}} = (1,2,3);
114 $spring2{"foo"}->[3] = 4;
115 is (join(':',@{$spring2{"foo"}}), "1:2:3:4");
117 # Test references to subroutines.
121 sub mysub { $called++; }
126 is ref eval {\&{""}}, "CODE", 'reference to &{""} [perl #94476]';
127 delete $My::{"Foo::"};
128 is ref \&My::Foo::foo, "CODE",
129 'creating stub with \&deleted_stash::foo [perl #128532]';
132 # Test references to return values of operators (TARGs/PADTMPs)
138 is join(" ", map $$_, @refs), "a b", 'refgen+PADTMP';
141 $subrefref = \\&mysub2;
142 is ($$subrefref->("GOOD"), "good");
143 sub mysub2 { lc shift }
145 # Test REGEXP assignment
148 skip_if_miniperl("no dynamic loading on miniperl, so can't load re", 5);
151 my $str = "$x"; # regex stringification may change
154 is ($y, $str, "bare REGEXP stringifies correctly");
155 ok (eval { "x" =~ $y }, "bare REGEXP matches correctly");
158 ok (re::is_regexp($z), "new ref to REXEXP passes is_regexp");
159 is ($z, $str, "new ref to REGEXP stringifies correctly");
160 ok (eval { "x" =~ $z }, "new ref to REGEXP matches correctly");
169 is ($x, $str, "REGEXP keeps a ref to its mother_re");
170 ok (eval { "x" =~ $x }, "REGEXP with mother_re still matches");
173 # Test the ref operator.
175 sub PVBM () { 'foo' }
176 { my $dummy = index 'foo', PVBM }
178 my $pviv = 1; "$pviv";
179 my $pvnv = 1.0; "$pvnv";
183 # tied lvalue => SCALAR, as we haven't tested tie yet
184 # BIND, 'cos we can't create them yet
185 # REGEXP, 'cos that requires overload or Scalar::Util
188 [ 'undef', SCALAR => \undef ],
189 [ 'constant IV', SCALAR => \1 ],
190 [ 'constant NV', SCALAR => \1.0 ],
191 [ 'constant PV', SCALAR => \'f' ],
192 [ 'scalar', SCALAR => \$x ],
193 [ 'PVIV', SCALAR => \$pviv ],
194 [ 'PVNV', SCALAR => \$pvnv ],
195 [ 'PVMG', SCALAR => \$0 ],
196 [ 'PVBM', SCALAR => \PVBM ],
197 [ 'scalar @array', SCALAR => \scalar @array ],
198 [ 'scalar %hash', SCALAR => \scalar %hash ],
199 [ 'vstring', VSTRING => \v1 ],
200 [ 'ref', REF => \\1 ],
201 [ 'substr lvalue', LVALUE => \substr($x, 0, 0) ],
202 [ 'pos lvalue', LVALUE => \pos ],
203 [ 'vec lvalue', LVALUE => \vec($x,0,1) ],
204 [ 'named array', ARRAY => \@ary ],
205 [ 'anon array', ARRAY => [ 1 ] ],
206 [ 'named hash', HASH => \%whatever ],
207 [ 'anon hash', HASH => { a => 1 } ],
208 [ 'named sub', CODE => \&mysub, ],
209 [ 'anon sub', CODE => sub { 1; } ],
210 [ 'glob', GLOB => \*foo ],
211 [ 'format', FORMAT => *STDERR{FORMAT} ],
213 my ($desc, $type, $ref) = @$_;
214 is (ref $ref, $type, "ref() for ref to $desc");
215 like ("$ref", qr/^$type\(0x[0-9a-f]+\)$/, "stringify for ref to $desc");
218 is (ref *STDOUT{IO}, 'IO::File', 'IO refs are blessed into IO::File');
219 like (*STDOUT{IO}, qr/^IO::File=IO\(0x[0-9a-f]+\)$/,
220 'stringify for IO refs');
222 { # Test re-use of ref's TARG [perl #101738]
223 my $obj = bless [], '____';
224 my $uniobj = bless [], chr 256;
225 my $get_ref = sub { ref shift };
226 my $dummy = &$get_ref($uniobj);
227 $dummy = &$get_ref($obj);
228 ok exists { ____ => undef }->{$dummy}, 'ref sets UTF8 flag correctly';
231 # Test anonymous hash syntax.
234 is (ref $anonhash, 'HASH');
235 $anonhash2 = {FOO => 'BAR', ABC => 'XYZ',};
236 is (join('', sort values %$anonhash2), 'BARXYZ');
238 # Test bless operator.
242 $object = bless $main'anonhash2;
243 main::is (ref $object, 'MYHASH');
244 main::is ($object->{ABC}, 'XYZ');
247 main::is (ref $object2, 'MYHASH');
249 # Test ordinary call on object method.
251 &mymethod($object,"argument");
254 local($THIS, @ARGS) = @_;
255 die 'Got a "' . ref($THIS). '" instead of a MYHASH'
256 unless ref $THIS eq 'MYHASH';
257 main::is ($ARGS[0], "argument");
258 main::is ($THIS->{FOO}, 'BAR');
261 # Test automatic destructor call.
266 $main'anonhash2 = "foo";
270 return unless $string;
271 main::is ($string, 'good');
273 # Test that the object has not already been "cursed".
274 main::isnt (ref shift, 'HASH');
277 # Now test inheritance of methods.
283 $main'object = bless {FOO => 'foo', BAR => 'bar'};
287 # Test arrow-style method invocation.
289 is ($object->doit("BAR"), 'bar');
291 # Test indirect-object-style method invocation.
293 $foo = doit $object "FOO";
294 main::is ($foo, 'foo');
298 die "Not an OBJ" unless ref $ref eq 'OBJ';
306 sub foo { main::is ($_[1], 'works') }
309 foo WHATEVER "works";
312 # test the \(@foo) construct
317 @baz = \(1,@foo,@bar);
318 is (scalar (@bar), 3);
319 is (scalar grep(ref($_), @bar), 3);
320 is (scalar (@baz), 3);
322 my(@fuu) = \(1..2,3);
324 my(@bzz) = \(1,@fuu,@baa);
325 is (scalar (@baa), 3);
326 is (scalar grep(ref($_), @baa), 3);
327 is (scalar (@bzz), 3);
329 # also, it can't be an lvalue
330 # (That’s what *you* think! --sprout)
331 eval '\\($x, $y) = (1, 2);';
332 like ($@, qr/Can\'t modify.*ref.*in.*assignment(?x:
333 )|Experimental aliasing via reference not enabled/);
335 # test for proper destruction of lexical objects
337 sub larry::DESTROY { print "# larry\nok $test\n"; }
338 sub curly::DESTROY { print "# curly\nok ", $test + 1, "\n"; }
339 sub moe::DESTROY { print "# moe\nok ", $test + 2, "\n"; }
342 my ($joe, @curly, %larry);
343 my $moe = bless \$joe, 'moe';
344 my $curly = bless \@curly, 'curly';
345 my $larry = bless \%larry, 'larry';
346 print "# leaving block\n";
349 print "# left block\n";
350 curr_test($test + 3);
356 { local(*bar) = "foo" }
366 # test if reblessing during destruction results in more destruction
370 sub new { bless {}, shift }
371 DESTROY { print "# destroying 'A'\nok ", $test + 1, "\n" }
373 sub new { bless {}, shift }
374 DESTROY { print "# destroying '_B'\nok $test\n"; bless shift, 'A' }
378 curr_test($test + 2);
380 # test if $_[0] is properly protected in DESTROY()
383 my $test = curr_test();
385 local $SIG{'__DIE__'} = sub {
388 print "# infinite recursion, bailing\nnot ok $test\n";
391 like ($m, qr/^Modification of a read-only/);
394 sub new { bless {}, shift }
395 DESTROY { $_[0] = 'foo' }
397 print "# should generate an error...\n";
400 print "# good, didn't recurse\n";
403 # test that DESTROY is called on all objects during global destruction,
404 # even those without hard references [perl #36347]
408 stderr => 1, prog => 'sub DESTROY { print qq-aaa\n- } bless \$a[0]'
410 "aaa\n", 'DESTROY called on array elem'
415 prog => '{ bless \my@x; *a=sub{@x}}sub DESTROY { print qq-aaa\n- }'
418 'DESTROY called on closure variable'
421 # But cursing objects must not result in double frees
422 # This caused "Attempt to free unreferenced scalar" in 5.16.
424 'bless \%foo::, bar::; bless \%bar::, foo::; print "ok\n"', "ok\n",
426 'no double free when stashes are blessed into each other');
429 # test if refgen behaves with autoviv magic
441 # This test is the reason for postponed destruction in sv_unref
446 # This test used to coredump. The BEGIN block is important as it causes the
447 # op that created the constant reference to be freed. Hence the only
448 # reference to the constant string "pass" is in $a. The hack that made
449 # sure $a = $a->[1] would work didn't work with references to constants.
452 foreach my $lexical ('', 'my $a; ') {
453 my $expect = "pass\n";
454 my $result = runperl (switches => ['-wl'], stderr => 1,
455 prog => $lexical . 'BEGIN {$a = \q{pass}}; $a = $$a; print $a');
458 is ($result, $expect);
462 sub x::DESTROY {print "ok ", $test + shift->[0], "\n"}
463 { my $a1 = bless [3],"x";
464 my $a2 = bless [2],"x";
465 { my $a3 = bless [1],"x";
466 my $a4 = bless [0],"x";
472 is (runperl (switches=>['-l'],
473 prog=> 'print 1; print qq-*$\*-;print 1;'),
478 runperl(prog => 'sub UNIVERSAL::AUTOLOAD { qr// } a->p' );
479 is ($?, 0, 'UNIVERSAL::AUTOLOAD called when freeing qr//');
481 runperl(prog => 'sub UNIVERSAL::DESTROY { warn } bless \$a, A', stderr => 1);
482 is ($?, 0, 'warn called inside UNIVERSAL::DESTROY');
487 runperl(prog => 'sub f { my $x = shift; *z = $x; } f({}); f();');
488 is ($?, 0, 'coredump on typeglob = (SvRV && !SvROK)');
490 # bug #27268: freeing self-referential typeglobs could trigger
491 # "Attempt to free unreferenced scalar" warnings
494 prog => 'use Symbol;my $x=bless \gensym,q{t}; print;*$$x=$x',
496 ), '', 'freeing self-referential typeglob');
498 # using a regex in the destructor for STDOUT segfaulted because the
499 # REGEX pad had already been freed (ithreads build only). The
500 # object is required to trigger the early freeing of GV refs to STDOUT
503 local $TODO = "works but output through pipe is mangled" if $^O eq 'VMS';
505 prog => '$x=bless[]; sub IO::Handle::DESTROY{$_=q{bad};s/bad/ok/;print}',
507 ), qr/^(ok)+$/, 'STDOUT destructor');
513 $name_utf8 = $name8 . chr 256;
516 is ($$name8, undef, 'Nothing before we start');
517 is ($$name_utf8, undef, 'Nothing before we start');
519 is ($$name8, "Pound", 'Accessing via 8 bit symref works');
520 is ($$name_utf8, "Pound", 'Accessing via UTF8 symref works');
525 $name_utf8 = $name = chr 9787;
526 utf8::encode $name_utf8;
528 is (length $name, 1, "Name is 1 char");
529 is (length $name_utf8, 3, "UTF8 representation is 3 chars");
531 is ($$name, undef, 'Nothing before we start');
532 is ($$name_utf8, undef, 'Nothing before we start');
534 is ($$name, "Face", 'Accessing via Unicode symref works');
535 is ($$name_utf8, undef,
536 'Accessing via the UTF8 byte sequence gives nothing');
544 isnt ($name1, $name2, "They differ");
546 is ($$name1, undef, 'Nothing before we start (scalars)');
547 is ($$name2, undef, 'Nothing before we start');
549 is ($$name1, "Yummy", 'Accessing via the correct name works');
551 'Accessing via a different NUL-containing name gives nothing');
552 # defined uses a different code path
553 ok (defined $$name1, 'defined via the correct name works');
554 ok (!defined $$name2,
555 'defined via a different NUL-containing name gives nothing');
557 is ($name1->[0], undef, 'Nothing before we start (arrays)');
558 is ($name2->[0], undef, 'Nothing before we start');
559 $name1->[0] = "Yummy";
560 is ($name1->[0], "Yummy", 'Accessing via the correct name works');
561 is ($name2->[0], undef,
562 'Accessing via a different NUL-containing name gives nothing');
563 ok (defined $name1->[0], 'defined via the correct name works');
564 ok (!defined$name2->[0],
565 'defined via a different NUL-containing name gives nothing');
567 my (undef, $one) = @{$name1}[2,3];
568 my (undef, $two) = @{$name2}[2,3];
569 is ($one, undef, 'Nothing before we start (array slices)');
570 is ($two, undef, 'Nothing before we start');
571 @{$name1}[2,3] = ("Very", "Yummy");
572 (undef, $one) = @{$name1}[2,3];
573 (undef, $two) = @{$name2}[2,3];
574 is ($one, "Yummy", 'Accessing via the correct name works');
576 'Accessing via a different NUL-containing name gives nothing');
577 ok (defined $one, 'defined via the correct name works');
579 'defined via a different NUL-containing name gives nothing');
581 is ($name1->{PWOF}, undef, 'Nothing before we start (hashes)');
582 is ($name2->{PWOF}, undef, 'Nothing before we start');
583 $name1->{PWOF} = "Yummy";
584 is ($name1->{PWOF}, "Yummy", 'Accessing via the correct name works');
585 is ($name2->{PWOF}, undef,
586 'Accessing via a different NUL-containing name gives nothing');
587 ok (defined $name1->{PWOF}, 'defined via the correct name works');
588 ok (!defined $name2->{PWOF},
589 'defined via a different NUL-containing name gives nothing');
591 my (undef, $one) = @{$name1}{'SNIF', 'BEEYOOP'};
592 my (undef, $two) = @{$name2}{'SNIF', 'BEEYOOP'};
593 is ($one, undef, 'Nothing before we start (hash slices)');
594 is ($two, undef, 'Nothing before we start');
595 @{$name1}{'SNIF', 'BEEYOOP'} = ("Very", "Yummy");
596 (undef, $one) = @{$name1}{'SNIF', 'BEEYOOP'};
597 (undef, $two) = @{$name2}{'SNIF', 'BEEYOOP'};
598 is ($one, "Yummy", 'Accessing via the correct name works');
600 'Accessing via a different NUL-containing name gives nothing');
601 ok (defined $one, 'defined via the correct name works');
603 'defined via a different NUL-containing name gives nothing');
605 $name1 = "Left"; $name2 = "Left\0Right";
606 my $glob2 = *{$name2};
608 is ($glob1, undef, "We get different typeglobs. In fact, undef");
610 *{$name1} = sub {"One"};
611 *{$name2} = sub {"Two"};
613 is (&{$name1}, "One");
614 is (&{$name2}, "Two");
617 # test derefs after list slice
619 is ( ({foo => "bar"})[0]{foo}, "bar", 'hash deref from list slice w/o ->' );
620 is ( ({foo => "bar"})[0]->{foo}, "bar", 'hash deref from list slice w/ ->' );
621 is ( ([qw/foo bar/])[0][1], "bar", 'array deref from list slice w/o ->' );
622 is ( ([qw/foo bar/])[0]->[1], "bar", 'array deref from list slice w/ ->' );
623 is ( (sub {"bar"})[0](), "bar", 'code deref from list slice w/o ->' );
624 is ( (sub {"bar"})[0]->(), "bar", 'code deref from list slice w/ ->' );
626 # deref on empty list shouldn't autovivify
630 like ( "$@", qr/Can't use an undefined value as a HASH reference/,
631 "deref of undef from list slice fails" );
634 # test dereferencing errors
639 foreach $ref (*STDOUT{IO}, *STDERR{FORMAT}) {
641 like($@, qr/Not a SCALAR reference/, "Scalar dereference");
643 like($@, qr/Not an ARRAY reference/, "Array dereference");
645 like($@, qr/Not a HASH reference/, "Hash dereference");
647 like($@, qr/Not a CODE reference/, "Code dereference");
650 $ref = *STDERR{FORMAT};
652 like($@, qr/Not a GLOB reference/, "Glob dereference");
656 is($@, '', "Glob dereference of PVIO is acceptable");
658 is($ref, *{$ref}{IO}, "IO slot of the temporary glob is set correctly");
661 # these will segfault if they fail
666 ok (!eval { *$rpvbm }, 'PVBM ref is not a GLOB ref');
667 ok (!eval { *$pvbm }, 'PVBM is not a GLOB ref');
668 ok (!eval { $$pvbm }, 'PVBM is not a SCALAR ref');
669 ok (!eval { @$pvbm }, 'PVBM is not an ARRAY ref');
670 ok (!eval { %$pvbm }, 'PVBM is not a HASH ref');
671 ok (!eval { $pvbm->() }, 'PVBM is not a CODE ref');
672 ok (!eval { $rpvbm->foo }, 'PVBM is not an object');
675 is( runperl(stderr => 1, prog => 'map eval qq(exit),1 for 1'), "");
676 is( runperl(stderr => 1, prog => 'eval { for (1) { map { die } 2 } };'), "");
677 is( runperl(stderr => 1, prog => 'for (125) { map { exit } (213)}'), "");
678 my $hushed = $^O eq 'VMS' ? 'use vmsish qw(hushed);' : '';
679 is( runperl(stderr => 1, prog => $hushed . 'map die,4 for 3'), "Died at -e line 1.\n");
680 is( runperl(stderr => 1, prog => $hushed . 'grep die,4 for 3'), "Died at -e line 1.\n");
681 is( runperl(stderr => 1, prog => $hushed . 'for $a (3) {@b=sort {die} 4,5}'), "Died at -e line 1.\n");
684 is( runperl(stderr => 1, prog => 'my $i;for $i (1) { for $i (2) { } }'), "");
686 # The mechanism for freeing objects in globs used to leave dangling
687 # pointers to freed SVs. To test this, we construct this nested structure:
688 # GV => blessed(AV) => RV => GV => blessed(SV)
689 # all with a refcnt of 1, and hope that the second GV gets processed first
690 # by do_clean_named_objs. Then when the first GV is processed, it mustn't
691 # find anything nasty left by the previous GV processing.
692 # The eval is stop things in the main body of the code holding a reference
693 # to a GV, and the print at the end seems to bee necessary to ensure
694 # the correct freeing order of *x and *y (no, I don't know why - DAPM).
697 prog => 'eval q[bless \@y; bless \$x; $y[0] = \*x; $z = \*y; ]; '
698 . 'delete $::{x}; delete $::{y}; print qq{ok\n};',
700 "ok\n", 'freeing freed glob in global destruction');
703 # Test undefined hash references as arguments to %{} in boolean context
707 eval { my $foo; %$foo; }; ok !$@, '%$undef';
708 eval { my $foo; scalar %$foo; }; ok !$@, 'scalar %$undef';
709 eval { my $foo; !%$foo; }; ok !$@, '!%$undef';
710 eval { my $foo; if ( %$foo) {} }; ok !$@, 'if ( %$undef) {}';
711 eval { my $foo; if (!%$foo) {} }; ok !$@, 'if (!%$undef) {}';
712 eval { my $foo; unless ( %$foo) {} }; ok !$@, 'unless ( %$undef) {}';
713 eval { my $foo; unless (!%$foo) {} }; ok !$@, 'unless (!%$undef) {}';
714 eval { my $foo; 1 if %$foo; }; ok !$@, '1 if %$undef';
715 eval { my $foo; 1 if !%$foo; }; ok !$@, '1 if !%$undef';
716 eval { my $foo; 1 unless %$foo; }; ok !$@, '1 unless %$undef;';
717 eval { my $foo; 1 unless ! %$foo; }; ok !$@, '1 unless ! %$undef';
718 eval { my $foo; %$foo ? 1 : 0; }; ok !$@, ' %$undef ? 1 : 0';
719 eval { my $foo; !%$foo ? 1 : 0; }; ok !$@, '!%$undef ? 1 : 0';
723 # Make sure that a leaked thinggy with multiple weak references to
724 # it doesn't trigger a panic with multiple rounds of global cleanup
725 # (Perl_sv_clean_all).
728 skip_if_miniperl('no Scalar::Util under miniperl', 4);
730 local $ENV{PERL_DESTRUCT_LEVEL} = 2;
732 # we do all permutations of array/hash, 1ref/2ref, to account
733 # for the different way backref magic is stored
735 fresh_perl_is(<<'EOF', 'ok', { stderr => 1 }, 'array with 1 weak ref');
736 use Scalar::Util qw(weaken);
738 Internals::SvREFCNT(@$r, 9);
744 fresh_perl_is(<<'EOF', 'ok', { stderr => 1 }, 'array with 2 weak refs');
745 use Scalar::Util qw(weaken);
747 Internals::SvREFCNT(@$r, 9);
755 fresh_perl_is(<<'EOF', 'ok', { stderr => 1 }, 'hash with 1 weak ref');
756 use Scalar::Util qw(weaken);
758 Internals::SvREFCNT(%$r, 9);
764 fresh_perl_is(<<'EOF', 'ok', { stderr => 1 }, 'hash with 2 weak refs');
765 use Scalar::Util qw(weaken);
767 Internals::SvREFCNT(%$r, 9);
778 skip_if_miniperl "no Scalar::Util on miniperl", 1;
780 *hassgropper::DESTROY = sub {
781 require Scalar::Util;
782 eval { Scalar::Util::weaken($_[0]) };
784 # This line caused a crash before weaken refused to weaken a
785 # read-only reference:
786 $do::not::overwrite::this = $_[0];
788 my $xs = bless [], "hassgropper";
790 like $error, qr/^Modification of a read-only/,
791 'weaken refuses to weaken a read-only ref';
792 # Now that the test has passed, avoid sabotaging global destruction:
793 undef *hassgropper::DESTROY;
794 undef $do::not::overwrite::this;
798 is ref( bless {}, "nul\0clean" ), "nul\0clean", "ref() is nul-clean";
800 # Test constants and references thereto.
803 like $@, qr/^Modification of a read-only/,
804 'assignment to value aliased to literal number';
806 like $@, qr/^Modification of a read-only/,
807 'refgen does not allow assignment to value aliased to literal number';
809 for ("4eounthouonth") {
811 like $@, qr/^Modification of a read-only/,
812 'assignment to value aliased to literal string';
814 like $@, qr/^Modification of a read-only/,
815 'refgen does not allow assignment to value aliased to literal string';
820 '[perl #109746] referential identity of \literal under threads+mad'
823 # ref in boolean context
828 my $obj = bless {}, "Foo";
829 my $objnull = bless [], "";
830 my $obj0 = bless [], "0";
831 my $obj00 = bless [], "00";
832 my $obj1 = bless [], "1";
834 is !ref $false, 1, '!ref $false';
835 is !ref $true, 1, '!ref $true';
836 is !ref $plain, "", '!ref $plain';
837 is !ref $obj, "", '!ref $obj';
838 is !ref $objnull, "", '!ref $objnull';
839 is !ref $obj0 , 1, '!ref $obj0';
840 is !ref $obj00, "", '!ref $obj00';
841 is !ref $obj1, "", '!ref $obj1';
843 is ref $obj || 0, "Foo", 'ref $obj || 0';
844 is ref $obj // 0, "Foo", 'ref $obj // 0';
845 is $true && ref $obj, "Foo", '$true && ref $obj';
846 is ref $obj ? "true" : "false", "true", 'ref $obj ? "true" : "false"';
849 if (ref $obj) { $r = 1 };
850 is $r, 1, 'if (ref $obj)';
853 if (ref $obj0) { $r = 1 };
854 is $r, 2, 'if (ref $obj0)';
857 if (ref $obj) { $r = 1 } else { $r = 0 };
858 is $r, 1, 'if (ref $obj) else';
861 if (ref $obj0) { $r = 1 } else { $r = 0 };
862 is $r, 0, 'if (ref $obj0) else';
867 # if an op returns &PL_sv_zero rather than newSViv(0), the
868 # value should be mutable. So ref (via the PADTMP flag) should
869 # make a mutable copy
872 my $r = \ scalar grep $_ == 1, @a;
874 is $$r, 10, "RT #78288 - mutable PL_sv_zero copy";
878 # RT#130861: heap-use-after-free in pp_rv2sv, from asan fuzzing
880 skip_if_miniperl("no dynamic loading on miniperl, so can't load arybase", 1);
881 # this value is critical - its just enough so that the stack gets
882 # grown which loading/calling arybase
887 my @a = map $$ary, 1..NNN;
891 my @exp = ("0") x $n;
892 fresh_perl_is($code, "@exp", { stderr => 1 },
893 'rt#130861: heap uaf in pp_rv2sv');
896 # Bit of a hack to make test.pl happy. There are 3 more tests after it leaves.
898 curr_test($test + 3);
899 # test global destruction
901 my $test1 = $test + 1;
902 my $test2 = $test + 2;
907 $ref3 = bless ["ok $test2\n"]; # package destruction
908 my $ref2 = bless ["ok $test1\n"]; # lexical destruction
909 local $ref1 = bless ["ok $test\n"]; # dynamic destruction
910 1; # flush any temp values on stack