diff options
author | Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> | 2021-12-03 17:56:56 +0000 |
---|---|---|
committer | Paul Evans <leonerd@leonerd.org.uk> | 2021-12-08 14:31:17 +0000 |
commit | 8d55e914e048b6646b2bafaaec296b12a92335f3 (patch) | |
tree | 1b33759b7a968a5aaa34be967fb133e70f295d6e | |
parent | a851b13eedbbea8c270db05d62381de2e8133080 (diff) | |
download | perl-8d55e914e048b6646b2bafaaec296b12a92335f3.tar.gz |
Use builtin::weaken() in t/
-rw-r--r-- | t/op/array.t | 13 | ||||
-rw-r--r-- | t/op/hash.t | 7 | ||||
-rw-r--r-- | t/op/hashassign.t | 17 | ||||
-rw-r--r-- | t/op/lvref.t | 6 | ||||
-rw-r--r-- | t/op/ref.t | 19 | ||||
-rw-r--r-- | t/op/svleak.t | 4 | ||||
-rw-r--r-- | t/op/threads.t | 12 | ||||
-rw-r--r-- | t/op/tie.t | 10 | ||||
-rw-r--r-- | t/op/write.t | 6 | ||||
-rw-r--r-- | t/re/qr-72922.t | 4 |
10 files changed, 44 insertions, 54 deletions
diff --git a/t/op/array.t b/t/op/array.t index 6370a9f072..ec6b5125af 100644 --- a/t/op/array.t +++ b/t/op/array.t @@ -440,14 +440,13 @@ $::ra = [ bless [], 'A' ]; pass 'no crash when freeing array that is being cleared'; # [perl #85670] Copying magic to elements -SKIP: { - skip "no Scalar::Util::weaken on miniperl", 1, if is_miniperl; - require Scalar::Util; +{ package glelp { - Scalar::Util::weaken ($a = \@ISA); - @ISA = qw(Foo); - Scalar::Util::weaken ($a = \$ISA[0]); - ::is @ISA, 1, 'backref magic is not copied to elements'; + use builtin 'weaken'; + weaken ($a = \@ISA); + @ISA = qw(Foo); + weaken ($a = \$ISA[0]); + ::is @ISA, 1, 'backref magic is not copied to elements'; } } package peen { diff --git a/t/op/hash.t b/t/op/hash.t index 6c9fa1b636..1d140be666 100644 --- a/t/op/hash.t +++ b/t/op/hash.t @@ -100,13 +100,12 @@ sub guard::DESTROY { } # Weak references to pad hashes -SKIP: { - skip_if_miniperl("No Scalar::Util::weaken under miniperl", 1); +{ my $ref; - require Scalar::Util; + use builtin 'weaken'; { my %hash; - Scalar::Util::weaken($ref = \%hash); + weaken($ref = \%hash); 1; # the previous statement must not be the last } is $ref, undef, 'weak refs to pad hashes go stale on scope exit'; diff --git a/t/op/hashassign.t b/t/op/hashassign.t index a457068442..d8bd9609e5 100644 --- a/t/op/hashassign.t +++ b/t/op/hashassign.t @@ -310,15 +310,14 @@ foreach my $chr (60, 200, 600, 6000, 60000) { } # [perl #76716] Hash assignment should not zap weak refs. -SKIP: { - skip_if_miniperl("no dynamic loading on miniperl, no Scalar::Util", 2); - my %tb; - require Scalar::Util; - Scalar::Util::weaken(my $p = \%tb); - %tb = (); - is $p, \%tb, "hash assignment should not zap weak refs"; - undef %tb; - is $p, \%tb, "hash undef should not zap weak refs"; +{ + my %tb; + use builtin 'weaken'; + weaken(my $p = \%tb); + %tb = (); + is $p, \%tb, "hash assignment should not zap weak refs"; + undef %tb; + is $p, \%tb, "hash undef should not zap weak refs"; } # test odd hash assignment warnings diff --git a/t/op/lvref.t b/t/op/lvref.t index 3991a53780..9553583848 100644 --- a/t/op/lvref.t +++ b/t/op/lvref.t @@ -538,11 +538,9 @@ like $@, is s(3), 1, 'padstale alias should not reset state' } -SKIP: { - skip_without_dynamic_extension('List/Util'); - require Scalar::Util; +{ my $a; - Scalar::Util::weaken($r = \$a); + builtin::weaken($r = \$a); \$a = $r; pass 'no crash when assigning \$lex = $weakref_to_lex' } diff --git a/t/op/ref.t b/t/op/ref.t index 93f39bdc7c..fbe0d1ffd2 100644 --- a/t/op/ref.t +++ b/t/op/ref.t @@ -724,16 +724,14 @@ is (runperl( # it doesn't trigger a panic with multiple rounds of global cleanup # (Perl_sv_clean_all). -SKIP: { - skip_if_miniperl('no Scalar::Util under miniperl', 4); - +{ local $ENV{PERL_DESTRUCT_LEVEL} = 2; # we do all permutations of array/hash, 1ref/2ref, to account # for the different way backref magic is stored fresh_perl_is(<<'EOF', 'ok', { stderr => 1 }, 'array with 1 weak ref'); -use Scalar::Util qw(weaken); +use builtin qw(weaken); my $r = []; Internals::SvREFCNT(@$r, 9); my $r1 = $r; @@ -742,7 +740,7 @@ print "ok"; EOF fresh_perl_is(<<'EOF', 'ok', { stderr => 1 }, 'array with 2 weak refs'); -use Scalar::Util qw(weaken); +use builtin qw(weaken); my $r = []; Internals::SvREFCNT(@$r, 9); my $r1 = $r; @@ -753,7 +751,7 @@ print "ok"; EOF fresh_perl_is(<<'EOF', 'ok', { stderr => 1 }, 'hash with 1 weak ref'); -use Scalar::Util qw(weaken); +use builtin qw(weaken); my $r = {}; Internals::SvREFCNT(%$r, 9); my $r1 = $r; @@ -762,7 +760,7 @@ print "ok"; EOF fresh_perl_is(<<'EOF', 'ok', { stderr => 1 }, 'hash with 2 weak refs'); -use Scalar::Util qw(weaken); +use builtin qw(weaken); my $r = {}; Internals::SvREFCNT(%$r, 9); my $r1 = $r; @@ -774,12 +772,11 @@ EOF } -SKIP:{ - skip_if_miniperl "no Scalar::Util on miniperl", 1; +{ my $error; *hassgropper::DESTROY = sub { - require Scalar::Util; - eval { Scalar::Util::weaken($_[0]) }; + use builtin qw(weaken); + eval { weaken($_[0]) }; $error = $@; # This line caused a crash before weaken refused to weaken a # read-only reference: diff --git a/t/op/svleak.t b/t/op/svleak.t index 3df4838be8..523293c74e 100644 --- a/t/op/svleak.t +++ b/t/op/svleak.t @@ -222,12 +222,10 @@ leak_expr(5, 0, q{"YYYYYa" =~ /.+?(a(.+?)|b)/ }, "trie leak"); 'map reading from sparse array'); } -SKIP: { # broken by 304474c3, fixed by cefd5c7c, but didn't seem to cause # any other test failures # base test case from ribasushi (Peter Rabbitson) - eval { require Scalar::Util; Scalar::Util->import("weaken"); 1; } - or skip "no weaken", 1; + use builtin 'weaken'; my $weak; { $weak = my $in = {}; diff --git a/t/op/threads.t b/t/op/threads.t index a2dbdca700..1277169f4c 100644 --- a/t/op/threads.t +++ b/t/op/threads.t @@ -29,11 +29,11 @@ EOI # Attempt to free unreferenced scalar: SV 0x814e0dc. fresh_perl_is(<<'EOI', 'ok', { }, 'weaken ref under threads'); use threads; -use Scalar::Util; +use builtin 'weaken'; my $data = "a"; my $obj = \$data; my $copy = $obj; -Scalar::Util::weaken($copy); +weaken($copy); threads->create(sub { 1 })->join for (1..1); print "ok"; EOI @@ -47,7 +47,7 @@ package Foo; sub new { bless {},shift } package main; use threads; -use Scalar::Util qw(weaken); +use builtin 'weaken'; my $object = Foo->new; my $ref = $object; weaken $ref; @@ -217,8 +217,8 @@ EOJ # The weak reference $a, however, is visible from the symbol table. fresh_perl_is(<<'EOI', 'ok', { }, 'Test for 34394ecd06e704e9'); use threads; + use builtin 'weaken'; %h = (1, 2); - use Scalar::Util 'weaken'; $a = \$h{1}; weaken($a); delete $h{1} && threads->create(sub {}, shift)->join(); @@ -243,8 +243,8 @@ EOI fresh_perl_is(<<'EOI', 'ok', { }, '0 refcnt neither on tmps stack nor in @_'); use threads; + use builtin 'weaken'; my %h = (1, []); - use Scalar::Util 'weaken'; my $a = $h{1}; weaken($a); delete $h{1} && threads->create(sub {}, shift)->join(); @@ -295,7 +295,7 @@ use threads; { package My::Obj; - use Scalar::Util 'weaken'; + use builtin 'weaken'; my %reg; diff --git a/t/op/tie.t b/t/op/tie.t index 089c1ee23d..e09b080559 100644 --- a/t/op/tie.t +++ b/t/op/tie.t @@ -996,7 +996,7 @@ EXPECT # # [perl #86328] Crash when freeing tie magic that can increment the refcnt -eval { require Scalar::Util } or print("ok\n"), exit; +use builtin 'weaken'; sub TIEHASH { return $_[1]; @@ -1010,12 +1010,12 @@ sub DESTROY { my $a = {}; my $o = bless []; -Scalar::Util::weaken($o->[0] = $a); +weaken($o->[0] = $a); tie %$a, "main", $o; my $b = []; my $p = bless []; -Scalar::Util::weaken($p->[0] = $b); +weaken($p->[0] = $b); tie @$b, "main", $p; # Done setting up the evil data structures @@ -1189,9 +1189,9 @@ EXPECT BEGIN { unless (defined &DynaLoader::boot_DynaLoader) { print "HASH\nHASH\nARRAY\nARRAY\n"; exit; }} -use Scalar::Util 'weaken'; +use builtin 'weaken'; { package xoufghd; - sub TIEHASH { Scalar::Util::weaken($_[1]); bless \$_[1], xoufghd:: } + sub TIEHASH { weaken($_[1]); bless \$_[1], xoufghd:: } *TIEARRAY = *TIEHASH; DESTROY { bless ${$_[0]} || return, 0; diff --git a/t/op/write.t b/t/op/write.t index 33f52c2b3f..feb1ffc9a8 100644 --- a/t/op/write.t +++ b/t/op/write.t @@ -1972,13 +1972,13 @@ write STRICT; close STRICT or die "Could not close: $!"; is cat('Op_write.tmp'), "oof:\n", 'pragmata on format line'; -SKIP: { - skip "no weak refs" unless eval { require Scalar::Util }; +{ + use builtin 'weaken'; sub Potshriggley { format Potshriggley = . } - Scalar::Util::weaken(my $x = *Potshriggley{FORMAT}); + weaken(my $x = *Potshriggley{FORMAT}); undef *Potshriggley; is $x, undef, 'formats in subs do not leak'; } diff --git a/t/re/qr-72922.t b/t/re/qr-72922.t index 5f41ae363f..279aba8146 100644 --- a/t/re/qr-72922.t +++ b/t/re/qr-72922.t @@ -4,16 +4,16 @@ use strict; BEGIN { chdir 't' if -d 't'; require './test.pl'; - skip_all_if_miniperl("no dynamic loading on miniperl, no Scalar::Util"); } +use builtin 'weaken'; + plan(tests => 14); # [perl 72922]: A 'copy' of a Regex object which has magic should not crash # When a Regex object was copied and the copy weaken then the original regex object # could no longer be 'copied' with qr// -use Scalar::Util 'weaken'; sub s1 { my $re = qr/abcdef/; my $re_copy1 = $re; |