Subject: | [PATCH] Stop skipping SvROK handling for all magical scalars (fixes 67105 and 79730) |
Hi there!
upon a more thorough discussion of the bug present in 79730 with Florian
Ragwitz (rafl), he was able to spot and fix the issue. As his commit
message states, when using clone() on references with (non-tie, as
references can't be tied) magic attached, the actual cloning of the
referent has been skipped as magic_ref indicated that it should be.
magic_ref appears to only have been intended to track whether or not a
scalar is tied so the contents of the tied structure aren't cloned.
However, it actually tracked whether or not a scalar had any kind of
magic attached. That is wrong, and this commit fixes it, making
t/08fieldhash.t pass in the process.
Both a patch and a new test file are attached to this message. After
applied, all tests still pass, plus the new one (which fails if this
patch is not applied).
Hope this helps!
Subject: | clone_patch_2_of_2.patch |
From 2ee5b4e9ad653bbf194359857c0fe61eaab0e9be Mon Sep 17 00:00:00 2001
From: Florian Ragwitz <rafl@debian.org>
Date: Mon, 15 Oct 2012 09:34:07 -0300
Subject: [PATCH 2/2] Stop skipping SvROK handling for all magical scalars
Previously, for references with (non-tie, as references can't be tied) magic
attached, cloning of the referent has been skipped as magic_ref indicated that
it should be.
magic_ref appears to only have been intended to track whether or not a scalar is
tied so the contents of the tied structure aren't cloned. However, it actually
tracked whether or not a scalar had any kind of magic attached. That is wrong,
and this commit fixes it, making t/08fieldhash.t pass in the process.
---
Clone.xs | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/Clone.xs b/Clone.xs
index df975e6..1720e53 100755
--- a/Clone.xs
+++ b/Clone.xs
@@ -253,13 +253,17 @@ sv_clone (SV * ref, HV* hseen, int depth)
case '@': /* PERL_MAGIC_arylen_p */
continue;
break;
+ case 'P': /* PERL_MAGIC_tied */
+ case 'p': /* PERL_MAGIC_tiedelem */
+ case 'q': /* PERL_MAGIC_tiedscalar */
+ magic_ref++;
+ /* fall through */
default:
obj = sv_clone(mg->mg_obj, hseen, -1);
}
} else {
TRACEME(("magic object for type %c in NULL\n", mg->mg_type));
}
- magic_ref++;
/* this is plain old magic, so do the same thing */
sv_magic(clone,
obj,
--
1.7.10.4
Subject: | clone_patch_1_of_2.patch |
From 00c24379baac4fc883cdec7c6fce12a10a02865b Mon Sep 17 00:00:00 2001
From: Florian Ragwitz <rafl@debian.org>
Date: Mon, 15 Oct 2012 09:33:57 -0300
Subject: [PATCH 1/2] Add a failing tests for cloning elements of fieldhashes
---
t/08fieldhash.t | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
create mode 100644 t/08fieldhash.t
diff --git a/t/08fieldhash.t b/t/08fieldhash.t
new file mode 100644
index 0000000..6c5974c
--- /dev/null
+++ b/t/08fieldhash.t
@@ -0,0 +1,19 @@
+# $Id: 07magic.t,v 1.8 2007/04/20 05:40:48 ray Exp $
+
+use strict;
+use warnings;
+use Test::More;
+
+use Clone 'clone';
+use Hash::Util::FieldHash 'fieldhash';
+
+fieldhash my %hash;
+
+my $var = {};
+
+exists $hash{ \$var };
+
+my $cloned = clone($var);
+cmp_ok($cloned, '!=', $var);
+
+done_testing;
--
1.7.10.4