Skip to content

Commit 0968cb8

Browse files
authored
Merge pull request #5 from Dual-Life/develop
1.57 Clang macros
2 parents 70dc7d3 + 8202861 commit 0968cb8

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

Changes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ Revision history for Perl extension threads::shared.
33
-
44
-
55

6+
1.57 Sun May 7 22:48:33 2017
7+
- Fix Clang macro backward compatibility per patch by Andy Grundman
8+
9+
1.56 Fri Apr 14 10:51:56 2017 +0100
10+
- RT #131124 Memory allocation fix (not released to CPAN)
11+
612
1.55 Sun Feb 26 18:23:45 2017
713
- Document issue with destructor not called on embedded shared objects
814

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
threads::shared version 1.55
1+
threads::shared version 1.57
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.55'; # Please update the pod, too.
10+
our $VERSION = '1.57'; # 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.55
198+
This document describes threads::shared version 1.57
199199
200200
=head1 SYNOPSIS
201201

shared.xs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -656,14 +656,15 @@ Perl_sharedsv_cond_timedwait(perl_cond *cond, perl_mutex *mut, double abs)
656656
abs -= (NV)ts.tv_sec;
657657
ts.tv_nsec = (long)(abs * 1000000000.0);
658658

659-
#if defined(__clang__) || defined(__clang)
659+
#if defined(CLANG_DIAG_IGNORE)
660660
CLANG_DIAG_IGNORE(-Wthread-safety);
661661
/* warning: calling function 'pthread_cond_timedwait' requires holding mutex 'mut' exclusively [-Wthread-safety-analysis] */
662662
#endif
663663

664664
switch (pthread_cond_timedwait(cond, mut, &ts)) {
665665

666-
#if defined(__clang__) || defined(__clang)
666+
/* perl.h defines CLANG_DIAG_* but only in 5.24+ */
667+
#if defined(CLANG_DIAG_RESTORE)
667668
CLANG_DIAG_RESTORE;
668669
#endif
669670

@@ -1104,8 +1105,9 @@ sharedsv_array_mg_CLEAR(pTHX_ SV *sv, MAGIC *mg)
11041105
if (!sv) continue;
11051106
if ( (SvOBJECT(sv) || (SvROK(sv) && (sv = SvRV(sv))))
11061107
&& SvREFCNT(sv) == 1 ) {
1107-
SV *tmp = Perl_sv_newmortal(caller_perl);
1108+
SV *tmp;
11081109
PERL_SET_CONTEXT((aTHX = caller_perl));
1110+
tmp = sv_newmortal();
11091111
sv_upgrade(tmp, SVt_RV);
11101112
get_RV(tmp, sv);
11111113
PERL_SET_CONTEXT((aTHX = PL_sharedsv_space));
@@ -1384,8 +1386,9 @@ STORESIZE(SV *obj,IV count)
13841386
if ( (SvOBJECT(sv) || (SvROK(sv) && (sv = SvRV(sv))))
13851387
&& SvREFCNT(sv) == 1 )
13861388
{
1387-
SV *tmp = Perl_sv_newmortal(caller_perl);
1389+
SV *tmp;
13881390
PERL_SET_CONTEXT((aTHX = caller_perl));
1391+
tmp = sv_newmortal();
13891392
sv_upgrade(tmp, SVt_RV);
13901393
get_RV(tmp, sv);
13911394
PERL_SET_CONTEXT((aTHX = PL_sharedsv_space));

t/object2.t

Lines changed: 23 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..131\n"); ### Number of tests that will be run ###
20+
print("1..133\n"); ### Number of tests that will be run ###
2121
};
2222

2323
use threads;
@@ -445,6 +445,28 @@ ok($destroyed[$ID], 'Scalar object removed from shared scalar');
445445
::ok($count == $n, "remove array object by undef");
446446
}
447447

448+
# RT #131124
449+
# Emptying a shared array creates new temp SVs. If there are no spare
450+
# SVs, a new arena is allocated. shared.xs was mallocing a new arena
451+
# with the wrong perl context set, meaning that when the arena was later
452+
# freed, it would "panic: realloc from wrong pool"
453+
#
454+
455+
{
456+
threads->new(sub {
457+
my @a :shared;
458+
push @a, bless &threads::shared::share({}) for 1..1000;
459+
undef @a; # this creates lots of temp SVs
460+
})->join;
461+
ok(1, "#131124 undef array doesnt panic");
462+
463+
threads->new(sub {
464+
my @a :shared;
465+
push @a, bless &threads::shared::share({}) for 1..1000;
466+
@a = (); # this creates lots of temp SVs
467+
})->join;
468+
ok(1, "#131124 clear array doesnt panic");
469+
}
448470

449471

450472
# EOF

0 commit comments

Comments
 (0)