Skip to content

Commit 3d1d3ff

Browse files
author
jdhedden
committed
threads-shared v1.48
1 parent 1e79896 commit 3d1d3ff

File tree

9 files changed

+208
-105
lines changed

9 files changed

+208
-105
lines changed

Changes

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
Revision history for Perl extension threads::shared.
22

3-
1.46 Tue Feb 4 21:48:51 2014
4-
- Sync from blead that fixes a thread context issue
5-
6-
1.45 Wed Nov 13 15:27:09 2013
7-
- Sync from blead
8-
9-
1.44 Wed Nov 13 15:21:08 2013
10-
- Sync from blead (not released on CPAN)
3+
-
4+
- Fix for when freeing elements with $#shared = N to trigger shared object destruction
115

126
1.43 Fri Jan 11 15:49:59 2013
137
- Timeout fix for t/stress.t (Nicholas Clark)

Makefile.PL

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ WriteMakefile(
6767
'Scalar::Util' => 0,
6868
'threads' => 1.73,
6969

70+
'Test' => 0,
7071
'Test::More' => 0,
7172
'ExtUtils::testlib' => 0,
7273
},

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
threads::shared version 1.46
1+
threads::shared version 1.48
22
============================
33

44
This module needs Perl 5.8.0 or later compiled with USEITHREADS.

lib/threads/shared.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use warnings;
77

88
use Scalar::Util qw(reftype refaddr blessed);
99

10-
our $VERSION = '1.46'; # Please update the pod, too.
10+
our $VERSION = '1.48'; # Please update the pod, too.
1111
my $XS_VERSION = $VERSION;
1212
$VERSION = eval $VERSION;
1313

@@ -195,7 +195,7 @@ threads::shared - Perl extension for sharing data structures between threads
195195
196196
=head1 VERSION
197197
198-
This document describes threads::shared version 1.46
198+
This document describes threads::shared version 1.48
199199
200200
=head1 SYNOPSIS
201201

shared.xs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
/*
137137
* The shared things need an interpreter to live in ...
138138
*/
139-
PerlInterpreter *PL_sharedsv_space; /* The shared sv space */
139+
static PerlInterpreter *PL_sharedsv_space; /* The shared sv space */
140140
/* To access shared space we fake aTHX in this scope and thread's context */
141141

142142
/* Bug #24255: We include ENTER+SAVETMPS/FREETMPS+LEAVE with
@@ -177,7 +177,7 @@ typedef struct {
177177
#endif
178178
} recursive_lock_t;
179179

180-
recursive_lock_t PL_sharedsv_lock; /* Mutex protecting the shared sv space */
180+
static recursive_lock_t PL_sharedsv_lock; /* Mutex protecting the shared sv space */
181181

182182
void
183183
recursive_lock_init(pTHX_ recursive_lock_t *lock)
@@ -291,7 +291,7 @@ sharedsv_userlock_free(pTHX_ SV *sv, MAGIC *mg)
291291
return (0);
292292
}
293293

