From: Michael G. Schwern Date: Wed, 28 Aug 2002 06:04:18 +0000 (-0700) Subject: Fixes to threads::shared when disabled X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0a9af0ff24cd14b55b1aae8251486f9ccf11b2b1;p=p5sagit%2Fp5-mst-13.2.git Fixes to threads::shared when disabled Message-ID: <20020828130418.GG773@ool-18b93024.dyn.optonline.net> p4raw-id: //depot/perl@17810 --- diff --git a/MANIFEST b/MANIFEST index 99539c6..f0341a3 100644 --- a/MANIFEST +++ b/MANIFEST @@ -681,6 +681,7 @@ ext/threads/shared/t/0nothread.t Tests for basic shared array functionality. ext/threads/shared/t/av_refs.t Tests for arrays containing references ext/threads/shared/t/av_simple.t Tests for basic shared array functionality. ext/threads/shared/t/cond.t Test condition variables +ext/threads/shared/t/disabled.t Test threads::shared when threads are disabled. ext/threads/shared/t/hv_refs.t Test shared hashes containing references ext/threads/shared/t/hv_simple.t Tests for basic shared hash functionality. ext/threads/shared/t/no_share.t Tests for disabled share on variables. diff --git a/ext/threads/shared/shared.pm b/ext/threads/shared/shared.pm index cd39da6..3b41a30 100644 --- a/ext/threads/shared/shared.pm +++ b/ext/threads/shared/shared.pm @@ -6,7 +6,7 @@ use warnings; require Exporter; our @ISA = qw(Exporter); -our @EXPORT = qw(share cond_wait cond_broadcast cond_signal _refcnt _id _thrcnt); +our @EXPORT = qw(share cond_wait cond_broadcast cond_signal); our $VERSION = '0.90'; if ($threads::threads) { @@ -24,10 +24,10 @@ else { } -sub cond_wait_disabled { return @_ }; -sub cond_signal_disabled { return @_}; -sub cond_broadcast_disabled { return @_}; -sub share_disabled { return @_} +sub cond_wait_disabled (\[$@%]) { undef } +sub cond_signal_disabled (\[$@%]) { undef } +sub cond_broadcast_disabled (\[$@%]) { undef } +sub share_disabled (\[$@%]) { return $_[0] } $threads::shared::threads_shared = 1; @@ -72,7 +72,7 @@ It is used together with the threads module. =head1 EXPORT -C, C, C, C, C +C, C, C, C Note that if this module is imported when C has not yet been loaded, then these functions all become no-ops. This makes it possible @@ -87,7 +87,7 @@ environments. C takes a value and marks it as shared. You can share a scalar, array, hash, scalar ref, array ref or hash ref. C will return -the shared rvalue. +the shared rvalue but always as a reference. C will traverse up references exactly I level. C is equivalent to C, while C is not. diff --git a/ext/threads/shared/t/disabled.t b/ext/threads/shared/t/disabled.t new file mode 100644 index 0000000..067cf25 --- /dev/null +++ b/ext/threads/shared/t/disabled.t @@ -0,0 +1,53 @@ +#!./perl -Tw + +# Tests of threads::shared's behavior when threads are disabled. + +BEGIN { + chdir 't'; + @INC = '../lib'; +} + +# Can't use Test::More, it turns threads on. +use Test; +plan tests => 31; + +use threads::shared; + +# Make sure threads are really off. +ok( !$INC{"threads.pm"} ); + +# Check each faked function. +foreach my $func (qw(share cond_wait cond_signal cond_broadcast)) { + ok( my $func_ref = __PACKAGE__->can($func) ? 1 : 0 ); + + eval qq{$func()}; + ok( $@, qr/^Not enough arguments / ); + + my %hash = (foo => 42, bar => 23); + eval qq{$func(\%hash)}; + ok( $@, '' ); + ok( $hash{foo}, 42 ); + ok( $hash{bar}, 23 ); +} + +# These all have no return value. +foreach my $func (qw(cond_wait cond_signal cond_broadcast)) { + my @array = qw(1 2 3 4); + ok( eval qq{$func(\@array)}, undef ); + ok( "@array", "1 2 3 4" ); +} + +# share() is supposed to return back it's argument as a ref. +{ + my @array = qw(1 2 3 4); + ok( share(@array), \@array ); + ok( ref &share({}), 'HASH' ); + ok( "@array", "1 2 3 4" ); +} + +# lock() should be a no-op. The return value is currently undefined. +{ + my @array = qw(1 2 3 4); + lock(@array); + ok( "@array", "1 2 3 4" ); +} diff --git a/ext/threads/shared/t/hv_refs.t b/ext/threads/shared/t/hv_refs.t index 31ea5d9..94bf822 100644 --- a/ext/threads/shared/t/hv_refs.t +++ b/ext/threads/shared/t/hv_refs.t @@ -32,7 +32,7 @@ use ExtUtils::testlib; use strict; BEGIN { print "1..13\n" }; use threads; -use threads::shared qw(:DEFAULT _refcnt _id); +use threads::shared; ok(1,1,"loaded"); my $foo; share($foo); @@ -57,9 +57,9 @@ my $gg = $foo{test}; $$gg = "test"; ok(7, ${$foo{test}} eq "test", "Check reference"); my $gg2 = delete($foo{test}); -ok(8, _id($$gg) == _id($$gg2), +ok(8, threads::shared::_id($$gg) == threads::shared::_id($$gg2), sprintf("Check we get the same thing (%x vs %x)", - _id($$gg),_id($$gg2))); + threads::shared::_id($$gg),threads::shared::_id($$gg2))); ok(9, $$gg eq $$gg2, "And check the values are the same"); ok(10, keys %foo == 0, "And make sure we realy have deleted the values"); {