Codebase list libclone-perl / 1b69ed2
[svn-upgrade] Integrating new upstream version, libclone-perl (0.28) Gregor Herrmann 16 years ago
7 changed file(s) with 120 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
00 Revision history for Perl extension Clone.
11
22 $Log: Changes,v $
3 Revision 0.26 2007-10-15 04:52:42 ray
4 Made a change in CLONE_KEY to the way Clone stores refs in the ref hash.
5 Perl no longer uses the SvANY part of the SV struct in the same way which
6 meams the old way of storing the hash key is no longer unique.
7 Thanks to Slaven Rezic for the patch.
8
9 Revision 0.25 2007-07-25 03:41:04 ray
10 Latest patch from Ruslan Zakirov. Patched another memory leak.
11
12 Revision 0.24 2007-07-25 03:33:57 ray
13 Bug fix for 5.9.*, for some reason the 'visible' logic is no longer working.
14 I #if 'ed it out until I figure out what is going on.
15 Also removed an old redundant CLONE_STORE, could have been the cause of some
16 memory leaks.
17
18 Revision 0.23 2007-04-20 05:40:27 ray
19 Applied patch so clone will contiue to work with newer perls.
20 Also fixed test to work with older perls.
21
322 Revision 0.22 2006-10-08 05:35:19 ray
423 D'oh! The 0.21 tardist that I just uploaded to CPAN contained the 0.20 Clone.xs file. This release is just in case any of the 0.21 releases get mirrored.
524
0 # $Id: Clone.pm,v 0.22 2006-10-08 05:35:19 ray Exp $
0 # $Id: Clone.pm,v 0.28 2007-10-15 04:52:42 ray Exp $
11 package Clone;
22
33 use strict;
1515 @EXPORT = qw();
1616 @EXPORT_OK = qw( clone );
1717
18 $VERSION = '0.22';
18 $VERSION = '0.28';
1919
2020 bootstrap Clone $VERSION;
2121
33 #include "perl.h"
44 #include "XSUB.h"
55
6 static char *rcs_id = "$Id: Clone.xs,v 0.21 2006-10-08 04:02:56 ray Exp $";
7
8 #define CLONE_KEY(x) ((char *) x)
6 static char *rcs_id = "$Id: Clone.xs,v 0.27 2007-10-15 04:52:42 ray Exp $";
7
8 #define CLONE_KEY(x) ((char *) &x)
99
1010 #define CLONE_STORE(x,y) \
1111 do { \
7474
7575 TRACEME(("ref = 0x%x(%d)\n", ref, SvREFCNT(ref)));
7676
77 if (SvREFCNT(ref) > 1)
78 CLONE_STORE(ref, (SV *)clone);
77 /* The following is a holdover from a very old version */
78 /* possible cause of memory leaks */
79 /* if ( (SvREFCNT(ref) > 1) ) */
80 /* CLONE_STORE(ref, (SV *)clone); */
7981
8082 arrlen = av_len (self);
8183 av_extend (clone, arrlen);
9698 {
9799 SV *clone = NULL;
98100 SV *rv = NULL;
99 UV visible = (SvREFCNT(ref) > 1);
100101
101102 assert(SvROK(ref));
102103
122123 {
123124 SV *clone = ref;
124125 SV **seen = NULL;
125 UV visible = (SvREFCNT(ref) > 1);
126 #if PERL_REVISION >= 5 && PERL_VERSION > 8
127 /* This is a hack for perl 5.9.*, save everything */
128 /* until I find out why mg_find is no longer working */
129 UV visible = 1;
130 #else
131 UV visible = (SvREFCNT(ref) > 1) || (SvMAGICAL(ref) && mg_find(ref, '<'));
132 #endif
126133 int magic_ref = 0;
127134
128135 TRACEME(("ref = 0x%x(%d)\n", ref, SvREFCNT(ref)));
151158 break;
152159 case SVt_RV: /* 3 */
153160 TRACEME(("ref scalar\n"));
154 clone = NEWSV(1002, 0);
155 sv_upgrade(clone, SVt_RV);
156 /* move the following to SvROK section below */
157 /* SvROK_on(clone); */
161 clone = newSVsv (ref);
158162 break;
159163 case SVt_PV: /* 4 */
160164 TRACEME(("string scalar\n"));
176180 case SVt_PVHV: /* 11 */
177181 clone = (SV *) newHV();
178182 break;
183 #if PERL_VERSION <= 8
179184 case SVt_PVBM: /* 8 */
185 #endif
180186 case SVt_PVLV: /* 9 */
181187 case SVt_PVCV: /* 12 */
182188 case SVt_PVGV: /* 13 */
270276 /* 3: REFERENCE (inlined for speed) */
271277 else if (SvROK (ref))
272278 {
273 SvROK_on(clone); /* only set if ROK is set if ref */
274279 TRACEME(("clone = 0x%x(%d)\n", clone, SvREFCNT(clone)));
280 SvREFCNT_dec(SvRV(clone));
275281 SvRV(clone) = sv_clone (SvRV(ref), depth); /* Clone the referent */
276282 if (sv_isobject (ref))
277283 {
278284 sv_bless (clone, SvSTASH (SvRV (ref)));
285 }
286 if (SvWEAKREF(ref)) {
287 sv_rvweaken(clone);
279288 }
280289 }
281290
00 # http://module-build.sourceforge.net/META-spec.html
11 #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
22 name: Clone
3 version: 0.22
3 version: 0.28
44 version_from: Clone.pm
55 installdirs: site
66 requires:
00 use ExtUtils::MakeMaker;
1 # $Id: Makefile.PL,v 0.18 2006-10-08 03:37:20 ray Exp $
1 # $Id: Makefile.PL,v 0.19 2007-10-15 04:57:20 ray Exp $
22 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
33 # the contents of the Makefile that is written.
44 WriteMakefile(
99 'INC' => '', # e.g., '-I/usr/include/other'
1010 # 'OPTIMIZE' => '-g', # e.g., '-I/usr/include/other'
1111 'OPTIMIZE' => '-O3', # e.g., '-I/usr/include/other'
12 clean => {FILES => '_Inline'},
1213 );
1314
0 # $Id: 06refcnt.t,v 0.18 2006-10-08 03:37:29 ray Exp $
0 # $Id: 06refcnt.t,v 0.22 2007-07-25 03:41:06 ray Exp $
11 # Before `make install' is performed this script should be runnable with
22 # `make test'. After `make install' it should work as `perl test.pl'
33
66 # Change 1..1 below to 1..last_test_to_print .
77 # (It may become useful if the test is moved to ./t subdirectory.)
88
9 BEGIN { $| = 1; print "1..9\n"; }
9 BEGIN { $| = 1; print "1..20\n"; }
1010 END {print "not ok 1\n" unless $loaded;}
1111 use Clone qw( clone );
1212 $loaded = 1;
2020
2121 # code to test for memory leaks
2222
23 use Benchmark;
23 ## use Benchmark;
2424 use Data::Dumper;
2525 # use Storable qw( dclone );
2626
27 $^W = 0;
27 $^W = 1;
2828 $test = 2;
2929
3030 sub ok { printf("ok %d\n", $test++); }
8282 bless $a, 'Test::Hash';
8383 bless $b, 'Test::Hash';
8484 }
85
86 # test for cloning ref that was an int(IV)
87 {
88 my $a = 1;
89 $a = [];
90 my $b = clone($a);
91 bless $a, 'Test::Hash';
92 bless $b, 'Test::Hash';
93 }
94
95 # test for cloning ref that was a string(PV)
96 {
97 my $a = '';
98 $a = [];
99 my $b = clone($a);
100 bless $a, 'Test::Hash';
101 bless $b, 'Test::Hash';
102 }
103
104 # test for cloning ref that was a magic(PVMG)
105 {
106 my $a = *STDOUT;
107 $a = [];
108 my $b = clone($a);
109 bless $a, 'Test::Hash';
110 bless $b, 'Test::Hash';
111 }
112
113 # test for cloning weak reference
114 {
115 use Scalar::Util qw(weaken isweak);
116 my $a = new Test::Hash();
117 my $b = { r => $a };
118 $a->{r} = $b;
119 weaken($b->{'r'});
120 my $c = clone($a);
121 }
122
123 # another weak reference problem, this one causes a segfault in 0.24
124 {
125 use Scalar::Util qw(weaken isweak);
126 my $a = new Test::Hash();
127 {
128 my $b = [ $a, $a ];
129 $a->{r} = $b;
130 weaken($b->[0]);
131 weaken($b->[1]);
132 }
133 my $c = clone($a);
134 # check that references point to the same thing
135 print "not " unless $c->{'r'}[0] == $c->{'r'}[1];
136 printf "ok %d\n", $::test++;
137 }
0 # $Id: 07magic.t,v 1.7 2006-10-08 05:25:23 ray Exp $
0 # $Id: 07magic.t,v 1.8 2007-04-20 05:40:48 ray Exp $
11
22 use strict;
33
1818 my $z = Clone::clone($x);
1919 ok( Dumper($x) eq Dumper($z), "Cloned weak reference");
2020 }
21
22 ## RT 21859: Clone segfault (isolated example)
23 SKIP: {
24 my $string = "HDDR-WD-250JS";
25 eval {
26 use utf8;
27 utf8::upgrade($string);
28 };
29 skip $@, 1 if $@;
30 $string = sprintf ('<<bg_color=%s>>%s<</bg_color>>%s',
31 '#EA0',
32 substr ($string, 0, 4),
33 substr ($string, 4),
34 );
35 my $z = Clone::clone($string);
36 ok( Dumper($string) eq Dumper($z), "Cloned magic utf8");
37 }
2138 }
2239
2340 SKIP: {
3552 ok( Dumper($x) eq Dumper($y), "Tainted input");
3653 }
3754
38 ## RT 21859: Clone segfault (isolated example)
39 SKIP: {
40 eval "use utf8";
41 skip "error in use utf8", 1 if $@;
42 my $string = "HDDR-WD-250JS";
43 utf8::upgrade($string);
44 $string = sprintf ('<<bg_color=%s>>%s<</bg_color>>%s',
45 '#EA0',
46 substr ($string, 0, 4),
47 substr ($string, 4),
48 );
49 print $string, "\n";
50 my $z = Clone::clone($string);
51 ok( 1, "At least it didn't segfault!");
52 }