1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841
|
#!./perl
#
# various typeglob tests
#
BEGIN {
chdir 't' if -d 't';
require './test.pl';
set_up_inc('../lib');
skip_all_without_unicode_tables();
}
use utf8;
use open qw( :utf8 :std );
use warnings;
plan( tests => 206 );
# type coersion on assignment
$ᕘ = 'ᕘ';
$ᴮᛅ = *main::ᕘ;
$ᴮᛅ = $ᕘ;
is(ref(\$ᴮᛅ), 'SCALAR');
$ᕘ = *main::ᴮᛅ;
# type coersion (not) on misc ops
ok($ᕘ);
is(ref(\$ᕘ), 'GLOB');
unlike ($ᕘ, qr/abcd/);
is(ref(\$ᕘ), 'GLOB');
is($ᕘ, '*main::ᴮᛅ');
is(ref(\$ᕘ), 'GLOB');
{
no warnings;
${\*$ᕘ} = undef;
is(ref(\$ᕘ), 'GLOB', 'no type coersion when assigning to *{} retval');
$::{ఫケ} = *ᴮᛅ;
is(
\$::{ఫケ}, \*{"ఫケ"},
'symbolic *{} returns symtab entry when FAKE'
);
${\*{"ఫケ"}} = undef;
is(
ref(\$::{ఫケ}), 'GLOB',
'no type coersion when assigning to retval of symbolic *{}'
);
$::{pɥአQuઍ} = *ᴮᛅ;
eval '
is(
\$::{pɥአQuઍ}, \*pɥአQuઍ,
"compile-time *{} returns symtab entry when FAKE"
);
${\*pɥአQuઍ} = undef;
';
is(
ref(\$::{pɥአQuઍ}), 'GLOB',
'no type coersion when assigning to retval of compile-time *{}'
);
}
# type coersion on substitutions that match
$a = *main::ᕘ;
$b = $a;
$a =~ s/^X//;
is(ref(\$a), 'GLOB');
$a =~ s/^\*//;
is($a, 'main::ᕘ');
is(ref(\$b), 'GLOB');
# typeglobs as lvalues
substr($ᕘ, 0, 1) = "XXX";
is(ref(\$ᕘ), 'SCALAR');
is($ᕘ, 'XXXmain::ᴮᛅ');
# returning glob values
sub ᕘ {
local($ᴮᛅ) = *main::ᕘ;
$ᕘ = *main::ᴮᛅ;
return ($ᕘ, $ᴮᛅ);
}
($ፉṶ, $ባ) = ᕘ();
ok(defined $ፉṶ);
is(ref(\$ፉṶ), 'GLOB');
ok(defined $ባ);
is(ref(\$ባ), 'GLOB');
# nested package globs
# NOTE: It's probably OK if these semantics change, because the
# fact that %X::Y:: is stored in %X:: isn't documented.
# (I hope.)
{ package ฝ오::ʉ; no warnings 'once'; $test=1; }
ok(exists $ฝ오::{'ʉ::'});
is($ฝ오::{'ʉ::'}, '*ฝ오::ʉ::');
# test undef operator clearing out entire glob
$ᕘ = 'stuff';
@ᕘ = qw(more stuff);
%ᕘ = qw(even more random stuff);
undef *ᕘ;
is ($ᕘ, undef);
is (scalar @ᕘ, 0);
is (scalar %ᕘ, 0);
{
# test warnings from assignment of undef to glob
my $msg = '';
local $SIG{__WARN__} = sub { $msg = $_[0] };
use warnings;
*ᕘ = 'ᴮᛅ';
is($msg, '');
*ᕘ = undef;
like($msg, qr/Undefined value assigned to typeglob/);
my $O_grave = utf8::unicode_to_native(0xd2);
my $E_grave = utf8::unicode_to_native(0xc8);
my $pat = sprintf(
# It took a lot of experimentation to get the backslashes right (khw)
"Argument \"\\*main::(?:PW\\\\x\\{%x\\}MPF"
. "|SKR\\\\x\\{%x\\}\\\\x\\{%x\\}\\\\x\\{%x\\})\" "
. "isn't numeric in sprintf",
$O_grave, $E_grave, $E_grave, $E_grave);
$pat = qr/$pat/;
no warnings 'once';
# test warnings for converting globs to other forms
my $copy = *PWÒMPF;
foreach ($copy, *SKRÈÈÈ) {
$msg = '';
my $victim = sprintf "%d", $_;
like($msg, $pat, "Warning on conversion to IV");
is($victim, 0);
$msg = '';
$victim = sprintf "%u", $_;
like($msg, $pat, "Warning on conversion to UV");
is($victim, 0);
$msg = '';
$victim = sprintf "%e", $_;
like($msg, $pat, "Warning on conversion to NV");
like($victim, qr/^0\.0+E\+?00/i, "Expect floating point zero");
$msg = '';
$victim = sprintf "%s", $_;
is($msg, '', "No warning on stringification");
is($victim, '' . $_);
}
}
my $test = curr_test();
# test *glob{THING} syntax
$Ẋ = "ok $test\n";
++$test;
@Ẋ = ("ok $test\n");
++$test;
%Ẋ = ("ok $test" => "\n");
++$test;
sub Ẋ { "ok $test\n" }
print ${*Ẋ{SCALAR}}, @{*Ẋ{ARRAY}}, %{*Ẋ{HASH}}, &{*Ẋ{CODE}};
# This needs to go here, after the print, as sub Ẋ will return the current
# value of test
++$test;
format Ẋ =
XXX This text isn't used. Should it be?
.
curr_test($test);
is (ref *Ẋ{FORMAT}, "FORMAT");
*Ẋ = *STDOUT;
is (*{*Ẋ{GLOB}}, "*main::STDOUT");
{
my $test = curr_test();
print {*Ẋ{IO}} "ok $test\n";
++$test;
my $warn;
local $SIG{__WARN__} = sub {
$warn .= $_[0];
};
my $val = *Ẋ{FILEHANDLE};
# deprecation warning removed in v5.23 -- rjbs, 2015-12-31
# https://github.com/Perl/perl5/issues/15105
print {*Ẋ{IO}} (! defined $warn
? "ok $test\n" : "not ok $test\n");
curr_test(++$test);
}
{
# test if defined() doesn't create any new symbols
my $a = "Sʎm000";
ok(!defined *{$a});
ok(!defined ${$a});
ok(!defined *{$a});
ok(!defined &{$a});
ok(!defined *{$a});
my $state = "not";
*{$a} = sub { $state = "ok" };
ok(defined &{$a});
ok(defined *{$a});
&{$a};
is ($state, 'ok');
}
# [ID 20010526.001 (#7038)] localized glob loses value when assigned to
$J=1; %J=(a=>1); @J=(1); local *J=*J; *J = sub{};
is($J, 1);
is($J{a}, 1);
is($J[0], 1);
{
# does pp_readline() handle glob-ness correctly?
my $g = *ᕘ;
$g = <DATA>;
is ($g, "Perl\n");
}
{
my $w = '';
local $SIG{__WARN__} = sub { $w = $_[0] };
sub aʙȼ1 ();
local *aʙȼ1 = sub { };
is ($w, '');
sub aʙȼ2 ();
local *aʙȼ2;
*aʙȼ2 = sub { };
is ($w, '');
sub aʙȼ3 ();
*aʙȼ3 = sub { };
like ($w, qr/Prototype mismatch/);
}
{
# [17375] rcatline to formerly-defined undef was broken. Fixed in
# do_readline by checking SvOK. AMS, 20020918
my $x = "not ";
$x = undef;
$x .= <DATA>;
is ($x, "Rules\n");
}
{
# test the assignment of a GLOB to an LVALUE
my $e = '';
local $SIG{__DIE__} = sub { $e = $_[0] };
my %V;
sub ƒ { $_[0] = 0; $_[0] = "a"; $_[0] = *DATA }
ƒ($V{V});
is ($V{V}, '*main::DATA');
is (ref\$V{V}, 'GLOB', 'lvalue assignment preserves globs');
my $x = readline $V{V};
is ($x, "perl\n");
is ($e, '', '__DIE__ handler never called');
}
{
my $e = '';
# GLOB assignment to tied element
local $SIG{__DIE__} = sub { $e = $_[0] };
sub Ʈ::TIEARRAY { bless [] => "Ʈ" }
sub Ʈ::STORE { $_[0]->[ $_[1] ] = $_[2] }
sub Ʈ::FETCH { $_[0]->[ $_[1] ] }
sub Ʈ::FETCHSIZE { @{$_[0]} }
tie my @ary => "Ʈ";
$ary[0] = *DATA;
is ($ary[0], '*main::DATA');
is (
ref\tied(@ary)->[0], 'GLOB',
'tied elem assignment preserves globs'
);
is ($e, '', '__DIE__ handler not called');
my $x = readline $ary[0];
is($x, "rocks\n");
is ($e, '', '__DIE__ handler never called');
}
{
SKIP: {
skip_if_miniperl('no dynamic loading on miniperl, no Encode', 2);
# Need some sort of die or warn to get the global destruction text if the
# bug is still present
my $prog = <<'EOPROG';
use utf8;
use open qw( :utf8 :std );
package ᴹ;
$| = 1;
sub DESTROY {eval {die qq{Farewell $_[0]}}; print $@}
package main;
bless \$Ⱥ::ㄅ, q{ᴹ};
*Ⱥ:: = \*ㄅ::;
EOPROG
utf8::decode($prog);
my $output = runperl(prog => $prog);
require Encode;
$output = Encode::decode("UTF-8", $output);
like($output, qr/^Farewell ᴹ=SCALAR/, "DESTROY was called");
unlike($output, qr/global destruction/,
"unreferenced symbol tables should be cleaned up immediately");
}
}
{
# Possibly not the correct test file for these tests.
# There are certain space optimisations implemented via promotion rules to
# GVs
foreach (qw (оઓnḲ ga_ㄕƚo잎)) {
ok(!exists $::{$_}, "no symbols of any sort to start with for $_");
}
# A string in place of the typeglob is promoted to the function prototype
$::{оઓnḲ} = "pìè";
my $proto = eval 'prototype \&оઓnḲ';
die if $@;
is ($proto, "pìè", "String is promoted to prototype");
# A reference to a value is used to generate a constant subroutine
foreach my $value (3, "Perl rules", \42, qr/whatever/, [1,2,3], {1=>2},
\*STDIN, \&ok, \undef, *STDOUT) {
delete $::{оઓnḲ};
$::{оઓnḲ} = \$value;
$proto = eval 'prototype \&оઓnḲ';
die if $@;
is ($proto, '', "Prototype for a constant subroutine is empty");
my $got = eval 'оઓnḲ';
die if $@;
is (ref $got, ref $value, "Correct type of value (" . ref($value) . ")");
is ($got, $value, "Value is correctly set");
}
}
delete $::{оઓnḲ};
$::{оઓnḲ} = \"Value";
*{"ga_ㄕƚo잎"} = \&{"оઓnḲ"};
is (ref $::{ga_ㄕƚo잎}, 'SCALAR', "Export of proxy constant as is");
is (ref $::{оઓnḲ}, 'SCALAR', "Export doesn't affect original");
is (eval 'ga_ㄕƚo잎', "Value", "Constant has correct value");
is (ref $::{ga_ㄕƚo잎}, 'SCALAR',
"Inlining of constant doesn't change representation");
delete $::{ga_ㄕƚo잎};
eval 'sub ga_ㄕƚo잎 (); 1' or die $@;
is ($::{ga_ㄕƚo잎}, '', "Prototype is stored as an empty string");
# Check that a prototype expands.
*{"ga_ㄕƚo잎"} = \&{"оઓnḲ"};
is (ref $::{оઓnḲ}, 'SCALAR', "Export doesn't affect original");
is (eval 'ga_ㄕƚo잎', "Value", "Constant has correct value");
is (ref \$::{ga_ㄕƚo잎}, 'GLOB', "Symbol table has full typeglob");
@::zᐓt = ('Zᐓt!');
# Check that assignment to an existing typeglob works
{
my $w = '';
local $SIG{__WARN__} = sub { $w = $_[0] };
*{"zᐓt"} = \&{"оઓnḲ"};
is($w, '', "Should be no warning");
}
is (ref $::{оઓnḲ}, 'SCALAR', "Export doesn't affect original");
is (eval 'zᐓt', "Value", "Constant has correct value");
is (ref \$::{zᐓt}, 'GLOB', "Symbol table has full typeglob");
is (join ('!', @::zᐓt), 'Zᐓt!', "Existing array still in typeglob");
sub Ṩp맅싵Ş () {
"Traditional";
}
# Check that assignment to an existing subroutine works
{
my $w = '';
local $SIG{__WARN__} = sub { $w = $_[0] };
*{"Ṩp맅싵Ş"} = \&{"оઓnḲ"};
like($w, qr/^Constant subroutine main::Ṩp맅싵Ş redefined/,
"Redefining a constant sub should warn");
}
is (ref $::{оઓnḲ}, 'SCALAR', "Export doesn't affect original");
is (eval 'Ṩp맅싵Ş', "Value", "Constant has correct value");
is (ref \$::{Ṩp맅싵Ş}, 'GLOB', "Symbol table has full typeglob");
# Check that assignment to an existing typeglob works
{
my $w = '';
local $SIG{__WARN__} = sub { $w = $_[0] };
*{"plუᒃ"} = [];
*{"plუᒃ"} = \&{"оઓnḲ"};
is($w, '', "Should be no warning");
}
is (ref $::{оઓnḲ}, 'SCALAR', "Export doesn't affect original");
is (eval 'plუᒃ', "Value", "Constant has correct value");
is (ref \$::{plუᒃ}, 'GLOB', "Symbol table has full typeglob");
my $gr = eval '\*plუᒃ' or die;
{
my $w = '';
local $SIG{__WARN__} = sub { $w = $_[0] };
*{$gr} = \&{"оઓnḲ"};
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)");
}
is (ref $::{оઓnḲ}, 'SCALAR', "Export doesn't affect original");
is (eval 'plუᒃ', "Value", "Constant has correct value");
is (ref \$::{plუᒃ}, 'GLOB', "Symbol table has full typeglob");
# Non-void context should defeat the optimisation, and will cause the original
# to be promoted (what change 26482 intended)
my $result;
{
my $w = '';
local $SIG{__WARN__} = sub { $w = $_[0] };
$result = *{"aẈʞƙʞƙʞƙ"} = \&{"оઓnḲ"};
is($w, '', "Should be no warning");
}
is (ref \$result, 'GLOB',
"Non void assignment should still return a typeglob");
is (ref \$::{оઓnḲ}, 'GLOB', "This export does affect original");
is (eval 'plუᒃ', "Value", "Constant has correct value");
is (ref \$::{plუᒃ}, 'GLOB', "Symbol table has full typeglob");
delete $::{оઓnḲ};
$::{оઓnḲ} = \"Value";
sub non_dangling {
my $w = '';
local $SIG{__WARN__} = sub { $w = $_[0] };
*{"z앞"} = \&{"оઓnḲ"};
is($w, '', "Should be no warning");
}
non_dangling();
is (ref $::{оઓnḲ}, 'SCALAR', "Export doesn't affect original");
is (eval 'z앞', "Value", "Constant has correct value");
is (ref $::{z앞}, 'SCALAR', "Exported target is also a PCS");
sub dangling {
local $SIG{__WARN__} = sub { die $_[0] };
*{"ビfᶠ"} = \&{"оઓnḲ"};
}
dangling();
is (ref \$::{оઓnḲ}, 'GLOB', "This export does affect original");
is (eval 'ビfᶠ', "Value", "Constant has correct value");
is (ref \$::{ビfᶠ}, 'GLOB', "Symbol table has full typeglob");
{
use vars qw($gᓙʞ $sምḲ $ᕘf);
# Check reference assignment isn't affected by the SV type (bug #38439)
$gᓙʞ = 3;
$sምḲ = 4;
$ᕘf = "halt and cool down";
my $rv = \*sምḲ;
is($gᓙʞ, 3);
*gᓙʞ = $rv;
is($gᓙʞ, 4);
my $pv = "";
$pv = \*sምḲ;
is($ᕘf, "halt and cool down");
*ᕘf = $pv;
is($ᕘf, 4);
}
{
no warnings 'once';
format =
.
foreach my $value ({1=>2}, *STDOUT{IO}, *STDOUT{FORMAT}) {
# *STDOUT{IO} returns a reference to a PVIO. As it's blessed, ref returns
# IO::Handle, which isn't what we want.
my $type = $value;
$type =~ s/.*=//;
$type =~ s/\(.*//;
delete $::{оઓnḲ};
$::{оઓnḲ} = $value;
$proto = eval 'prototype \&оઓnḲ';
like ($@, qr/^Cannot convert a reference to $type to typeglob/,
"Cannot upgrade ref-to-$type to typeglob");
}
}
{
no warnings qw(once uninitialized);
my $g = \*ȼલᑧɹ;
my $r = eval {no strict; ${*{$g}{SCALAR}}};
is ($@, '', "PERL_DONT_CREATE_GVSV shouldn't affect thingy syntax");
$g = \*vȍwɯ;
$r = eval {use strict; ${*{$g}{SCALAR}}};
is ($@, '',
"PERL_DONT_CREATE_GVSV shouldn't affect thingy syntax under strict");
}
{
# Bug reported by broquaint on IRC
*ᔅᓗsḨ::{HASH}->{ISA}=[];
ᔅᓗsḨ->import;
pass("gv_fetchmeth coped with the unexpected");
# An audit found these:
{
package ᔅᓗsḨ;
sub 맆 {
my $s = shift;
$s->SUPER::맆;
}
}
{
eval {ᔅᓗsḨ->맆;};
like ($@, qr/^Can't locate object method "맆"/, "Even with SUPER");
}
is(ᔅᓗsḨ->isa('swoosh'), '');
}
{
die if exists $::{본ㄎ};
$::{본ㄎ} = \"포ヰe";
*{"본ㄎ"} = \&{"본ㄎ"};
eval 'is(본ㄎ(), "포ヰe",
"Assignment works when glob created midway (bug 45607)"); 1'
or die $@;
}
# [perl #72740] - indirect object syntax, heuristically imputed due to
# the non-existence of a function, should not cause a stash entry to be
# created for the non-existent function.
{
{
package RƬ72740a;
my $f = bless({}, RƬ72740b);
sub s1 { s2 $f; }
our $s4;
sub s3 { s4 $f; }
}
{
package RƬ72740b;
sub s2 { "RƬ72740b::s2" }
sub s4 { "RƬ72740b::s4" }
}
ok(exists($RƬ72740a::{s1}), "RƬ72740a::s1 exists");
ok(!exists($RƬ72740a::{s2}), "RƬ72740a::s2 does not exist");
ok(exists($RƬ72740a::{s3}), "RƬ72740a::s3 exists");
ok(exists($RƬ72740a::{s4}), "RƬ72740a::s4 exists");
is(RƬ72740a::s1(), "RƬ72740b::s2", "RƬ72740::s1 parsed correctly");
is(RƬ72740a::s3(), "RƬ72740b::s4", "RƬ72740::s3 parsed correctly");
}
# [perl #71686] Globs that are in symbol table can be un-globbed
$ŚyṀ = undef;
$::{Ḟ앜ɞ} = *ŚyṀ;
is (eval 'local *::Ḟ앜ɞ = \"chuck"; $Ḟ앜ɞ', 'chuck',
"Localized glob didn't coerce into a RV");
is ($@, '', "Can localize FAKE glob that's present in stash");
{
is (scalar $::{Ḟ앜ɞ}, "*main::ŚyṀ",
"Localized FAKE glob's value was correctly restored");
}
# [perl #1804] *$x assignment when $x is a copy of another glob
# And [perl #77508] (same thing with list assignment)
{
no warnings 'once';
my $x = *_ràndom::glob_that_is_not_used_elsewhere;
*$x = sub{};
is(
"$x", '*_ràndom::glob_that_is_not_used_elsewhere',
'[perl #1804] *$x assignment when $x is FAKE',
);
$x = *_ràndom::glob_that_is_not_used_elsewhere;
(my $dummy, *$x) = (undef,[]);
is(
"$x", '*_ràndom::glob_that_is_not_used_elsewhere',
'[perl #77508] *$x list assignment when $x is FAKE',
) or require Devel::Peek, Devel::Peek::Dump($x);
}
# [perl #76540]
# this caused panics or 'Attempt to free unreferenced scalar'
# (its a compile-time issue, so the die lets us skip the prints)
{
my @warnings;
local $SIG{__WARN__} = sub { push @warnings, @_ };
eval <<'EOF';
BEGIN { $::{FÒÒ} = \'ᴮᛅ' }
die "made it";
print FÒÒ, "\n";
print FÒÒ, "\n";
EOF
like($@, qr/made it/, "#76540 - no panic");
ok(!@warnings, "#76540 - no 'Attempt to free unreferenced scalar'");
}
# [perl #77362] various bugs related to globs as PVLVs
{
no warnings qw 'once void';
my %h; # We pass a key of this hash to the subroutine to get a PVLV.
sub { for(shift) {
# Set up our glob-as-PVLV
$_ = *hòn;
is $_, "*main::hòn";
# Bad symbol for array
ok eval{ @$_; 1 }, 'PVLV glob slots can be autovivified' or diag $@;
{
# This should call TIEHANDLE, not TIESCALAR
*thèxt::TIEHANDLE = sub{};
ok eval{ tie *$_, 'thèxt'; 1 }, 'PVLV globs can be tied as handles'
or diag $@;
}
# Assigning undef to the glob should not overwrite it...
{
my $w;
local $SIG{__WARN__} = sub { $w = shift };
*$_ = undef;
is $_, "*main::hòn", 'PVLV: assigning undef to the glob does nothing';
like $w, qr\Undefined value assigned to typeglob\,
'PVLV: assigning undef to the glob warns';
}
# Neither should reference assignment.
*$_ = [];
is $_, "*main::hòn", "PVLV: arrayref assignment assigns to the AV slot";
# Concatenation should still work.
ok eval { $_ .= 'thlèw' }, 'PVLV concatenation does not die' or diag $@;
is $_, '*main::hònthlèw', 'PVLV concatenation works';
# And we should be able to overwrite it with a string, number, or refer-
# ence, too, if we omit the *.
$_ = *hòn; $_ = 'tzòr';
is $_, 'tzòr', 'PVLV: assigning a string over a glob';
$_ = *hòn; $_ = 23;
is $_, 23, 'PVLV: assigning an integer over a glob';
$_ = *hòn; $_ = 23.23;
is $_, 23.23, 'PVLV: assigning a float over a glob';
$_ = *hòn; $_ = \my $sthat;
is $_, \$sthat, 'PVLV: assigning a reference over a glob';
# This bug was found by code inspection. Could this ever happen in
# real life? :-)
# This duplicates a file handle, accessing it through a PVLV glob, the
# glob having been removed from the symbol table, so a stringified form
# of it does not work. This checks that sv_2io does not stringify a PVLV.
$_ = *quìn;
open *quìn, "test.pl"; # test.pl is as good a file as any
delete $::{quìn};
ok eval { open my $zow, "<&", $_ }, 'PVLV: sv_2io stringifieth not'
or diag $@;
# Similar tests to make sure sv_2cv etc. do not stringify.
*$_ = sub { 1 };
ok eval { &$_ }, "PVLV glob can be called as a sub" or diag $@;
*flèlp = sub { 2 };
$_ = 'flèlp';
is eval { &$_ }, 2, 'PVLV holding a string can be called as a sub'
or diag $@;
# Coderef-to-glob assignment when the glob is no longer accessible
# under its name: These tests are to make sure the OPpASSIGN_CV_TO_GV
# optimisation takes PVLVs into account, which is why the RHSs have to be
# named subs.
use constant ghèèn => 'quàrè';
$_ = *mìng;
delete $::{mìng};
*$_ = \&ghèèn;
is eval { &$_ }, 'quàrè',
'PVLV: constant assignment when the glob is detached from the symtab'
or diag $@;
$_ = *bèngth;
delete $::{bèngth};
*ghèck = sub { 'lon' };
*$_ = \&ghèck;
is eval { &$_ }, 'lon',
'PVLV: coderef assignment when the glob is detached from the symtab'
or diag $@;
{
# open should accept a PVLV as its first argument
$_ = *hòn;
ok eval { open $_,'<', \my $thlext }, 'PVLV can be the first arg to open'
or diag $@;
}
# -t should not stringify
$_ = *thlìt; delete $::{thlìt};
*$_ = *STDOUT{IO};
ok defined -t $_, 'PVLV: -t does not stringify';
# neither should -T
# but some systems donât support this on file handles
my $pass;
ok
eval {
open my $quìle, "<", 'test.pl';
$_ = *$quìle;
$pass = -T $_;
1
} ? $pass : $@ =~ /not implemented on filehandles/,
"PVLV: -T does not stringify";
# Unopened file handle
{
my $w;
local $SIG{__WARN__} = sub { $w .= shift };
$_ = *vòr;
close $_;
like $w, qr\unopened filehandle vòr\,
'PVLV globs get their names reported in unopened error messages';
}
}}->($h{k});
}
*àieee = 4;
pass('Can assign integers to typeglobs');
*àieee = 3.14;
pass('Can assign floats to typeglobs');
*àieee = 'pi';
pass('Can assign strings to typeglobs');
{
package thrèxt;
sub TIESCALAR{bless[]}
sub STORE{ die "No!"}
sub FETCH{ no warnings 'once'; *thrìt }
tie my $a, "thrèxt";
() = "$a"; # do a fetch; now $a holds a glob
eval { *$a = sub{} };
untie $a;
eval { $a = "ᴮᛅ" };
::is $a, "ᴮᛅ",
"[perl #77812] Globs in tied scalars can be reified if STORE dies"
}
# These two crashed prior to 5.13.6. In 5.13.6 they were fatal errors. They
# were fixed in 5.13.7.
ok eval {
my $glob = \*hèèn::ISA;
delete $::{"hèèn::"};
*$glob = *ᴮᛅ;
}, "glob-to-*ISA assignment works when *ISA has lost its stash";
ok eval {
my $glob = \*slàre::ISA;
delete $::{"slàre::"};
*$glob = [];
}, "array-to-*ISA assignment works when *ISA has lost its stash";
# These two crashed in 5.13.6. They were likewise fixed in 5.13.7.
ok eval {
sub grèck;
my $glob = do { no warnings "once"; \*phìng::ᕘ};
delete $::{"phìng::"};
*$glob = *grèck;
}, "Assigning a glob-with-sub to a glob that has lost its stash warks";
ok eval {
sub pòn::ᕘ;
my $glob = \*pòn::ᕘ;
delete $::{"pòn::"};
*$glob = *ᕘ;
}, "Assigning a glob to a glob-with-sub that has lost its stash warks";
{
package Tie::Alias;
sub TIESCALAR{ bless \\pop }
sub FETCH { $${$_[0]} }
sub STORE { $${$_[0]} = $_[1] }
package main;
tie my $alias, 'Tie::Alias', my $var;
no warnings 'once';
$var = *gàlobbe;
{
local *$alias = [];
$var = 3;
is $alias, 3, "[perl #77926] Glob reification during localisation";
}
}
# This code causes gp_free to call a destructor when a glob is being
# restored on scope exit. The destructor used to see SVs with a refcount of
# zero inside the glob, which could result in crashes (though not in this
# test case, which just panics).
{
no warnings 'once';
my $survived;
*Trìt::DESTROY = sub {
$thwèxt = 42; # panic
$survived = 1;
};
{
local *thwèxt = bless [],'Trìt';
();
}
ok $survived,
'no error when gp_free calls a destructor that assigns to the gv';
}
__END__
Perl
Rules
perl
rocks
|