This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make PL_utf8_foldclosures interpreter level
authorKarl Williamson <khw@cpan.org>
Mon, 18 May 2020 20:40:04 +0000 (14:40 -0600)
committerSawyer X <xsawyerx@cpan.org>
Tue, 2 Jun 2020 09:17:47 +0000 (12:17 +0300)
This resolves #17774.

This ticket is because the fixes in GH #17154 failed to get every case,
leaving this one outlier to be fixed by this commit.

The text in https://github.com/Perl/perl5/issues/17154 gives extensive
details as to the problem.  But briefly, in an attempt to speed up
interpreter cloning, I moved certain SVs from interpreter level to
global level in e80a0113c4a8036dfb22aec44d0a9feb65d36fed (v5.27.11,
March 2018).  This was doable, we thought, because the content of these
SVs is constant throughout the life of the program, so no need to copy
them when cloning a new interpreter or thread.  However when an
interpreter exits, all its SVs get cleaned up, which caused these to
become garbage in applications where another interpreter remains
running.  This circumstance is rare enough that the bug wasn't reported
until September 2019,  #17154.  I made an initial attempt to fix the
problem, and closed that ticket, but I overlooked one of the variables,
which was reported in #17774, which this commit addresses.

Effectively the behavior is reverted to the way it was before
e80a0113c4a8036dfb22aec44d0a9feb65d36fed.

embedvar.h
intrpvar.h
perl.c
perlapi.h
perlvars.h
sv.c

index 5b6aa2b..de1aa99 100644 (file)
 #define PL_unsafe              (vTHX->Iunsafe)
 #define PL_utf8_charname_begin (vTHX->Iutf8_charname_begin)
 #define PL_utf8_charname_continue      (vTHX->Iutf8_charname_continue)
+#define PL_utf8_foldclosures   (vTHX->Iutf8_foldclosures)
 #define PL_utf8_idcont         (vTHX->Iutf8_idcont)
 #define PL_utf8_idstart                (vTHX->Iutf8_idstart)
 #define PL_utf8_mark           (vTHX->Iutf8_mark)
 #define PL_Guser_def_props_aTHX        (my_vars->Guser_def_props_aTHX)
 #define PL_user_prop_mutex     (my_vars->Guser_prop_mutex)
 #define PL_Guser_prop_mutex    (my_vars->Guser_prop_mutex)
-#define PL_utf8_foldclosures   (my_vars->Gutf8_foldclosures)
-#define PL_Gutf8_foldclosures  (my_vars->Gutf8_foldclosures)
 #define PL_veto_cleanup                (my_vars->Gveto_cleanup)
 #define PL_Gveto_cleanup       (my_vars->Gveto_cleanup)
 #define PL_watch_pvx           (my_vars->Gwatch_pvx)
index b888f0f..23de9d9 100644 (file)
@@ -915,6 +915,10 @@ PERLVAR(I, UpperLatin1,    SV *)   /* Code points 128 - 255 */
 /* List of characters that participate in any fold defined by Unicode */
 PERLVAR(I, in_some_fold, SV *)
 
+/* Everything that folds to a given character, for case insensitivity regex
+ * matching */
+PERLVAR(I, utf8_foldclosures, SV *)
+
 PERLVAR(I, utf8_idcont,        SV *)
 PERLVAR(I, utf8_idstart, SV *)
 PERLVAR(I, utf8_perl_idcont, SV *)
diff --git a/perl.c b/perl.c
index 422a548..2013a76 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -1198,6 +1198,8 @@ perl_destruct(pTHXx)
     PL_UpperLatin1 = NULL;
     SvREFCNT_dec(PL_in_some_fold);
     PL_in_some_fold = NULL;
+    SvREFCNT_dec(PL_utf8_foldclosures);
+    PL_utf8_foldclosures = NULL;
     SvREFCNT_dec(PL_utf8_idcont);
     PL_utf8_idcont = NULL;
     SvREFCNT_dec(PL_utf8_idstart);
index f3ef930..305c11d 100644 (file)
--- a/perlapi.h
+++ b/perlapi.h
@@ -215,8 +215,6 @@ END_EXTERN_C
 #define PL_user_def_props_aTHX (*Perl_Guser_def_props_aTHX_ptr(NULL))
 #undef  PL_user_prop_mutex
 #define PL_user_prop_mutex     (*Perl_Guser_prop_mutex_ptr(NULL))
-#undef  PL_utf8_foldclosures
-#define PL_utf8_foldclosures   (*Perl_Gutf8_foldclosures_ptr(NULL))
 #undef  PL_veto_cleanup
 #define PL_veto_cleanup                (*Perl_Gveto_cleanup_ptr(NULL))
 #undef  PL_watch_pvx
index 0892332..cd1523d 100644 (file)
@@ -305,10 +305,6 @@ PERLVAR(G, user_prop_mutex, perl_mutex)    /* Mutex for manipulating
                                               PL_user_defined_properties */
 #endif
 
-/* Everything that folds to a given character, for case insensitivity regex
- * matching */
-PERLVAR(G, utf8_foldclosures, SV *)
-
 /* these record the best way to perform certain IO operations while
  * atomically setting FD_CLOEXEC. On the first call, a probe is done
  * and the result recorded for use by subsequent calls.
diff --git a/sv.c b/sv.c
index fb1b9fd..9c7f3ba 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -15731,6 +15731,7 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags,
     PL_SCX_invlist            = sv_dup_inc(proto_perl->ISCX_invlist, param);
     PL_UpperLatin1            = sv_dup_inc(proto_perl->IUpperLatin1, param);
     PL_in_some_fold           = sv_dup_inc(proto_perl->Iin_some_fold, param);
+    PL_utf8_foldclosures      = sv_dup_inc(proto_perl->Iutf8_foldclosures, param);
     PL_utf8_idcont            = sv_dup_inc(proto_perl->Iutf8_idcont, param);
     PL_utf8_idstart           = sv_dup_inc(proto_perl->Iutf8_idstart, param);
     PL_utf8_perl_idcont       = sv_dup_inc(proto_perl->Iutf8_perl_idcont, param);