Skip Menu |

This queue is for tickets about the Clone CPAN distribution.

Report information
The Basics
Id: 11997
Status: resolved
Priority: 0/
Queue: Clone

People
Owner: Nobody in particular
Requestors: adamk [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.15
Fixed in: (no value)



Subject: Clone dies horribly when Scalar::Util::weaken is around
Clone and Scalar::Util::weaken are absolutely fatal to each other. The most canonical example I can produce so far is: perl -MClone=clone -MScalar::Util=weaken -wle '$x = { a => "worked\n" }; $y = $x; weaken($y); print clone($x)->{a};' When this runs, it fails to clone, generating only an empty hashref, then when the scope ends, it panics perl.
From the look of it, once $y is weakened, the hash gets a magic back-reference attached to it. Before the weakening of $y DB<5> Dump($x) SV = RV(0x817be1c) at 0x816329c REFCNT = 1 FLAGS = (ROK) RV = 0x8163350 SV = PVHV(0x84cdbf8) at 0x8163350 REFCNT = 2 FLAGS = (SHAREKEYS) IV = 1 NV = 0 ARRAY = 0x82f65d0 (0:7, 1:1) hash quality = 100.0% KEYS = 1 FILL = 1 MAX = 7 RITER = -1 EITER = 0x0 Elt "a" HASH = 0xca2e9442 SV = PV(0x814cea4) at 0x81633a4 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x8164990 "worked\n"\0 CUR = 7 LEN = 8 After the weakening of $y DB<6> Dump($x) SV = RV(0x817be1c) at 0x816329c REFCNT = 1 FLAGS = (ROK) RV = 0x8163350 SV = PVHV(0x84cdbf8) at 0x8163350 REFCNT = 1 FLAGS = (RMG,SHAREKEYS) IV = 1 NV = 0 MAGIC = 0x8574020 MG_VIRTUAL = &PL_vtbl_backref MG_TYPE = PERL_MAGIC_backref(<) MG_FLAGS = 0x02 REFCOUNTED MG_OBJ = 0x8525484 SV = PVAV(0x84c4a54) at 0x8525484 REFCNT = 2 FLAGS = () IV = 0 NV = 0 ARRAY = 0x84aafb8 FILL = 0 MAX = 3 ARYLEN = 0x0 FLAGS = (REAL) Elt No. 0 SV = RV(0x817be58) at 0x81632cc REFCNT = 1 FLAGS = (ROK,WEAKREF,IsUV) RV = 0x8163350 SV = PVHV(0x84cdbf8) at 0x8163350 REFCNT = 1 FLAGS = (RMG,SHAREKEYS) IV = 1 NV = 0 MAGIC = 0x8574020 MG_VIRTUAL = &PL_vtbl_backref MG_TYPE = PERL_MAGIC_backref(<) MG_FLAGS = 0x02 REFCOUNTED MG_OBJ = 0x8525484 SV = PVAV(0x84c4a54) at 0x8525484 REFCNT = 2 FLAGS = () IV = 0 NV = 0 ARRAY = 0x84aafb8 FILL = 0 MAX = 3 ARYLEN = 0x0 FLAGS = (REAL) ARRAY = 0x82f65d0 (0:7, 1:1) hash quality = 100.0% KEYS = 1 FILL = 1 MAX = 7 RITER = -1 EITER = 0x0 ARRAY = 0x82f65d0 (0:7, 1:1) hash quality = 100.0% KEYS = 1 FILL = 1 MAX = 7 RITER = -1 EITER = 0x0 Elt "a" HASH = 0xca2e9442 SV = PV(0x814cea4) at 0x81633a4 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x8164990 "worked\n"\0 CUR = 7 LEN = 8 The #perl channel recommends taking the cloning code from sv.c to handle the various types of SV cloning that you don't current handle. Specifically (in my case) that for PERL_MAGIC_backref(<)
Hi, I just uploaded a new version that has a fix for the MAGIC_backref problem. Looking at the perl code there are other cases that will probably fail as well. In my copious free time, I'll have to come up with some test cases and a better way to handle the magic.