diff options
author | Karl Williamson <khw@cpan.org> | 2018-03-13 21:52:15 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2018-03-14 09:35:35 -0600 |
commit | 744ebf52f3e4ca5e41d9ce8bc68e10cae14592a0 (patch) | |
tree | 2a41d4ff70b04876f40f0e5b442f470465b5c476 | |
parent | 32a62865ef662fce2b2250a7e0eca15861e7fe20 (diff) | |
download | perl-744ebf52f3e4ca5e41d9ce8bc68e10cae14592a0.tar.gz |
Make Unicode data structures global
These structures are read-only, use const C strings, and are truly
global, so no need to have them be interpreter level. This saves
duplicating and freeing them as threads come and go.
In doing this, I noticed that not every one was properly being
copied/deallocated, so this fixes some potential unreported bugs, and
leaks.
-rw-r--r-- | embedvar.h | 57 | ||||
-rw-r--r-- | intrpvar.h | 24 | ||||
-rw-r--r-- | perl.c | 25 | ||||
-rw-r--r-- | perlapi.h | 38 | ||||
-rw-r--r-- | perlvars.h | 24 | ||||
-rw-r--r-- | sv.c | 20 |
6 files changed, 100 insertions, 88 deletions
diff --git a/embedvar.h b/embedvar.h index 73c20e7f1b..a3f7fb3dd3 100644 --- a/embedvar.h +++ b/embedvar.h @@ -40,8 +40,6 @@ # define vTHX PERL_GET_INTERP # endif -#define PL_AboveLatin1 (vTHX->IAboveLatin1) -#define PL_Assigned_invlist (vTHX->IAssigned_invlist) #define PL_DBcontrol (vTHX->IDBcontrol) #define PL_DBcv (vTHX->IDBcv) #define PL_DBgv (vTHX->IDBgv) @@ -52,25 +50,15 @@ #define PL_DBtrace (vTHX->IDBtrace) #define PL_Dir (vTHX->IDir) #define PL_Env (vTHX->IEnv) -#define PL_GCB_invlist (vTHX->IGCB_invlist) -#define PL_HasMultiCharFold (vTHX->IHasMultiCharFold) #define PL_InBitmap (vTHX->IInBitmap) -#define PL_LB_invlist (vTHX->ILB_invlist) #define PL_LIO (vTHX->ILIO) -#define PL_Latin1 (vTHX->ILatin1) #define PL_Mem (vTHX->IMem) #define PL_MemParse (vTHX->IMemParse) #define PL_MemShared (vTHX->IMemShared) -#define PL_NonL1NonFinalFold (vTHX->INonL1NonFinalFold) #define PL_Proc (vTHX->IProc) -#define PL_SB_invlist (vTHX->ISB_invlist) -#define PL_SCX_invlist (vTHX->ISCX_invlist) #define PL_Sock (vTHX->ISock) #define PL_StdIO (vTHX->IStdIO) #define PL_Sv (vTHX->ISv) -#define PL_UpperLatin1 (vTHX->IUpperLatin1) -#define PL_WB_invlist (vTHX->IWB_invlist) -#define PL_XPosix_ptrs (vTHX->IXPosix_ptrs) #define PL_Xpv (vTHX->IXpv) #define PL_an (vTHX->Ian) #define PL_argvgv (vTHX->Iargvgv) @@ -350,20 +338,13 @@ #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_foldable (vTHX->Iutf8_foldable) #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_utf8_perl_idcont (vTHX->Iutf8_perl_idcont) -#define PL_utf8_perl_idstart (vTHX->Iutf8_perl_idstart) #define PL_utf8_swash_ptrs (vTHX->Iutf8_swash_ptrs) #define PL_utf8_tofold (vTHX->Iutf8_tofold) #define PL_utf8_tolower (vTHX->Iutf8_tolower) #define PL_utf8_totitle (vTHX->Iutf8_totitle) #define PL_utf8_toupper (vTHX->Iutf8_toupper) -#define PL_utf8_xidcont (vTHX->Iutf8_xidcont) -#define PL_utf8_xidstart (vTHX->Iutf8_xidstart) #define PL_utf8cache (vTHX->Iutf8cache) #define PL_utf8locale (vTHX->Iutf8locale) #define PL_warn_locale (vTHX->Iwarn_locale) @@ -376,8 +357,32 @@ #if defined(PERL_GLOBAL_STRUCT) +#define PL_AboveLatin1 (my_vars->GAboveLatin1) +#define PL_GAboveLatin1 (my_vars->GAboveLatin1) +#define PL_Assigned_invlist (my_vars->GAssigned_invlist) +#define PL_GAssigned_invlist (my_vars->GAssigned_invlist) #define PL_C_locale_obj (my_vars->GC_locale_obj) #define PL_GC_locale_obj (my_vars->GC_locale_obj) +#define PL_GCB_invlist (my_vars->GGCB_invlist) +#define PL_GGCB_invlist (my_vars->GGCB_invlist) +#define PL_HasMultiCharFold (my_vars->GHasMultiCharFold) +#define PL_GHasMultiCharFold (my_vars->GHasMultiCharFold) +#define PL_LB_invlist (my_vars->GLB_invlist) +#define PL_GLB_invlist (my_vars->GLB_invlist) +#define PL_Latin1 (my_vars->GLatin1) +#define PL_GLatin1 (my_vars->GLatin1) +#define PL_NonL1NonFinalFold (my_vars->GNonL1NonFinalFold) +#define PL_GNonL1NonFinalFold (my_vars->GNonL1NonFinalFold) +#define PL_SB_invlist (my_vars->GSB_invlist) +#define PL_GSB_invlist (my_vars->GSB_invlist) +#define PL_SCX_invlist (my_vars->GSCX_invlist) +#define PL_GSCX_invlist (my_vars->GSCX_invlist) +#define PL_UpperLatin1 (my_vars->GUpperLatin1) +#define PL_GUpperLatin1 (my_vars->GUpperLatin1) +#define PL_WB_invlist (my_vars->GWB_invlist) +#define PL_GWB_invlist (my_vars->GWB_invlist) +#define PL_XPosix_ptrs (my_vars->GXPosix_ptrs) +#define PL_GXPosix_ptrs (my_vars->GXPosix_ptrs) #define PL_appctx (my_vars->Gappctx) #define PL_Gappctx (my_vars->Gappctx) #define PL_check (my_vars->Gcheck) @@ -462,6 +467,20 @@ #define PL_Gtimesbase (my_vars->Gtimesbase) #define PL_use_safe_putenv (my_vars->Guse_safe_putenv) #define PL_Guse_safe_putenv (my_vars->Guse_safe_putenv) +#define PL_utf8_foldable (my_vars->Gutf8_foldable) +#define PL_Gutf8_foldable (my_vars->Gutf8_foldable) +#define PL_utf8_idcont (my_vars->Gutf8_idcont) +#define PL_Gutf8_idcont (my_vars->Gutf8_idcont) +#define PL_utf8_idstart (my_vars->Gutf8_idstart) +#define PL_Gutf8_idstart (my_vars->Gutf8_idstart) +#define PL_utf8_perl_idcont (my_vars->Gutf8_perl_idcont) +#define PL_Gutf8_perl_idcont (my_vars->Gutf8_perl_idcont) +#define PL_utf8_perl_idstart (my_vars->Gutf8_perl_idstart) +#define PL_Gutf8_perl_idstart (my_vars->Gutf8_perl_idstart) +#define PL_utf8_xidcont (my_vars->Gutf8_xidcont) +#define PL_Gutf8_xidcont (my_vars->Gutf8_xidcont) +#define PL_utf8_xidstart (my_vars->Gutf8_xidstart) +#define PL_Gutf8_xidstart (my_vars->Gutf8_xidstart) #define PL_veto_cleanup (my_vars->Gveto_cleanup) #define PL_Gveto_cleanup (my_vars->Gveto_cleanup) #define PL_watch_pvx (my_vars->Gwatch_pvx) diff --git a/intrpvar.h b/intrpvar.h index 466785b882..33d952682a 100644 --- a/intrpvar.h +++ b/intrpvar.h @@ -639,14 +639,8 @@ PERLVARI(I, underlying_numeric_obj, locale_t, NULL) #endif /* !USE_LOCALE_NUMERIC */ /* Unicode inversion lists */ -PERLVAR(I, Latin1, SV *) -PERLVAR(I, UpperLatin1, SV *) /* Code points 128 - 255 */ -PERLVAR(I, AboveLatin1, SV *) PERLVAR(I, InBitmap, SV *) -PERLVAR(I, NonL1NonFinalFold, SV *) -PERLVAR(I, HasMultiCharFold, SV *) - /* utf8 character class swashes */ PERLVAR(I, utf8_mark, SV *) PERLVAR(I, utf8_toupper, SV *) @@ -657,13 +651,6 @@ PERLVAR(I, utf8_charname_begin, SV *) PERLVAR(I, utf8_charname_continue, SV *) PERLVARA(I, utf8_swash_ptrs, POSIX_SWASH_COUNT, SV *) -PERLVARA(I, XPosix_ptrs, POSIX_CC_COUNT, SV *) -PERLVAR(I, GCB_invlist, SV *) -PERLVAR(I, LB_invlist, SV *) -PERLVAR(I, SB_invlist, SV *) -PERLVAR(I, SCX_invlist, SV *) -PERLVAR(I, WB_invlist, SV *) -PERLVAR(I, Assigned_invlist, SV *) PERLVAR(I, seen_deprecated_macro, HV *) PERLVAR(I, last_swash_hv, HV *) @@ -733,13 +720,6 @@ PERLVARI(I, known_layers, PerlIO_list_t *, NULL) PERLVARI(I, def_layerlist, PerlIO_list_t *, NULL) #endif -PERLVAR(I, utf8_idstart, SV *) -PERLVAR(I, utf8_idcont, SV *) -PERLVAR(I, utf8_xidstart, SV *) -PERLVAR(I, utf8_perl_idstart, SV *) -PERLVAR(I, utf8_perl_idcont, SV *) -PERLVAR(I, utf8_xidcont, SV *) - PERLVAR(I, sort_RealCmp, SVCOMPARE_t) PERLVARI(I, checkav_save, AV *, NULL) /* save CHECK{}s when compiling */ @@ -783,10 +763,6 @@ PERLVAR(I, blockhooks, AV *) * matching */ PERLVARI(I, utf8_foldclosures, HV *, NULL) -/* List of characters that participate in folds (except marks, etc in - * multi-char folds) */ -PERLVARI(I, utf8_foldable, SV *, NULL) - PERLVAR(I, custom_ops, HV *) /* custom op registrations */ PERLVAR(I, Xpv, XPV *) /* (unused) held temporary value */ @@ -1190,16 +1190,8 @@ perl_destruct(pTHXx) SvREFCNT_dec(PL_utf8_totitle); SvREFCNT_dec(PL_utf8_tolower); SvREFCNT_dec(PL_utf8_tofold); - SvREFCNT_dec(PL_utf8_idstart); - SvREFCNT_dec(PL_utf8_idcont); - SvREFCNT_dec(PL_utf8_foldable); SvREFCNT_dec(PL_utf8_foldclosures); - SvREFCNT_dec(PL_AboveLatin1); SvREFCNT_dec(PL_InBitmap); - SvREFCNT_dec(PL_UpperLatin1); - SvREFCNT_dec(PL_Latin1); - SvREFCNT_dec(PL_NonL1NonFinalFold); - SvREFCNT_dec(PL_HasMultiCharFold); #ifdef USE_LOCALE_CTYPE SvREFCNT_dec(PL_warn_locale); #endif @@ -1208,28 +1200,11 @@ perl_destruct(pTHXx) PL_utf8_totitle = NULL; PL_utf8_tolower = NULL; PL_utf8_tofold = NULL; - PL_utf8_idstart = NULL; - PL_utf8_idcont = NULL; PL_utf8_foldclosures = NULL; - PL_AboveLatin1 = NULL; PL_InBitmap = NULL; - PL_HasMultiCharFold = NULL; #ifdef USE_LOCALE_CTYPE PL_warn_locale = NULL; #endif - PL_Latin1 = NULL; - PL_NonL1NonFinalFold = NULL; - PL_UpperLatin1 = NULL; - for (i = 0; i < POSIX_CC_COUNT; i++) { - SvREFCNT_dec(PL_XPosix_ptrs[i]); - PL_XPosix_ptrs[i] = NULL; - } - PL_GCB_invlist = NULL; - PL_LB_invlist = NULL; - PL_SB_invlist = NULL; - PL_SCX_invlist = NULL; - PL_WB_invlist = NULL; - PL_Assigned_invlist = NULL; if (!specialWARN(PL_compiling.cop_warnings)) PerlMemShared_free(PL_compiling.cop_warnings); @@ -99,8 +99,32 @@ END_EXTERN_C #else /* !PERL_CORE */ +#undef PL_AboveLatin1 +#define PL_AboveLatin1 (*Perl_GAboveLatin1_ptr(NULL)) +#undef PL_Assigned_invlist +#define PL_Assigned_invlist (*Perl_GAssigned_invlist_ptr(NULL)) #undef PL_C_locale_obj #define PL_C_locale_obj (*Perl_GC_locale_obj_ptr(NULL)) +#undef PL_GCB_invlist +#define PL_GCB_invlist (*Perl_GGCB_invlist_ptr(NULL)) +#undef PL_HasMultiCharFold +#define PL_HasMultiCharFold (*Perl_GHasMultiCharFold_ptr(NULL)) +#undef PL_LB_invlist +#define PL_LB_invlist (*Perl_GLB_invlist_ptr(NULL)) +#undef PL_Latin1 +#define PL_Latin1 (*Perl_GLatin1_ptr(NULL)) +#undef PL_NonL1NonFinalFold +#define PL_NonL1NonFinalFold (*Perl_GNonL1NonFinalFold_ptr(NULL)) +#undef PL_SB_invlist +#define PL_SB_invlist (*Perl_GSB_invlist_ptr(NULL)) +#undef PL_SCX_invlist +#define PL_SCX_invlist (*Perl_GSCX_invlist_ptr(NULL)) +#undef PL_UpperLatin1 +#define PL_UpperLatin1 (*Perl_GUpperLatin1_ptr(NULL)) +#undef PL_WB_invlist +#define PL_WB_invlist (*Perl_GWB_invlist_ptr(NULL)) +#undef PL_XPosix_ptrs +#define PL_XPosix_ptrs (*Perl_GXPosix_ptrs_ptr(NULL)) #undef PL_appctx #define PL_appctx (*Perl_Gappctx_ptr(NULL)) #undef PL_check @@ -181,6 +205,20 @@ END_EXTERN_C #define PL_timesbase (*Perl_Gtimesbase_ptr(NULL)) #undef PL_use_safe_putenv #define PL_use_safe_putenv (*Perl_Guse_safe_putenv_ptr(NULL)) +#undef PL_utf8_foldable +#define PL_utf8_foldable (*Perl_Gutf8_foldable_ptr(NULL)) +#undef PL_utf8_idcont +#define PL_utf8_idcont (*Perl_Gutf8_idcont_ptr(NULL)) +#undef PL_utf8_idstart +#define PL_utf8_idstart (*Perl_Gutf8_idstart_ptr(NULL)) +#undef PL_utf8_perl_idcont +#define PL_utf8_perl_idcont (*Perl_Gutf8_perl_idcont_ptr(NULL)) +#undef PL_utf8_perl_idstart +#define PL_utf8_perl_idstart (*Perl_Gutf8_perl_idstart_ptr(NULL)) +#undef PL_utf8_xidcont +#define PL_utf8_xidcont (*Perl_Gutf8_xidcont_ptr(NULL)) +#undef PL_utf8_xidstart +#define PL_utf8_xidstart (*Perl_Gutf8_xidstart_ptr(NULL)) #undef PL_veto_cleanup #define PL_veto_cleanup (*Perl_Gveto_cleanup_ptr(NULL)) #undef PL_watch_pvx diff --git a/perlvars.h b/perlvars.h index ac97ebcd99..e3ded3c7ef 100644 --- a/perlvars.h +++ b/perlvars.h @@ -271,3 +271,27 @@ PERLVARA(G, hash_chars, (1+256) * sizeof(U32), unsigned char) /* perl.c and hv.h #ifdef __VMS PERLVAR(G, perllib_sep, char) #endif + +PERLVAR(G, AboveLatin1, SV *) +PERLVAR(G, Assigned_invlist, SV *) +PERLVAR(G, GCB_invlist, SV *) +PERLVAR(G, HasMultiCharFold, SV *) +PERLVAR(G, Latin1, SV *) +PERLVAR(G, LB_invlist, SV *) +PERLVAR(G, NonL1NonFinalFold, SV *) +PERLVAR(G, SB_invlist, SV *) +PERLVAR(G, SCX_invlist, SV *) +PERLVAR(G, UpperLatin1, SV *) /* Code points 128 - 255 */ + +/* List of characters that participate in folds (except marks, etc in + * multi-char folds) */ +PERLVARI(G, utf8_foldable, SV *, NULL) + +PERLVAR(G, utf8_idcont, SV *) +PERLVAR(G, utf8_idstart, SV *) +PERLVAR(G, utf8_perl_idcont, SV *) +PERLVAR(G, utf8_perl_idstart, SV *) +PERLVAR(G, utf8_xidcont, SV *) +PERLVAR(G, utf8_xidstart, SV *) +PERLVAR(G, WB_invlist, SV *) +PERLVARA(G, XPosix_ptrs, POSIX_CC_COUNT, SV *) @@ -15582,38 +15582,18 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags, PL_setlocale_bufsize = 0; /* Unicode inversion lists */ - PL_Latin1 = sv_dup_inc(proto_perl->ILatin1, param); - PL_UpperLatin1 = sv_dup_inc(proto_perl->IUpperLatin1, param); - PL_AboveLatin1 = sv_dup_inc(proto_perl->IAboveLatin1, param); PL_InBitmap = sv_dup_inc(proto_perl->IInBitmap, param); - PL_NonL1NonFinalFold = sv_dup_inc(proto_perl->INonL1NonFinalFold, param); - PL_HasMultiCharFold = sv_dup_inc(proto_perl->IHasMultiCharFold, param); - /* utf8 character class swashes */ for (i = 0; i < POSIX_SWASH_COUNT; i++) { PL_utf8_swash_ptrs[i] = sv_dup_inc(proto_perl->Iutf8_swash_ptrs[i], param); } - for (i = 0; i < POSIX_CC_COUNT; i++) { - PL_XPosix_ptrs[i] = sv_dup_inc(proto_perl->IXPosix_ptrs[i], param); - } - PL_GCB_invlist = sv_dup_inc(proto_perl->IGCB_invlist, param); - PL_SB_invlist = sv_dup_inc(proto_perl->ISB_invlist, param); - PL_SCX_invlist = sv_dup_inc(proto_perl->ISCX_invlist, param); - PL_WB_invlist = sv_dup_inc(proto_perl->IWB_invlist, param); PL_seen_deprecated_macro = hv_dup_inc(proto_perl->Iseen_deprecated_macro, param); PL_utf8_mark = sv_dup_inc(proto_perl->Iutf8_mark, param); PL_utf8_toupper = sv_dup_inc(proto_perl->Iutf8_toupper, param); PL_utf8_totitle = sv_dup_inc(proto_perl->Iutf8_totitle, param); PL_utf8_tolower = sv_dup_inc(proto_perl->Iutf8_tolower, param); PL_utf8_tofold = sv_dup_inc(proto_perl->Iutf8_tofold, param); - PL_utf8_idstart = sv_dup_inc(proto_perl->Iutf8_idstart, param); - PL_utf8_xidstart = sv_dup_inc(proto_perl->Iutf8_xidstart, param); - PL_utf8_perl_idstart = sv_dup_inc(proto_perl->Iutf8_perl_idstart, param); - PL_utf8_perl_idcont = sv_dup_inc(proto_perl->Iutf8_perl_idcont, param); - PL_utf8_idcont = sv_dup_inc(proto_perl->Iutf8_idcont, param); - PL_utf8_xidcont = sv_dup_inc(proto_perl->Iutf8_xidcont, param); - PL_utf8_foldable = sv_dup_inc(proto_perl->Iutf8_foldable, param); PL_utf8_charname_begin = sv_dup_inc(proto_perl->Iutf8_charname_begin, param); PL_utf8_charname_continue = sv_dup_inc(proto_perl->Iutf8_charname_continue, param); |