Change 17810 by [EMAIL PROTECTED] on 2002/08/30 11:58:18

        Subject: [PATCH] Fixes to threads::shared when disabled
        From: Michael G Schwern <[EMAIL PROTECTED]>
        Date: Wed, 28 Aug 2002 06:04:18 -0700
        Message-ID: <[EMAIL PROTECTED]>

Affected files ...

.... //depot/perl/MANIFEST#936 edit
.... //depot/perl/ext/threads/shared/shared.pm#30 edit
.... //depot/perl/ext/threads/shared/t/disabled.t#1 add
.... //depot/perl/ext/threads/shared/t/hv_refs.t#7 edit

Differences ...

==== //depot/perl/MANIFEST#936 (text) ====
Index: perl/MANIFEST
--- perl/MANIFEST#935~17798~    Thu Aug 29 04:44:00 2002
+++ perl/MANIFEST       Fri Aug 30 04:58:18 2002
@@ -681,6 +681,7 @@
 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.

==== //depot/perl/ext/threads/shared/shared.pm#30 (text) ====
Index: perl/ext/threads/shared/shared.pm
--- perl/ext/threads/shared/shared.pm#29~17512~ Fri Jul 12 16:53:22 2002
+++ perl/ext/threads/shared/shared.pm   Fri Aug 30 04:58:18 2002
@@ -6,7 +6,7 @@
 
 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 @@
 }
 
 
-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 @@
 
 =head1 EXPORT
 
-C<share>, C<lock>, C<cond_wait>, C<cond_signal>, C<cond_broadcast>
+C<share>, C<cond_wait>, C<cond_signal>, C<cond_broadcast>
 
 Note that if this module is imported when C<threads> has not yet been
 loaded, then these functions all become no-ops. This makes it possible
@@ -87,7 +87,7 @@
 
 C<share> takes a value and marks it as shared. You can share a scalar,
 array, hash, scalar ref, array ref or hash ref.  C<share> will return
-the shared rvalue.
+the shared rvalue but always as a reference.
 
 C<share> will traverse up references exactly I<one> level.
 C<share(\$a)> is equivalent to C<share($a)>, while C<share(\\$a)> is not.

==== //depot/perl/ext/threads/shared/t/disabled.t#1 (text) ====
Index: perl/ext/threads/shared/t/disabled.t
--- /dev/null   Tue May  5 13:32:27 1998
+++ perl/ext/threads/shared/t/disabled.t        Fri Aug 30 04:58:18 2002
@@ -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" );
+}

==== //depot/perl/ext/threads/shared/t/hv_refs.t#7 (text) ====
Index: perl/ext/threads/shared/t/hv_refs.t
--- perl/ext/threads/shared/t/hv_refs.t#6~17109~        Sat Jun  8 12:02:19 2002
+++ perl/ext/threads/shared/t/hv_refs.t Fri Aug 30 04:58:18 2002
@@ -32,7 +32,7 @@
 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 @@
 $$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");
 {
End of Patch.

Reply via email to