develooper Front page | perl.perl5.porters | Postings from November 2004

share() producing empty hash

Thread Next
From:
Michael G Schwern
Date:
November 23, 2004 01:41
Subject:
share() producing empty hash
Message ID:
20041123094126.GA11627@windhund.schwern.org
With Test::More 0.50 and threads I get an odd error using skip and threads.

[~/tmp/Test-Simple-0.50] perl5.8.5 -Ilib -wle 'use threads;  use Test::More "no_plan";  pass("foo");  SKIP: { skip "this", 1 }'
ok 1 - foo
ok 2 # skip this
1..2
# Looks like you failed 1 test of 2.

Internally what's happening is in Test::Builder->skip.  On line 721 it
does this.

    $Test_Results[$Curr_Test-1] = &share({
        'ok'      => 1,
        actual_ok => 1,
        name      => '',
        type      => 'skip',
        reason    => $why,
    });

But for some reason &share() is returning an empty hash.

Elsewhere in the code &share() works fine as evidenced by pass() working.

0.47 did not tickle this threading bug.

Tested with 5.8.1RC3, 5.8.5 and bleadperl on OS X.

I've got a work around that involves a wrapper around share() to make a
copy of the variable to be shared, share it, then put the data back.

        require threads::shared;

        *share = sub (\[$@%]) {
            my $type = ref $_[0];
            my $data;

            if( $type eq 'HASH' ) {
                %$data = %{$_[0]};
            }
            elsif( $type eq 'ARRAY' ) {
                @$data = @{$_[0]};
            }
            elsif( $type eq 'SCALAR' ) {
                $$data = ${$_[0]};
            }
            else {
                die "Unknown type: ".$type;
            }

            $_[0] = &threads::shared::share($_[0]);

            if( $type eq 'HASH' ) {
                %{$_[0]} = %$data;
            }
            elsif( $type eq 'ARRAY' ) {
                @{$_[0]} = @$data;
            }
            elsif( $type eq 'SCALAR' ) {
                ${$_[0]} = $$data;
            }
            else {
                die "Unknown type: ".$type;
            }

            return $_[0];
        };

Bleh.


-- 
Michael G Schwern        schwern@pobox.com  http://www.pobox.com/~schwern/
Kindly do not attempt to cloud the issue with facts.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About