Skip to content

Commit 35a0358

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 a3256a1 commit 35a0358

File tree

6 files changed

+15
-21
lines changed

6 files changed

+15
-21
lines changed

dist/threads/threads.xs

-3
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,7 @@ S_ithread_set(pTHX_ ithread *thread)
220220
dMY_CXT;
221221
DEBUG_U(PerlIO_printf(Perl_debug_log, "ithread_set about to set MY_CXT context to thread %p; tid=%ld\n", thread, thread->tid));
222222
MY_CXT.context = thread;
223-
#ifdef PERL_SET_NON_tTHX_CONTEXT
224223
PERL_SET_NON_tTHX_CONTEXT(thread->interp);
225-
DEBUG_U(PerlIO_printf(Perl_debug_log, "ithread_set just set MY_CXT context to thread\n"));
226-
#endif
227224
}
228225

229226
STATIC ithread *

embed.fnc

+1-1
Original file line numberDiff line numberDiff line change
@@ -6193,7 +6193,7 @@ Adhp |SSize_t|PerlIO_write |NULLOK PerlIO *f \
61936193
|Size_t count
61946194
#endif /* defined(USE_PERLIO) */
61956195
#if defined(USE_PERL_SWITCH_LOCALE_CONTEXT)
6196-
CTop |void |switch_locale_context
6196+
Cop |void |switch_locale_context
61976197
#endif
61986198
#if defined(USE_QUADMATH)
61996199
Tdp |bool |quadmath_format_needed \

locale.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -9844,7 +9844,7 @@ S_my_setlocale_debug_string_i(pTHX_
98449844
#ifdef USE_PERL_SWITCH_LOCALE_CONTEXT
98459845

98469846
void
9847-
Perl_switch_locale_context()
9847+
Perl_switch_locale_context(pTHX)
98489848
{
98499849
/* libc keeps per-thread locale status information in some configurations.
98509850
* So, we can't just switch out aTHX to switch to a new thread. libc has
@@ -9853,10 +9853,7 @@ Perl_switch_locale_context()
98539853

98549854
/* Can't use pTHX, because we may be called from a place where that
98559855
* isn't available */
9856-
dTHX;
9857-
9858-
if (UNLIKELY( aTHX == NULL
9859-
|| PL_veto_switch_non_tTHX_context
9856+
if (UNLIKELY( PL_veto_switch_non_tTHX_context
98609857
|| PL_phase == PERL_PHASE_CONSTRUCT))
98619858
/* ??? Xxx || ! PL_perl_controls_locale */
98629859
{

perl.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -6479,20 +6479,20 @@ EXTCONST U8 PL_deBruijn_bitpos_tab64[];
64796479
# define PERL_SET_LOCALE_CONTEXT(i) \
64806480
STMT_START { \
64816481
if (LIKELY(! PL_veto_switch_non_tTHX_context)) \
6482-
Perl_switch_locale_context(); \
6482+
Perl_switch_locale_context(i); \
64836483
} STMT_END
6484+
6485+
/* In some Configurations there may be per-thread information that is
6486+
* carried in a library instead of perl's tTHX structure. This macro is to
6487+
* be used to handle those when tTHX is changed. Only locale handling is
6488+
* currently known to be affected. */
6489+
# define PERL_SET_NON_tTHX_CONTEXT(i) \
6490+
STMT_START { if (i) PERL_SET_LOCALE_CONTEXT(i); } STMT_END
64846491
#else
6485-
# define PERL_SET_LOCALE_CONTEXT(i) NOOP
6492+
# define PERL_SET_LOCALE_CONTEXT(i) NOOP
6493+
# define PERL_SET_NON_tTHX_CONTEXT(i) NOOP
64866494
#endif
64876495

6488-
/* In some Configurations there may be per-thread information that is carried
6489-
* in a library instead of perl's tTHX structure. This macro is to be used to
6490-
* handle those when tTHX is changed. Only locale handling is currently known
6491-
* to be affected. */
6492-
#define PERL_SET_NON_tTHX_CONTEXT(i) \
6493-
STMT_START { PERL_SET_LOCALE_CONTEXT(i); } STMT_END
6494-
6495-
64966496
#ifndef PERL_GET_CONTEXT
64976497
# define PERL_GET_CONTEXT PERL_GET_INTERP
64986498
#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)