294-
MGVTBL sharedsv_userlock_vtbl = {
294+
static const MGVTBL sharedsv_userlock_vtbl = {
295295
0, /* get */
296296
0, /* set */
297297
0, /* len */
@@ -332,10 +332,10 @@ MGVTBL sharedsv_userlock_vtbl = {
332332
the shared thing.
333333
*/
334334

335-
extern MGVTBL sharedsv_scalar_vtbl; /* Scalars have this vtable */
336-
extern MGVTBL sharedsv_array_vtbl; /* Hashes and arrays have this
335+
extern const MGVTBL sharedsv_scalar_vtbl; /* Scalars have this vtable */
336+
extern const MGVTBL sharedsv_array_vtbl; /* Hashes and arrays have this
337337
- like 'tie' */
338-
extern MGVTBL sharedsv_elem_vtbl; /* Elements of hashes and arrays have
338+
extern const MGVTBL sharedsv_elem_vtbl; /* Elements of hashes and arrays have
339339
this _AS WELL AS_ the scalar magic:
340340
The sharedsv_elem_vtbl associates the element with the array/hash and
341341
the sharedsv_scalar_vtbl associates it with the value
@@ -878,7 +878,7 @@ sharedsv_scalar_mg_local(pTHX_ SV* nsv, MAGIC *mg)
878878
}
879879
#endif
880880

881-
MGVTBL sharedsv_scalar_vtbl = {
881+
const MGVTBL sharedsv_scalar_vtbl = {
882882
sharedsv_scalar_mg_get, /* get */
883883
sharedsv_scalar_mg_set, /* set */
884884
0, /* len */
@@ -1039,7 +1039,7 @@ sharedsv_elem_mg_dup(pTHX_ MAGIC *mg, CLONE_PARAMS *param)
10391039
return (0);
10401040
}
10411041

1042-
MGVTBL sharedsv_elem_vtbl = {
1042+
const MGVTBL sharedsv_elem_vtbl = {
10431043
sharedsv_elem_mg_FETCH, /* get */
10441044
sharedsv_elem_mg_STORE, /* set */
10451045
0, /* len */
@@ -1152,7 +1152,7 @@ sharedsv_array_mg_dup(pTHX_ MAGIC *mg, CLONE_PARAMS *param)
11521152
return (0);
11531153
}
11541154

1155-
MGVTBL sharedsv_array_vtbl = {
1155+
const MGVTBL sharedsv_array_vtbl = {
11561156
0, /* get */
11571157
0, /* set */
11581158
sharedsv_array_mg_FETCHSIZE,/* len */
@@ -1371,9 +1371,29 @@ void
13711371
STORESIZE(SV *obj,IV count)
13721372
CODE:
13731373
dTHXc;
1374-
SV *sobj = SHAREDSV_FROM_OBJ(obj);
1374+
SV *ssv = SHAREDSV_FROM_OBJ(obj);
1375+
13751376
SHARED_EDIT;
1376-
av_fill((AV*) sobj, count);
1377+
assert(SvTYPE(ssv) == SVt_PVAV);
1378+
if (!PL_dirty) {
1379+
SV **svp = AvARRAY((AV *)ssv);
1380+
I32 ix = AvFILLp((AV *)ssv);
1381+
for (;ix >= count; ix--) {
1382+
SV *sv = svp[ix];
1383+
if (!sv)
1384+
continue;
1385+
if ( (SvOBJECT(sv) || (SvROK(sv) && (sv = SvRV(sv))))
1386+
&& SvREFCNT(sv) == 1 )
1387+
{
1388+
SV *tmp = Perl_sv_newmortal(caller_perl);
1389+
PERL_SET_CONTEXT((aTHX = caller_perl));
1390+
sv_upgrade(tmp, SVt_RV);
1391+
get_RV(tmp, sv);
1392+
PERL_SET_CONTEXT((aTHX = PL_sharedsv_space));
1393+
}
1394+
}
1395+
}
1396+
av_fill((AV*) ssv, count - 1);
13771397
SHARED_RELEASE;
13781398

13791399

t/av_simple.t

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ sub ok {
2727

2828
BEGIN {
2929
$| = 1;
30-
print("1..44\n"); ### Number of tests that will be run ###
30+
print("1..47\n"); ### Number of tests that will be run ###
3131
};
3232

3333
use threads;
@@ -130,6 +130,16 @@ ok(37, !defined delete($foo[0]), "Check that delete works from a thread");
130130

131131
ok(44, is_shared(@foo), "Check for sharing");
132132

133+
# RT #122950
134+
135+
@foo = ('a'..'z');
136+
$#foo = 2;
137+
138+
ok(45, $#foo == 2, "\$#foo assignment: \$#");
139+
ok(46, @foo == 3, "\$#foo assignment: scalar");
140+
ok(47, "@foo" eq "a b c", "\$#foo assignment: array interpolation");
141+
142+
133143
exit(0);
134144

135145
# EOF

t/hv_refs.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ ok(8, threads::shared::_id($$gg) == threads::shared::_id($$gg2),
6363
sprintf("Check we get the same thing (%x vs %x)",
6464
threads::shared::_id($$gg),threads::shared::_id($$gg2)));
6565
ok(9, $$gg eq $$gg2, "And check the values are the same");
66-
ok(10, keys %foo == 0, "And make sure we realy have deleted the values");
66+
ok(10, keys %foo == 0, "And make sure we really have deleted the values");
6767
{
6868
my (%hash1, %hash2);
6969
share(%hash1);

t/object2.t

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use ExtUtils::testlib;
1717

1818
BEGIN {
1919
$| = 1;
20-
print("1..122\n"); ### Number of tests that will be run ###
20+
print("1..131\n"); ### Number of tests that will be run ###
2121
};
2222

2323
use threads;
@@ -406,4 +406,45 @@ ok($destroyed[$ID], 'Scalar object removed from undef shared hash');
406406
}
407407
ok($destroyed[$ID], 'Scalar object removed from shared scalar');
408408

409+
#
410+
# RT #122950 abandoning array elements (e.g. by setting $#ary)
411+
# should trigger destructors
412+
413+
{
414+
package rt122950;
415+
416+
my $count = 0;
417+
sub DESTROY { $count++ }
418+
419+
my $n = 4;
420+
421+
for my $type (0..1) {
422+
my @a : shared;
423+
$count = 0;
424+
push @a, bless &threads::shared::share({}) for 1..$n;
425+
for (1..$n) {
426+
{ # new scope to ensure tmps are freed, destructors called
427+
if ($type) {
428+
pop @a;
429+
}
430+
else {
431+
$#a = $n - $_ - 1;
432+
}
433+
}
434+
::ok($count == $_,
435+
"remove array object $_ by " . ($type ? "pop" : '$#a=N'));
436+
}
437+
}
438+
439+
my @a : shared;
440+
$count = 0;
441+
push @a, bless &threads::shared::share({}) for 1..$n;
442+
{
443+
undef @a; # this is implemented internally as $#a = -01
444+
}
445+
::ok($count == $n, "remove array object by undef");
446+
}
447+
448+
449+
409450
# EOF

0 commit comments

Comments
 (0)