Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weakened refs always clone as undef [rt.cpan.org #113033] #15

Open
atoomic opened this issue Oct 25, 2018 · 1 comment
Open

Weakened refs always clone as undef [rt.cpan.org #113033] #15

atoomic opened this issue Oct 25, 2018 · 1 comment

Comments

@atoomic
Copy link
Collaborator

atoomic commented Oct 25, 2018

Migrated from rt.cpan.org#113033 (status was 'new')

Requestors:

From [email protected] on 2016-03-15 06:36:21:

Hi,

Your very-useful module Clone does not seem to handle weakened refs:
They always clone as undef.

Please run the test script below to see the problem.
(bug observed in Clone version 0.38, the latest in CPAN)

Thanks,
-Jim Avera

P.S. The author email in the source ([email protected]) bounced.
#!/usr/bin/perl
use strict; use warnings;

package Parent;
sub new { bless { children => [] }, shift }

package Child;
use Scalar::Util qw(weaken);

sub new {
   my ($class, $parent) = @_;
   my $child = bless { parent => $parent }, $class;
   weaken($child->{parent});  ### COMMENT OUT TO REMOVE BUG
   push @{ $parent->{children} }, $child;
   return $child;
}

package main;
use Data::Dumper;
use Clone qw(clone);

my $p = Parent->new(foo => 123, bar => 456);
my $c = Child->new($p);
my $c_clone = clone($c);

warn Data::Dumper->Dump([$c], ["c"]);
warn Data::Dumper->Dump([$c_clone], ["c_clone"]);

die "bug" if ! defined $c->{parent};
die "bug" if ! defined $c_clone->{parent};
@atoomic
Copy link
Collaborator Author

atoomic commented Oct 25, 2018

I think this would be very good to detect/fix

atoomic added a commit to atoomic/Clone that referenced this issue Oct 29, 2018
Resolves GH garu#15

Provide one extra unit test to cover the testcase described
in GH garu#15 via t/weakened-ref.t.

Adjust t/06refcnt.t to also check REFCNT.
atoomic added a commit to atoomic/Clone that referenced this issue Oct 29, 2018
Resolves GH garu#15

Provide one extra unit test to cover the testcase described
in GH garu#15 via t/weakened-ref.t.

Adjust t/06refcnt.t to also check REFCNT.
atoomic added a commit to atoomic/Clone that referenced this issue Oct 29, 2018
Resolves GH garu#15

Provide one extra unit test to cover the testcase described
in GH garu#15 via t/weakened-ref.t.

Adjust t/06refcnt.t to also check REFCNT.
atoomic added a commit to atoomic/Clone that referenced this issue Oct 30, 2018
As part of the work for GH garu#15 via GH garu#23
the t/06refcnt.t was improved, and it should
deserve its own commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant