Branch: refs/heads/blead
  Home:   https://github.com/Perl/perl5
  Commit: 2c8e798e942eeb1d2bf2ba3a2b15fcae3c7c2c53
      
https://github.com/Perl/perl5/commit/2c8e798e942eeb1d2bf2ba3a2b15fcae3c7c2c53
  Author: Karl Williamson <k...@cpan.org>
  Date:   2022-10-18 (Tue, 18 Oct 2022)

  Changed paths:
    M sv.c

  Log Message:
  -----------
  sv.c: Move some code; consolidate

This moves the code for cloning the locale variables to a single place,
consolidating some that had the same cpp directives.  It showed that one
variable was cloned twice; the redundant one is now removed.


  Commit: 1c33371ae09893c7dcf660df882cc1a5dbc37266
      
https://github.com/Perl/perl5/commit/1c33371ae09893c7dcf660df882cc1a5dbc37266
  Author: Karl Williamson <k...@cpan.org>
  Date:   2022-10-18 (Tue, 18 Oct 2022)

  Changed paths:
    M sv.c

  Log Message:
  -----------
  sv.c: Clone interpreter with locale set to C

A thread is supposed to start with the locale set to the C locale.  We
were duping the parent values, and later overriding.  Better to set to C
from the beginning.


  Commit: 7d6b94bd41d6d1ff762b10b7f7f43889321d3a3f
      
https://github.com/Perl/perl5/commit/7d6b94bd41d6d1ff762b10b7f7f43889321d3a3f
  Author: Karl Williamson <k...@cpan.org>
  Date:   2022-10-18 (Tue, 18 Oct 2022)

  Changed paths:
    M sv.c

  Log Message:
  -----------
  sv.c: Set phase to CONSTRUCT on interpreter being cloned

So far this hadn't been an issue, but it will be for a future commit.


  Commit: d52dd969e613d078943e8c99baec94ae5c4aef53
      
https://github.com/Perl/perl5/commit/d52dd969e613d078943e8c99baec94ae5c4aef53
  Author: Karl Williamson <k...@cpan.org>
  Date:   2022-10-18 (Tue, 18 Oct 2022)

  Changed paths:
    M perl.h

  Log Message:
  -----------
  Don't #define USE_THREAD_SAFE LOCALE unless threaded

If there aren't threads, yes locales are trivially thread-safe, but
the code that gets executed to make them so doesn't need to get
compiled, and that is controlled by this #define.


  Commit: 7de8159af380f738facd9db4aa5455f02ba5af04
      
https://github.com/Perl/perl5/commit/7de8159af380f738facd9db4aa5455f02ba5af04
  Author: Karl Williamson <k...@cpan.org>
  Date:   2022-10-18 (Tue, 18 Oct 2022)

  Changed paths:
    M makedef.pl
    M perl.h

  Log Message:
  -----------
  Clean up perl.h/makedef.pl common logic

This has gotten two twisty little mazy over time.  Clean it up, add
comments, and make sure the logic is the same on both.


  Commit: 6a4065f28f30d59e3a6cea6504be34bdb5e5eb8b
      
https://github.com/Perl/perl5/commit/6a4065f28f30d59e3a6cea6504be34bdb5e5eb8b
  Author: Karl Williamson <k...@cpan.org>
  Date:   2022-10-18 (Tue, 18 Oct 2022)

  Changed paths:
    M embedvar.h
    M intrpvar.h
    M locale.c
    M makedef.pl
    M perl.c
    M perl.h
    M sv.c

  Log Message:
  -----------
  locale: Create special variable to hold current LC_ALL

Some configurations require us to store the current locale for each
category.  Prior to this commit, this was done in the array
PL_curlocales, with the entry for LC_ALL being in the highest element.

Future commits will need just the value for LC_ALL in some other
configurations, without needing the rest of the array.  This commit
splits off the LC_ALL element into its own per-interpreter variable to
accommodate those.  It always had to have special handling anyway beyond
the rest of the array elements,


  Commit: 49825ce8d49ec49e0c08ecb341ea5a7b7383225b
      
https://github.com/Perl/perl5/commit/49825ce8d49ec49e0c08ecb341ea5a7b7383225b
  Author: Karl Williamson <k...@cpan.org>
  Date:   2022-10-18 (Tue, 18 Oct 2022)

  Changed paths:
    M embed.fnc
    M embed.h
    M locale.c
    M proto.h

  Log Message:
  -----------
  locale.c: Compile display fcn under more circumstances

This is in preparation for it to be used in more instances in future
commits.  It uses a symbol that won't be defined until those commits.


  Commit: 7af2d2037375d58e700f9e1b217efb2c4db66133
      
https://github.com/Perl/perl5/commit/7af2d2037375d58e700f9e1b217efb2c4db66133
  Author: Karl Williamson <k...@cpan.org>
  Date:   2022-10-18 (Tue, 18 Oct 2022)

  Changed paths:
    M locale.c

  Log Message:
  -----------
  locale.c: Do uselocale() earlier in init process

