4 # various typeglob tests
17 # type coercion on assignment
21 is(ref(\$bar), 'SCALAR');
24 # type coercion (not) on misc ops
27 is(ref(\$foo), 'GLOB');
29 unlike ($foo, qr/abcd/);
30 is(ref(\$foo), 'GLOB');
32 is($foo, '*main::bar');
33 is(ref(\$foo), 'GLOB');
38 is(ref(\$foo), 'GLOB', 'no type coercion when assigning to *{} retval');
41 \$::{phake}, \*{"phake"},
42 'symbolic *{} returns symtab entry when FAKE'
44 ${\*{"phake"}} = undef;
46 ref(\$::{phake}), 'GLOB',
47 'no type coercion when assigning to retval of symbolic *{}'
52 \$::{phaque}, \*phaque,
53 "compile-time *{} returns symtab entry when FAKE"
58 ref(\$::{phaque}), 'GLOB',
59 'no type coercion when assigning to retval of compile-time *{}'
63 # type coercion on substitutions that match
72 # typeglobs as lvalues
73 substr($foo, 0, 1) = "XXX";
74 is(ref(\$foo), 'SCALAR');
75 is($foo, 'XXXmain::bar');
77 # returning glob values
79 local($bar) = *main::foo;
86 is(ref(\$fuu), 'GLOB');
90 is(ref(\$baa), 'GLOB');
92 # nested package globs
93 # NOTE: It's probably OK if these semantics change, because the
94 # fact that %X::Y:: is stored in %X:: isn't documented.
97 { package Foo::Bar; no warnings 'once'; $test=1; }
98 ok(exists $Foo::{'Bar::'});
99 is($Foo::{'Bar::'}, '*Foo::Bar::');
102 # test undef operator clearing out entire glob
104 @foo = qw(more stuff);
105 %foo = qw(even more random stuff);
112 # test warnings from assignment of undef to glob
114 local $SIG{__WARN__} = sub { $msg = $_[0] };
119 like($msg, qr/Undefined value assigned to typeglob/);
122 # test warnings for converting globs to other forms
124 foreach ($copy, *SKREEE) {
126 my $victim = sprintf "%d", $_;
127 like($msg, qr/Argument "\*main::[A-Z]{6}" isn't numeric in sprintf/,
128 "Warning on conversion to IV");
132 $victim = sprintf "%u", $_;
133 like($msg, qr/Argument "\*main::[A-Z]{6}" isn't numeric in sprintf/,
134 "Warning on conversion to UV");
138 $victim = sprintf "%e", $_;
139 like($msg, qr/Argument "\*main::[A-Z]{6}" isn't numeric in sprintf/,
140 "Warning on conversion to NV");
141 like($victim, qr/^0\.0+E\+?00/i, "Expect floating point zero");
144 $victim = sprintf "%s", $_;
145 is($msg, '', "No warning on stringification");
146 is($victim, '' . $_);
150 my $test = curr_test();
151 # test *glob{THING} syntax
156 %x = ("ok $test" => "\n");
158 sub x { "ok $test\n" }
159 print ${*x{SCALAR}}, @{*x{ARRAY}}, %{*x{HASH}}, &{*x{CODE}};
160 # This needs to go here, after the print, as sub x will return the current
164 XXX This text isn't used. Should it be?
168 is (ref *x{FORMAT}, "FORMAT");
169 is ("@{sub { *_{ARRAY} }->(1..3)}", "1 2 3",
170 'returning *_{ARRAY} from sub');
172 is (*{*x{GLOB}}, "*main::STDOUT");
175 my $test = curr_test();
177 print {*x{IO}} "ok $test\n";
181 local $SIG{__WARN__} = sub {
184 my $val = *x{FILEHANDLE};
185 print {*x{IO}} ($warn =~ /is deprecated/
186 ? "ok $test\n" : "not ok $test\n");
190 is *x{NAME}, 'x', '*foo{NAME}';
191 is *x{PACKAGE}, 'main', '*foo{PACKAGE}';
192 { no warnings 'once'; *x = *Foo::y; }
193 is *x, '*Foo::y', 'glob stringifies as assignee after glob-to-glob assign';
194 is *x{NAME}, 'x', 'but *foo{NAME} still returns the original name';
195 is *x{PACKAGE}, 'main', 'and *foo{PACKAGE} the original package';
198 # test if defined() doesn't create any new symbols
210 *{$a} = sub { $state = "ok" };
218 # although it *should* if you're talking about magicals
235 "o" =~ /(((((((((((o)))))))))))/;
240 # [ID 20010526.001] localized glob loses value when assigned to
242 $j=1; %j=(a=>1); @j=(1); local *j=*j; *j = sub{};
249 # does pp_readline() handle glob-ness correctly?
257 local $SIG{__WARN__} = sub { $w = $_[0] };
259 local *abc1 = sub { };
267 like ($w, qr/Prototype mismatch/);
271 # [17375] rcatline to formerly-defined undef was broken. Fixed in
272 # do_readline by checking SvOK. AMS, 20020918
280 # test the assignment of a GLOB to an LVALUE
282 local $SIG{__DIE__} = sub { $e = $_[0] };
284 sub f { $_[0] = 0; $_[0] = "a"; $_[0] = *DATA }
286 is ($v{v}, '*main::DATA');
287 is (ref\$v{v}, 'GLOB', 'lvalue assignment preserves globs');
288 my $x = readline $v{v};
290 is ($e, '', '__DIE__ handler never called');
295 # GLOB assignment to tied element
296 local $SIG{__DIE__} = sub { $e = $_[0] };
297 sub T::TIEARRAY { bless [] => "T" }
298 sub T::STORE { $_[0]->[ $_[1] ] = $_[2] }
299 sub T::FETCH { $_[0]->[ $_[1] ] }
300 sub T::FETCHSIZE { @{$_[0]} }
303 is ($ary[0], '*main::DATA');
305 ref\tied(@ary)->[0], 'GLOB',
306 'tied elem assignment preserves globs'
308 is ($e, '', '__DIE__ handler not called');
309 my $x = readline $ary[0];
311 is ($e, '', '__DIE__ handler never called');
315 # Need some sort of die or warn to get the global destruction text if the
316 # bug is still present
317 my $output = runperl(prog => <<'EOPROG');
320 sub DESTROY {eval {die qq{Farewell $_[0]}}; print $@}
326 like($output, qr/^Farewell M=SCALAR/, "DESTROY was called");
327 unlike($output, qr/global destruction/,
328 "unreferenced symbol tables should be cleaned up immediately");
331 # Possibly not the correct test file for these tests.
332 # There are certain space optimisations implemented via promotion rules to
335 foreach (qw (oonk ga_shloip)) {
336 ok(!exists $::{$_}, "no symbols of any sort to start with for $_");
339 # A string in place of the typeglob is promoted to the function prototype
341 my $proto = eval 'prototype \&oonk';
343 is ($proto, "pie", "String is promoted to prototype");
346 # A reference to a value is used to generate a constant subroutine
347 foreach my $value (3, "Perl rules", \42, qr/whatever/, [1,2,3], {1=>2},
348 \*STDIN, \&ok, \undef, *STDOUT) {
351 $proto = eval 'prototype \&oonk';
353 is ($proto, '', "Prototype for a constant subroutine is empty");
355 my $got = eval 'oonk';
357 is (ref $got, ref $value, "Correct type of value (" . ref($value) . ")");
358 is ($got, $value, "Value is correctly set");
362 $::{oonk} = \"Value";
364 *{"ga_shloip"} = \&{"oonk"};
366 is (ref $::{ga_shloip}, 'SCALAR', "Export of proxy constant as is");
367 is (ref $::{oonk}, 'SCALAR', "Export doesn't affect original");
368 is (eval 'ga_shloip', "Value", "Constant has correct value");
369 is (ref $::{ga_shloip}, 'SCALAR',
370 "Inlining of constant doesn't change representation");
372 delete $::{ga_shloip};
374 eval 'sub ga_shloip (); 1' or die $@;
375 is ($::{ga_shloip}, '', "Prototype is stored as an empty string");
377 # Check that a prototype expands.
378 *{"ga_shloip"} = \&{"oonk"};
380 is (ref $::{oonk}, 'SCALAR', "Export doesn't affect original");
381 is (eval 'ga_shloip', "Value", "Constant has correct value");
382 is (ref \$::{ga_shloip}, 'GLOB', "Symbol table has full typeglob");
387 # Check that assignment to an existing typeglob works
390 local $SIG{__WARN__} = sub { $w = $_[0] };
391 *{"zwot"} = \&{"oonk"};
392 is($w, '', "Should be no warning");
395 is (ref $::{oonk}, 'SCALAR', "Export doesn't affect original");
396 is (eval 'zwot', "Value", "Constant has correct value");
397 is (ref \$::{zwot}, 'GLOB', "Symbol table has full typeglob");
398 is (join ('!', @::zwot), 'Zwot!', "Existing array still in typeglob");
404 # Check that assignment to an existing subroutine works
407 local $SIG{__WARN__} = sub { $w = $_[0] };
408 *{"spritsits"} = \&{"oonk"};
409 like($w, qr/^Constant subroutine main::spritsits redefined/,
410 "Redefining a constant sub should warn");
413 is (ref $::{oonk}, 'SCALAR', "Export doesn't affect original");
414 is (eval 'spritsits', "Value", "Constant has correct value");
415 is (ref \$::{spritsits}, 'GLOB', "Symbol table has full typeglob");
417 # Check that assignment to an existing typeglob works
420 local $SIG{__WARN__} = sub { $w = $_[0] };
422 *{"plunk"} = \&{"oonk"};
423 is($w, '', "Should be no warning");
426 is (ref $::{oonk}, 'SCALAR', "Export doesn't affect original");
427 is (eval 'plunk', "Value", "Constant has correct value");
428 is (ref \$::{plunk}, 'GLOB', "Symbol table has full typeglob");
430 my $gr = eval '\*plunk' or die;
434 local $SIG{__WARN__} = sub { $w = $_[0] };
436 is($w, '', "Redefining a constant sub to another constant sub with the same underlying value should not warn (It's just re-exporting, and that was always legal)");
439 is (ref $::{oonk}, 'SCALAR', "Export doesn't affect original");
440 is (eval 'plunk', "Value", "Constant has correct value");
441 is (ref \$::{plunk}, 'GLOB', "Symbol table has full typeglob");
443 # Non-void context should defeat the optimisation, and will cause the original
444 # to be promoted (what change 26482 intended)
448 local $SIG{__WARN__} = sub { $w = $_[0] };
449 $result = *{"awkkkkkk"} = \&{"oonk"};
450 is($w, '', "Should be no warning");
453 is (ref \$result, 'GLOB',
454 "Non void assignment should still return a typeglob");
456 is (ref \$::{oonk}, 'GLOB', "This export does affect original");
457 is (eval 'plunk', "Value", "Constant has correct value");
458 is (ref \$::{plunk}, 'GLOB', "Symbol table has full typeglob");
461 $::{oonk} = \"Value";
465 local $SIG{__WARN__} = sub { $w = $_[0] };
466 *{"zap"} = \&{"oonk"};
467 is($w, '', "Should be no warning");
471 is (ref $::{oonk}, 'SCALAR', "Export doesn't affect original");
472 is (eval 'zap', "Value", "Constant has correct value");
473 is (ref $::{zap}, 'SCALAR', "Exported target is also a PCS");
476 local $SIG{__WARN__} = sub { die $_[0] };
477 *{"biff"} = \&{"oonk"};
481 is (ref \$::{oonk}, 'GLOB', "This export does affect original");
482 is (eval 'biff', "Value", "Constant has correct value");
483 is (ref \$::{biff}, 'GLOB', "Symbol table has full typeglob");
485 $::{yarrow} = [4,5,6];
486 is join("-", eval "yarrow()"), '4-5-6', 'array ref as stash elem';
487 is ref $::{yarrow}, "ARRAY", 'stash elem is still array ref after use';
488 is join("-", eval "&yarrow"), '4-5-6', 'calling const list with &';
489 is join("-", eval "&yarrow(1..10)"), '4-5-6', 'const list ignores & args';
490 is prototype "yarrow", "", 'const list has "" prototype';
491 is eval "yarrow", 3, 'const list in scalar cx returns length';
494 use vars qw($glook $smek $foof);
495 # Check reference assignment isn't affected by the SV type (bug #38439)
498 $foof = "halt and cool down";
507 is($foof, "halt and cool down");
515 foreach my $value ({1=>2}, *STDOUT{IO}, \&ok, *STDOUT{FORMAT}) {
516 # *STDOUT{IO} returns a reference to a PVIO. As it's blessed, ref returns
517 # IO::Handle, which isn't what we want.
523 $proto = eval 'prototype \&oonk';
524 like ($@, qr/^Cannot convert a reference to $type to typeglob/,
525 "Cannot upgrade ref-to-$type to typeglob");
529 no warnings qw(once uninitialized);
531 my $r = eval {no strict; ${*{$g}{SCALAR}}};
532 is ($@, '', "PERL_DONT_CREATE_GVSV shouldn't affect thingy syntax");
535 $r = eval {use strict; ${*{$g}{SCALAR}}};
537 "PERL_DONT_CREATE_GVSV shouldn't affect thingy syntax under strict");
541 # Bug reported by broquaint on IRC
542 *slosh::{HASH}->{ISA}=[];
544 pass("gv_fetchmeth coped with the unexpected");
546 # An audit found these:
555 like ($@, qr/^Can't locate object method "rip"/, "Even with SUPER");
557 is(slosh->isa('swoosh'), '');
559 $CORE::GLOBAL::{"lock"}=[];
560 eval "no warnings; lock";
561 like($@, qr/^Not enough arguments for lock/,
562 "Can't trip up general keyword overloading");
564 $CORE::GLOBAL::{"readline"}=[];
565 eval "<STDOUT> if 0";
566 is($@, '', "Can't trip up readline overloading");
568 $CORE::GLOBAL::{"readpipe"}=[];
570 is($@, '', "Can't trip up readpipe overloading");
574 die if exists $::{BONK};
575 $::{BONK} = \"powie";
576 *{"BONK"} = \&{"BONK"};
577 eval 'is(BONK(), "powie",
578 "Assignment works when glob created midway (bug 45607)"); 1'
582 # For now these tests are here, but they would probably be better in a file for
583 # tests for croaks. (And in turn, that probably deserves to be in a different
584 # directory. Gerard Goossen has a point about the layout being unclear
587 no warnings 'numeric';
591 no warnings 'numeric';
598 foreach my $type (qw(integer number string)) {
599 my $prog = "coerce_$type(*STDERR)";
600 is (scalar eval "$prog; 1", undef, "$prog failed...");
601 like ($@, qr/Can't coerce GLOB to $type in/,
602 "with the correct error message");
605 # RT #65582 anonymous glob should be defined, and not coredump when
606 # stringified. The behaviours are:
608 # defined($glob) "$glob" $glob .= ...
609 # 5.8.8 false "" with uninit warning "" with uninit warning
610 # 5.10.0 true (coredump) (coredump)
611 # 5.1[24] true "" "" with uninit warning
612 # 5.16 true "*__ANON__::..." "*__ANON__::..."
615 my $io_ref = *STDOUT{IO};
617 ok(defined $glob, "RT #65582 anon glob should be defined");
620 local $SIG{__WARN__} = sub { $warn = $_[0] };
623 is($warn, '', "RT #65582 anon glob stringification shouldn't warn");
624 is($str, '*__ANON__::__ANONIO__',
625 "RT #65582/#96326 anon glob stringification");
628 # Another stringification bug: Test that recursion does not cause lexical
629 # handles to lose their names.
632 @output = r($_[0]-1) if $_[0];
639 '*main::$fh *main::$fh *main::$fh *main::$fh *main::$fh',
640 'recursion does not cause lex handles to lose their names';
642 # And sub cloning, too; not just recursion
647 @output = CORE::__SUB__->($_[0]-1) if $_[0];
653 '*main::$fh *main::$fh *main::$fh *main::$fh *main::$fh',
654 'sub cloning does not cause lex handles to lose their names';
656 # [perl #71254] - Assigning a glob to a variable that has a current
657 # match position. (We are testing that Perl_magic_setmglob respects globs'
658 # special used of SvSCREAM.)
660 $m = 2; $m=~s/./0/gems; $m= *STDERR;
662 "$m", "*main::STDERR",
663 '[perl #71254] assignment of globs to vars with pos'
667 # [perl #72740] - indirect object syntax, heuristically imputed due to
668 # the non-existence of a function, should not cause a stash entry to be
669 # created for the non-existent function.
672 my $f = bless({}, RT72740b);
679 sub s2 { "RT72740b::s2" }
680 sub s4 { "RT72740b::s4" }
682 ok(exists($RT72740a::{s1}), "RT72740a::s1 exists");
683 ok(!exists($RT72740a::{s2}), "RT72740a::s2 does not exist");
684 ok(exists($RT72740a::{s3}), "RT72740a::s3 exists");
685 ok(exists($RT72740a::{s4}), "RT72740a::s4 exists");
686 is(RT72740a::s1(), "RT72740b::s2", "RT72740::s1 parsed correctly");
687 is(RT72740a::s3(), "RT72740b::s4", "RT72740::s3 parsed correctly");
689 # [perl #71686] Globs that are in symbol table can be un-globbed
692 is (eval 'local *::fake = \"chuck"; $fake', 'chuck',
693 "Localized glob didn't coerce into a RV");
694 is ($@, '', "Can localize FAKE glob that's present in stash");
695 is (scalar $::{fake}, "*main::sym",
696 "Localized FAKE glob's value was correctly restored");
698 # [perl #1804] *$x assignment when $x is a copy of another glob
699 # And [perl #77508] (same thing with list assignment)
702 my $x = *_random::glob_that_is_not_used_elsewhere;
705 "$x", '*_random::glob_that_is_not_used_elsewhere',
706 '[perl #1804] *$x assignment when $x is FAKE',
708 $x = *_random::glob_that_is_not_used_elsewhere;
709 (my $dummy, *$x) = (undef,[]);
711 "$x", '*_random::glob_that_is_not_used_elsewhere',
712 '[perl #77508] *$x list assignment when $x is FAKE',
713 ) or require Devel::Peek, Devel::Peek::Dump($x);
717 # this caused panics or 'Attempt to free unreferenced scalar'
718 # (its a compile-time issue, so the die lets us skip the prints)
721 local $SIG{__WARN__} = sub { push @warnings, @_ };
724 BEGIN { $::{FOO} = \'bar' }
730 like($@, qr/made it/, "#76540 - no panic");
731 ok(!@warnings, "#76540 - no 'Attempt to free unreferenced scalar'");
734 # [perl #77362] various bugs related to globs as PVLVs
736 no warnings qw 'once void';
737 my %h; # We pass a key of this hash to the subroutine to get a PVLV.
739 # Set up our glob-as-PVLV
742 # Bad symbol for array
743 ok eval{ @$_; 1 }, 'PVLV glob slots can be autovivified' or diag $@;
745 # This should call TIEHANDLE, not TIESCALAR
746 *thext::TIEHANDLE = sub{};
747 ok eval{ tie *$_, 'thext'; 1 }, 'PVLV globs can be tied as handles'
750 # Assigning undef to the glob should not overwrite it...
753 local $SIG{__WARN__} = sub { $w = shift };
755 is $_, "*main::hon", 'PVLV: assigning undef to the glob does nothing';
756 like $w, qr\Undefined value assigned to typeglob\,
757 'PVLV: assigning undef to the glob warns';
760 # Neither should reference assignment.
762 is $_, "*main::hon", "PVLV: arrayref assignment assigns to the AV slot";
764 # Concatenation should still work.
765 ok eval { $_ .= 'thlew' }, 'PVLV concatenation does not die' or diag $@;
766 is $_, '*main::honthlew', 'PVLV concatenation works';
768 # And we should be able to overwrite it with a string, number, or refer-
769 # ence, too, if we omit the *.
770 $_ = *hon; $_ = 'tzor';
771 is $_, 'tzor', 'PVLV: assigning a string over a glob';
773 is $_, 23, 'PVLV: assigning an integer over a glob';
774 $_ = *hon; $_ = 23.23;
775 is $_, 23.23, 'PVLV: assigning a float over a glob';
776 $_ = *hon; $_ = \my $sthat;
777 is $_, \$sthat, 'PVLV: assigning a reference over a glob';
779 # This bug was found by code inspection. Could this ever happen in
781 # This duplicates a file handle, accessing it through a PVLV glob, the
782 # glob having been removed from the symbol table, so a stringified form
783 # of it does not work. This checks that sv_2io does not stringify a PVLV.
785 open *quin, "test.pl"; # test.pl is as good a file as any
787 ok eval { open my $zow, "<&", $_ }, 'PVLV: sv_2io stringifieth not'
790 # Similar tests to make sure sv_2cv etc. do not stringify.
792 ok eval { &$_ }, "PVLV glob can be called as a sub" or diag $@;
795 is eval { &$_ }, 2, 'PVLV holding a string can be called as a sub'
798 # Coderef-to-glob assignment when the glob is no longer accessible
799 # under its name: These tests are to make sure the OPpASSIGN_CV_TO_GV
800 # optimisation takes PVLVs into account, which is why the RHSs have to be
802 use constant gheen => 'quare';
806 is eval { &$_ }, 'quare',
807 'PVLV: constant assignment when the glob is detached from the symtab'
811 *gheck = sub { 'lon' };
813 is eval { &$_ }, 'lon',
814 'PVLV: coderef assignment when the glob is detached from the symtab'
818 skip_if_miniperl("no dynamic loading on miniperl, so can't load PerlIO::scalar", 1);
819 # open should accept a PVLV as its first argument
821 ok eval { open $_,'<', \my $thlext }, 'PVLV can be the first arg to open'
825 # -t should not stringify
826 $_ = *thlit; delete $::{thlit};
828 ok defined -t $_, 'PVLV: -t does not stringify';
831 # but some systems don’t support this on file handles
835 open my $quile, "<", 'test.pl';
839 } ? $pass : $@ =~ /not implemented on filehandles/,
840 "PVLV: -T does not stringify";
842 # Unopened file handle
845 local $SIG{__WARN__} = sub { $w .= shift };
848 like $w, qr\unopened filehandle vor\,
849 'PVLV globs get their names reported in unopened error messages';
856 pass('Can assign integers to typeglobs');
858 pass('Can assign floats to typeglobs');
860 pass('Can assign strings to typeglobs');
864 sub TIESCALAR{bless[]}
865 sub STORE{ die "No!"}
866 sub FETCH{ no warnings 'once'; *thrit }
868 () = "$a"; # do a fetch; now $a holds a glob
869 eval { *$a = sub{} };
873 "[perl #77812] Globs in tied scalars can be reified if STORE dies"
876 # These two crashed prior to 5.13.6. In 5.13.6 they were fatal errors. They
877 # were fixed in 5.13.7.
879 my $glob = \*heen::ISA;
880 delete $::{"heen::"};
882 }, "glob-to-*ISA assignment works when *ISA has lost its stash";
884 my $glob = \*slare::ISA;
885 delete $::{"slare::"};
887 }, "array-to-*ISA assignment works when *ISA has lost its stash";
888 # These two crashed in 5.13.6. They were likewise fixed in 5.13.7.
891 my $glob = do { no warnings "once"; \*phing::foo};
892 delete $::{"phing::"};
894 }, "Assigning a glob-with-sub to a glob that has lost its stash works";
897 my $glob = \*pon::foo;
900 }, "Assigning a glob to a glob-with-sub that has lost its stash works";
904 sub TIESCALAR{ bless \\pop }
905 sub FETCH { $${$_[0]} }
906 sub STORE { $${$_[0]} = $_[1] }
908 tie my $alias, 'Tie::Alias', my $var;
914 is $alias, 3, "[perl #77926] Glob reification during localisation";
918 # This code causes gp_free to call a destructor when a glob is being
919 # restored on scope exit. The destructor used to see SVs with a refcount of
920 # zero inside the glob, which could result in crashes (though not in this
921 # test case, which just panics).
925 *Trit::DESTROY = sub {
926 $thwext = 42; # panic
931 $thwext = bless[],'Trit';
935 'no error when gp_free calls a destructor that assigns to the gv';
938 # This is a similar test, for destructors seeing a GV without a reference
940 sub undefine_me_if_you_dare {}
941 bless \&undefine_me_if_you_dare, "Undefiner";
942 sub Undefiner::DESTROY {
943 undef *undefine_me_if_you_dare;
947 local $SIG{__WARN__} = sub { $w .= shift };
948 undef *undefine_me_if_you_dare;
950 'undeffing a gv in DESTROY triggered by undeffing the same gv'
954 # More gp_free madness. gp_free could call a destructor that frees the gv
955 # whose gp is being freed.
956 sub Fred::AUTOLOAD { $Fred::AUTOLOAD }
957 undef *{"Fred::AUTOLOAD"};
958 pass 'no crash from gp_free triggering gv_try_downgrade';
959 sub _121242::DESTROY { delete $_121242::{$_[0][0]} };
960 ${"_121242::foo"} = bless ["foo"], _121242::;
961 undef *{"_121242::foo"};
962 pass 'no crash from pp_undef/gp_free freeing the gv';
963 ${"_121242::bar"} = bless ["bar"], _121242::;
964 *{"_121242::bar"} = "bar";
965 pass 'no crash from sv_setsv/gp_free freeing the gv';
966 ${"_121242::baz"} = bless ["baz"], _121242::;
967 *{"_121242::baz"} = *foo;
968 pass 'no crash from glob_assign_glob/gp_free freeing the gv';
971 undef *_121242::DESTROY;
972 *_121242::DESTROY = sub { undef $foo };
973 my $set_up_foo = sub {
974 # Make $$foo into a fake glob whose array slot holds a blessed
975 # array that undefines $foo, freeing the fake glob.
977 $$foo = do {local *bar};
978 *$$foo = bless [], _121242::;
982 pass 'no crash from sv_setsv/sv_unglob/gp_free freeing the gv';
985 pass 'no crash from sv_utf8_encode/sv_unglob/gp_free freeing the gv';
989 pass 'no crash from do_readline/sv_unglob/gp_free freeing the gv';
993 pass 'no crash from pp_concat/sv_unglob/gp_free freeing the gv';
997 pass 'no crash from sv_inc/sv_unglob/gp_free freeing the gv';
1000 pass 'no crash from sv_dec/sv_unglob/gp_free freeing the gv';
1003 pass 'no crash from pp_undef/sv_unglob/gp_free freeing the gv';
1006 $$foo =~ s/3/$$foo = do {local *bar}; *$$foo = bless [],_121242::; 4/e;
1007 pass 'no crash from pp_substcont/sv_unglob/gp_free freeing the gv';
1011 eval { *{my $undef} = 3 };
1012 like $@, qr/^Can't use an undefined value as a symbol reference at /,
1013 '*{ $undef } assignment';
1014 eval { *{;undef} = 3 };
1015 like $@, qr/^Can't use an undefined value as a symbol reference at /,
1016 '*{ ;undef } assignment';
1018 # [perl #99142] defined &{"foo"} when there is a constant stub
1019 # If I break your module, you get to have it mentioned in Perl's tests. :-)
1020 package HTTP::MobileAttribute::Plugin::Locator {
1021 use constant LOCATOR_GPS => 1;
1022 ::ok defined &{__PACKAGE__."::LOCATOR_GPS"},
1023 'defined &{"name of constant"}';
1024 ::ok Internals::SvREFCNT(${__PACKAGE__."::"}{LOCATOR_GPS}),
1025 "stash elem for slot is not freed prematurely";
1028 # Check that constants promoted to CVs point to the right GVs when the name
1031 use constant x => 3;
1032 # These two lines abuse the optimisation that copies the scalar ref from
1033 # one stash element to another, to get a constant with a null in its name
1034 *{"yz\0a"} = \&{"x"};
1035 my $ref = \&{"yz\0a"};
1036 ::ok !exists $lrcg::{yz},
1037 'constants w/nulls in their names point 2 the right GVs when promoted';
1042 stat *{"try_downgrade"};
1045 eval "*try_downgrade if 0";
1048 'try_downgrade does not touch PL_statgv (last stat handle)';
1049 readline *{"try_downgrade2"};
1050 my $lastfh = "${^LAST_FH}";
1051 eval "*try_downgrade2 if 0";
1052 is ${^LAST_FH}, $lastfh, 'try_downgrade does not touch PL_last_in_gv';
1055 is runperl(prog => '$s = STDERR; close $s; undef *$s;'
1056 .'eval q-*STDERR if 0-; *$s = *STDOUT{IO}; warn'),
1057 "Warning: something's wrong at -e line 1.\n",
1058 "try_downgrade does not touch PL_stderrgv";
1061 'use constant foo=>1; BEGIN { $x = \&foo } undef &$x; $x->()',
1063 "Undefined subroutine &main::foo called at -e line 1.\n",
1064 "gv_try_downgrade does not anonymise CVs referenced elsewhere";
1066 package glob_constant_test {
1068 use constant bar => *foo;
1069 BEGIN { undef *foo }
1070 ::is eval { bar->() }, eval { &{+bar} },
1071 'glob_constant->() is not mangled at compile time';
1072 ::is "$@", "", 'no error from eval { &{+glob_constant} }';
1075 # Look away, please.
1076 # This violates perl's internal structures by fiddling with stashes in a
1077 # way that should never happen, but perl should not start trying to free
1078 # unallocated memory as a result. There is no ok() or is() because the
1079 # panic that used to occur only occurred during global destruction, and
1080 # only with PERL_DESTRUCT_LEVEL=2. (The panic itself was sufficient for
1081 # the harness to consider this test script to have failed.)
1082 $::{aoeuaoeuaoeaoeu} = __PACKAGE__; # cow
1083 () = *{"aoeuaoeuaoeaoeu"};
1089 pass "No crash due to CvGV(vivified stub) pointing to flattened glob copy";
1090 # Not really supported, but this should not crash either:
1092 delete $::{_119051again};
1093 $::{_119051again} = $x; # now we have a fake glob under the right name
1094 $y = \&$x; # so when this tries to look up the right GV for
1095 undef $::{_119051again}; # CvGV, it still gets a fake one
1097 pass "No crash due to CvGV pointing to glob copy in the stash";