Skip to content

switch_locale_context: Add aTHX #21392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dist/threads/lib/threads.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use 5.008;
use strict;
use warnings;

our $VERSION = '2.38'; # remember to update version in POD!
our $VERSION = '2.39'; # remember to update version in POD!
my $XS_VERSION = $VERSION;
$VERSION = eval $VERSION;

Expand Down Expand Up @@ -134,7 +134,7 @@ threads - Perl interpreter-based threads

=head1 VERSION

This document describes threads version 2.38
This document describes threads version 2.39

=head1 WARNING

Expand Down
3 changes: 0 additions & 3 deletions dist/threads/threads.xs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,6 @@ S_ithread_set(pTHX_ ithread *thread)
{
dMY_CXT;
MY_CXT.context = thread;
#ifdef PERL_SET_NON_tTHX_CONTEXT
PERL_SET_NON_tTHX_CONTEXT(thread->interp);
#endif
}

STATIC ithread *
Expand Down
2 changes: 1 addition & 1 deletion embed.fnc
Original file line number Diff line number Diff line change
Expand Up @@ -6226,7 +6226,7 @@ Adhp |SSize_t|PerlIO_write |NULLOK PerlIO *f \
|Size_t count
#endif /* defined(USE_PERLIO) */
#if defined(USE_PERL_SWITCH_LOCALE_CONTEXT)
CTop |void |switch_locale_context
Cop |void |switch_locale_context
#endif
#if defined(USE_QUADMATH)
Tdp |bool |quadmath_format_needed \
Expand Down
35 changes: 27 additions & 8 deletions locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -8538,19 +8538,38 @@ S_my_setlocale_debug_string_i(pTHX_
#ifdef USE_PERL_SWITCH_LOCALE_CONTEXT

void
Perl_switch_locale_context()
Perl_switch_locale_context(pTHX)
{
/* libc keeps per-thread locale status information in some configurations.
* So, we can't just switch out aTHX to switch to a new thread. libc has
* to follow along. This routine does that based on per-interpreter
* variables we keep just for this purpose */

/* Can't use pTHX, because we may be called from a place where that
* isn't available */
dTHX;
* variables we keep just for this purpose.
*
* There are two implementations where this is an issue. For the other
* implementations, it doesn't matter because libc is using global values
* that all threads know about.
*
* The two implementations are where libc keeps thread-specific information
* on its own. These are
*
* POSIX 2008: The current locale is kept by libc as an object. We save
* a copy of that in the per-thread PL_cur_locale_obj, and so
* this routine uses that copy to tell the thread it should be
* operating with that object
* Windows thread-safe locales: A given thread in Windows can be being run
* with per-thread locales, or not. When the thread context
* changes, libc doesn't automatically know if the thread is
* using per-thread locales, nor does it know what the new
* thread's locale is. We keep that information in the
* per-thread variables:
* PL_controls_locale indicates if this thread is using
* per-thread locales or not
* PL_cur_LC_ALL indicates what the the locale
* should be if it is a per-thread
* locale.
*/

if (UNLIKELY( aTHX == NULL
|| PL_veto_switch_non_tTHX_context
if (UNLIKELY( PL_veto_switch_non_tTHX_context
|| PL_phase == PERL_PHASE_CONSTRUCT))
{
return;
Expand Down
22 changes: 11 additions & 11 deletions perl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6359,21 +6359,21 @@ EXTCONST U8 PL_deBruijn_bitpos_tab64[];
#ifdef USE_PERL_SWITCH_LOCALE_CONTEXT
# define PERL_SET_LOCALE_CONTEXT(i) \
STMT_START { \
if (UNLIKELY(PL_veto_switch_non_tTHX_context)) \
Perl_switch_locale_context(); \
if (LIKELY(! PL_veto_switch_non_tTHX_context)) \
Perl_switch_locale_context(i); \
} STMT_END

/* In some Configurations there may be per-thread information that is
* carried in a library instead of perl's tTHX structure. This macro is to
* be used to handle those when tTHX is changed. Only locale handling is
* currently known to be affected. */
# define PERL_SET_NON_tTHX_CONTEXT(i) \
STMT_START { if (i) PERL_SET_LOCALE_CONTEXT(i); } STMT_END
#else
# define PERL_SET_LOCALE_CONTEXT(i) NOOP
# define PERL_SET_LOCALE_CONTEXT(i) NOOP
# define PERL_SET_NON_tTHX_CONTEXT(i) NOOP
#endif

/* In some Configurations there may be per-thread information that is carried
* in a library instead of perl's tTHX structure. This macro is to be used to
* handle those when tTHX is changed. Only locale handling is currently known
* to be affected. */
#define PERL_SET_NON_tTHX_CONTEXT(i) \
STMT_START { PERL_SET_LOCALE_CONTEXT(i); } STMT_END


#ifndef PERL_GET_CONTEXT
# define PERL_GET_CONTEXT PERL_GET_INTERP
#endif
Expand Down
2 changes: 1 addition & 1 deletion proto.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion util.c
Original file line number Diff line number Diff line change
Expand Up @@ -3587,7 +3587,7 @@ Perl_set_context(void *t)
}
# endif

PERL_SET_NON_tTHX_CONTEXT(t);
PERL_SET_NON_tTHX_CONTEXT((PerlInterpreter *) t);

#else
PERL_UNUSED_ARG(t);
Expand Down
1 change: 1 addition & 0 deletions win32/win32thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Perl_set_context(void *t)
#if defined(USE_ITHREADS)
# ifdef USE_DECLSPEC_THREAD
Perl_current_context = t;
PERL_SET_NON_tTHX_CONTEXT(t);
# else
DWORD err = GetLastError();
TlsSetValue(PL_thr_key,t);
Expand Down