This prevents some unnecessary steps, that the next commit would turn
into memory leaks.


  Commit: 1094750e0904f86121732c4af342fbdaccf70df3
      
https://github.com/Perl/perl5/commit/1094750e0904f86121732c4af342fbdaccf70df3
  Author: Karl Williamson <k...@cpan.org>
  Date:   2022-10-18 (Tue, 18 Oct 2022)

  Changed paths:
    M embedvar.h
    M intrpvar.h
    M locale.c
    M makedef.pl
    M perl.c
    M sv.c

  Log Message:
  -----------
  Some locale operations need to be done in proper thread

This is a step in solving #20155

The POSIX 2008 locale API introduces per-thread locales.  But the
previous global locale system is retained, probably for backward
compatibility.

The POSIX 2008 interface causes memory to be malloc'd that needs to be
freed.  In order to do this, the caller must first stop using that
memory, by switching to another locale.  perl accomplishes this during
termination by switching to the global locale, which is always available
and doesn't need to be freed.

Perl has long assumed that all that was needed to switch threads was to
change out tTHX.  That's because that structure was intended to hold all
the information for a given thread.  But it turns out that this doesn't
work when some library independently holds information about the
thread's state.  And there are now some libraries that do that.

What was happening in this case was that perl thought that it was
sufficient to switch tTHX to change to a different thread in order to do
the freeing of memory, and then used the POSIX 2008 function to change
to the global locale so that the memory could be safely freed.  But the
POSIX 2008 function doesn't care about tTHX, and actually was typically
operating on a different thread, and so changed that thread to the global
locale instead of the intended thread.  Often that was the top-level
thread, thread 0.  That caused whatever thread it was to no longer be in
the expected locale, and to no longer be thread-safe with regards to
localess,

This commit causes locale_term(), which has always been called from the
actual terminating thread that POSIX 2008 knows about, to change to the
global thread and free the memory.

It also creates a new per-interpreter variable that effectively maps the
tTHX thread to the associated POSIX 2008 memory.  During
perl_destruct(), it frees the memory this variable points to, instead of
blindly assuming the memory to free is the current tTHX thread's.

This fixes the symptoms associtated with #20155, but doesn't solve the
whole problem.  In general, a library that has independent thread status
needs to be updated to the new thread when Perl changes threads using
tTHX.  Future commits will do this.


  Commit: 644641ff58ccf88bd860ef5517a40d1fb27bf022
      
https://github.com/Perl/perl5/commit/644641ff58ccf88bd860ef5517a40d1fb27bf022
  Author: Karl Williamson <k...@cpan.org>
  Date:   2022-10-18 (Tue, 18 Oct 2022)

  Changed paths:
    M dist/threads/lib/threads.pm
    M dist/threads/threads.xs
    M embed.fnc
    M locale.c
    M makedef.pl
    M perl.h
    M perlvars.h
    M proto.h
    M thread.h
    M util.c

  Log Message:
  -----------
  Switch libc per-interpreter data when tTHX changes

As noted in the previous commit, some library functions now keep
per-thread state.  So far the only ones we care about are libc
locale-changing ones.

When perl changes threads by swapping out tTHX, those library functions
need to be informed about the new value so that they remain in sync with
what perl thinks the locale should be.

This commit creates a function to do this, and changes the
thread-changing macros to also call this as part of the change.

For POSIX 2008, the function just calls uselocale() using the
per-interpreter object introduced previously.

For Windows, this commit adds a per-interpreter string of the current
LC_ALL, and the function calls setlocale on that.  We keep the same
string for POSIX 2008 implementations that lack querylocale(), so this
commit just enables that variable on Windows as well.  The code is
already in place to free the memory the string occupies when done.

The commit also creates a mechanism to skip this during thread
destruction.  A thread in its death throes doesn't need to have accurate
locale information, and the information needed to map from thread to
what libc needs to know gets destroyed as part of those throes, while
relics of the thread remain.  I couldn't find a way to accurately know
if we are dealing with a relic or not, so the solution I adopted was to
just not switch during destruction.

This commit completes fixing #20155.


  Commit: 505ba11509259ba60519468c48f93e43da72a481
      
https://github.com/Perl/perl5/commit/505ba11509259ba60519468c48f93e43da72a481
  Author: Karl Williamson <k...@cpan.org>
  Date:   2022-10-18 (Tue, 18 Oct 2022)

  Changed paths:
    M locale.c

  Log Message:
  -----------
  Revert code changes for Workaround for attributes.pm breakage

This partially reverts ebb1d9ce1d2cad3a1ef580148b3788cba3524319.

The real fix for this problem has now been committed, so the workaround
can be reverted, leaving the tests.


Compare: https://github.com/Perl/perl5/compare/9748957e92f9...505ba1150925

Reply via email to