Skip to content

Commit a44cad4

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 feaf661 commit a44cad4

File tree

6 files changed

+16
-22
lines changed

6 files changed

+16
-22
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
@@ -6176,7 +6176,7 @@ Adhp |SSize_t|PerlIO_write |NULLOK PerlIO *f \
61766176
|Size_t count
61776177
#endif /* defined(USE_PERLIO) */
61786178
#if defined(USE_PERL_SWITCH_LOCALE_CONTEXT)
6179-
CTop |void |switch_locale_context
6179+
Cop |void |switch_locale_context
61806180
#endif
61816181
#if defined(USE_QUADMATH)
61826182
Tdp |bool |quadmath_format_needed \

locale.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -9685,7 +9685,7 @@ S_my_setlocale_debug_string_i(pTHX_
96859685
#ifdef USE_PERL_SWITCH_LOCALE_CONTEXT
96869686

96879687
void
9688-
Perl_switch_locale_context()
9688+
Perl_switch_locale_context(pTHX)
96899689
{
96909690
/* libc keeps per-thread locale status information in some configurations.
96919691
* So, we can't just switch out aTHX to switch to a new thread. libc has
@@ -9694,10 +9694,7 @@ Perl_switch_locale_context()
96949694

96959695
/* Can't use pTHX, because we may be called from a place where that
96969696
* isn't available */
9697-
dTHX;
9698-
9699-
if (UNLIKELY( aTHX == NULL
9700-
|| PL_veto_switch_non_tTHX_context
9697+
if (UNLIKELY( PL_veto_switch_non_tTHX_context
97019698
|| PL_phase == PERL_PHASE_CONSTRUCT))
97029699
{
97039700
return;

perl.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -6493,21 +6493,21 @@ EXTCONST U8 PL_deBruijn_bitpos_tab64[];
64936493
#ifdef USE_PERL_SWITCH_LOCALE_CONTEXT
64946494
# define PERL_SET_LOCALE_CONTEXT(i) \
64956495
STMT_START { \
6496-
if (UNLIKELY(PL_veto_switch_non_tTHX_context)) \
6497-
Perl_switch_locale_context(); \
6496+
if (LIKELY(! PL_veto_switch_non_tTHX_context)) \
6497+
Perl_switch_locale_context(i); \
64986498
} STMT_END
6499+
6500+
/* In some Configurations there may be per-thread information that is
6501+
* carried in a library instead of perl's tTHX structure. This macro is to
6502+
* be used to handle those when tTHX is changed. Only locale handling is
6503+
* currently known to be affected. */
6504+
# define PERL_SET_NON_tTHX_CONTEXT(i) \
6505+
STMT_START { if (i) PERL_SET_LOCALE_CONTEXT(i); } STMT_END
64996506
#else
6500-
# define PERL_SET_LOCALE_CONTEXT(i) NOOP
6507+
# define PERL_SET_LOCALE_CONTEXT(i) NOOP
6508+
# define PERL_SET_NON_tTHX_CONTEXT(i) NOOP
65016509
#endif
65026510

6503-
/* In some Configurations there may be per-thread information that is carried
6504-
* in a library instead of perl's tTHX structure. This macro is to be used to
6505-
* handle those when tTHX is changed. Only locale handling is currently known
6506-
* to be affected. */
6507-
#define PERL_SET_NON_tTHX_CONTEXT(i) \
6508-
STMT_START { PERL_SET_LOCALE_CONTEXT(i); } STMT_END
6509-
6510-
65116511
#ifndef PERL_GET_CONTEXT
65126512
# define PERL_GET_CONTEXT PERL_GET_INTERP
65136513
#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)