Skip to content

Commit b5816b8

Browse files
committed
switch_locale_context: Add aTHX
This fixes GH #21040 Instead of a dTHX, this passes aTHX automatically, and skips calling this function if there is no valid context. It moves that decision into the macro itself, avoiding some #ifdef directives.
1 parent 6bbe21a commit b5816b8

File tree

7 files changed

+17
-22
lines changed

7 files changed

+17
-22
lines changed

dist/threads/lib/threads.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use 5.008;
55
use strict;
66
use warnings;
77

8-
our $VERSION = '2.36'; # remember to update version in POD!
8+
our $VERSION = '2.37'; # remember to update version in POD!
99
my $XS_VERSION = $VERSION;
1010
$VERSION = eval $VERSION;
1111

@@ -134,7 +134,7 @@ threads - Perl interpreter-based threads
134134
135135
=head1 VERSION
136136
137-
This document describes threads version 2.36
137+
This document describes threads version 2.37
138138
139139
=head1 WARNING
140140

dist/threads/threads.xs

-2
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,7 @@ S_ithread_set(pTHX_ ithread *thread)
205205
{
206206
dMY_CXT;
207207
MY_CXT.context = thread;
208-
#ifdef PERL_SET_NON_tTHX_CONTEXT
209208
PERL_SET_NON_tTHX_CONTEXT(thread->interp);
210-
#endif
211209
}
212210

213211
STATIC ithread *

embed.fnc

+1-1
Original file line numberDiff line numberDiff line change
@@ -6153,7 +6153,7 @@ Adhp |SSize_t|PerlIO_write |NULLOK PerlIO *f \
61536153
|Size_t count
61546154
#endif /* defined(USE_PERLIO) */
61556155
#if defined(USE_PERL_SWITCH_LOCALE_CONTEXT)
6156-
CTop |void |switch_locale_context
6156+
Cop |void |switch_locale_context
61576157
#endif
61586158
#if defined(USE_QUADMATH)
61596159
Tdp |bool |quadmath_format_needed \

locale.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -7210,7 +7210,7 @@ S_my_setlocale_debug_string_i(pTHX_
72107210
#ifdef USE_PERL_SWITCH_LOCALE_CONTEXT
72117211

72127212
void
7213-
Perl_switch_locale_context()
7213+
Perl_switch_locale_context(pTHX)
72147214
{
72157215
/* libc keeps per-thread locale status information in some configurations.
72167216
* So, we can't just switch out aTHX to switch to a new thread. libc has
@@ -7219,10 +7219,7 @@ Perl_switch_locale_context()
72197219

72207220
/* Can't use pTHX, because we may be called from a place where that
72217221
* isn't available */
7222-
dTHX;
7223-
7224-
if (UNLIKELY( aTHX == NULL
7225-
|| PL_veto_switch_non_tTHX_context
7222+
if (UNLIKELY( PL_veto_switch_non_tTHX_context
72267223
|| PL_phase == PERL_PHASE_CONSTRUCT))
72277224
{
72287225
return;

perl.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -6366,20 +6366,20 @@ EXTCONST U8 PL_deBruijn_bitpos_tab64[];
63666366
# define PERL_SET_LOCALE_CONTEXT(i) \
63676367
STMT_START { \
63686368
if (LIKELY(! PL_veto_switch_non_tTHX_context)) \
6369-
Perl_switch_locale_context(); \
6369+
Perl_switch_locale_context(i); \
63706370
} STMT_END
6371+
6372+
/* In some Configurations there may be per-thread information that is
6373+
* carried in a library instead of perl's tTHX structure. This macro is to
6374+
* be used to handle those when tTHX is changed. Only locale handling is
6375+
* currently known to be affected. */
6376+
# define PERL_SET_NON_tTHX_CONTEXT(i) \
6377+
STMT_START { if (i) PERL_SET_LOCALE_CONTEXT(i); } STMT_END
63716378
#else
6372-
# define PERL_SET_LOCALE_CONTEXT(i) NOOP
6379+
# define PERL_SET_LOCALE_CONTEXT(i) NOOP
6380+
# define PERL_SET_NON_tTHX_CONTEXT(i) NOOP
63736381
#endif
63746382

6375-
/* In some Configurations there may be per-thread information that is carried
6376-
* in a library instead of perl's tTHX structure. This macro is to be used to
6377-
* handle those when tTHX is changed. Only locale handling is currently known
6378-
* to be affected. */
6379-
#define PERL_SET_NON_tTHX_CONTEXT(i) \
6380-
STMT_START { PERL_SET_LOCALE_CONTEXT(i); } STMT_END
6381-
6382-
63836383
#ifndef PERL_GET_CONTEXT
63846384
# define PERL_GET_CONTEXT PERL_GET_INTERP
63856385
#endif

proto.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

util.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3591,7 +3591,7 @@ Perl_set_context(void *t)
35913591
}
35923592
# endif
35933593

3594-
PERL_SET_NON_tTHX_CONTEXT(t);
3594+
PERL_SET_NON_tTHX_CONTEXT((PerlInterpreter *) t);
35953595

35963596
#else
35973597
PERL_UNUSED_ARG(t);

0 commit comments

Comments
 (0)