Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 64fb820

Browse files
committed
locale: fix partial change
now always inspect the hints hash value, as the hints bit can mean plain or partial, both. This made 'use locale' slower, but freed the hints bit.
1 parent 314d58c commit 64fb820

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

lib/locale.pm

+1-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ to behave as if in the "C" locale; attempts to change the locale will fail.
5151
# argument.
5252

5353
$locale::hint_bits = 0x4;
54-
# $locale::partial_hint_bits = 0x10; # Unused. If pragma had an argument
5554

5655
# The pseudo-category :characters consists of 2 real ones; but it also is
5756
# given its own number, -1, because in the complement form it also has the
@@ -99,10 +98,8 @@ sub import {
9998
next;
10099
}
101100

102-
# $^H |= $locale::partial_hint_bits;
103-
# This form of the pragma did override the other
101+
$^H |= $locale::hint_bits;
104102
# Now check the $^H{locale} value.
105-
# $^H &= ~$locale::hint_bits;
106103

107104
$arg =~ s/^://;
108105

locale.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -4968,7 +4968,12 @@ Perl__is_in_locale_category(pTHX_ const bool compiling, const int category)
49684968
/* The pseudo-category 'not_characters' is -1, so just add 1 to each to get
49694969
* a valid unsigned */
49704970
assert(category >= -1);
4971-
return cBOOL(SvUV(cat_sv) & (1U << (category + 1)));
4971+
/* The 0 check is for the old HINTS_LOCALE via use locale;
4972+
The -1 check is for IN_UNI_8_BIT
4973+
*/
4974+
return cBOOL(
4975+
(category != -1 && SvUV(cat_sv) == 0)
4976+
|| SvUV(cat_sv) & (1U << (category + 1)) );
49724977
}
49734978

49744979
char *

perl.h

+28-18
Original file line numberDiff line numberDiff line change
@@ -5372,7 +5372,8 @@ EXTCONST char *const PL_phase_names[];
53725372
# define PL_amagic_generation PL_na
53735373
#endif /* !PERL_CORE */
53745374

5375-
#define PL_hints PL_compiling.cop_hints
5375+
#define PL_hints PL_compiling.cop_hints
5376+
#define PL_hints_hash PL_compiling.cop_hints_hash
53765377

53775378
END_EXTERN_C
53785379

@@ -5409,7 +5410,7 @@ END_EXTERN_C
54095410
#define HINT_STRICT_REFS 0x00000002 /* strict pragma */
54105411
#define HINT_LOCALE 0x00000004 /* locale pragma */
54115412
#define HINT_BYTES 0x00000008 /* bytes pragma */
5412-
#define HINT_LOCALE_PARTIAL 0x00000004 /* ignored. was a subset of categories */
5413+
#define HINT_LOCALE_PARTIAL 0x00000004 /* ignored. was 0x10 categories subset */
54135414
#define HINT_EXACT_ARITH 0x00000010 /* exact_arith pragma */
54145415

54155416
#define HINT_EXPLICIT_STRICT_REFS 0x00000020 /* strict.pm */
@@ -6379,39 +6380,48 @@ typedef struct am_table_short AMTS;
63796380

63806381
/* Returns TRUE if the plain locale pragma without a parameter is in effect
63816382
*/
6382-
# define IN_LOCALE_RUNTIME (PL_curcop \
6383-
&& CopHINTS_get(PL_curcop) & HINT_LOCALE)
6383+
# define IN_LOCALE_RUNTIME \
6384+
(PL_curcop \
6385+
&& CopHINTS_get(PL_curcop) & HINT_LOCALE \
6386+
&& !SvIVX(cophh_fetch_pvs(PL_curcop->cop_hints_hash, "locale", 0)) \
6387+
)
63846388

6385-
/* Returns TRUE if either form of the locale pragma is in effect */
6389+
/* Returns TRUE if either form of the locale pragma is in effect (unused) */
63866390
# define IN_SOME_LOCALE_FORM_RUNTIME \
6387-
cBOOL(CopHINTS_get(PL_curcop) & (HINT_LOCALE|HINT_LOCALE_PARTIAL))
6391+
cBOOL(CopHINTS_get(PL_curcop) & HINT_LOCALE)
63886392

6389-
# define IN_LOCALE_COMPILETIME cBOOL(PL_hints & HINT_LOCALE)
6393+
/* (used) */
6394+
# define IN_LOCALE_COMPILETIME \
6395+
cBOOL(PL_hints & HINT_LOCALE \
6396+
&& !SvIVX(cophh_fetch_pvs(PL_hints_hash, "locale", 0)))
6397+
/* (unused) */
63906398
# define IN_SOME_LOCALE_FORM_COMPILETIME \
6391-
cBOOL(PL_hints & (HINT_LOCALE|HINT_LOCALE_PARTIAL))
6399+
cBOOL(PL_hints & HINT_LOCALE)
63926400

6401+
/* Only for use locale; (used) */
63936402
# define IN_LOCALE \
63946403
(IN_PERL_COMPILETIME ? IN_LOCALE_COMPILETIME : IN_LOCALE_RUNTIME)
6404+
/* use locale ... ; (unused) */
63956405
# define IN_SOME_LOCALE_FORM \
63966406
(IN_PERL_COMPILETIME ? IN_SOME_LOCALE_FORM_COMPILETIME \
63976407
: IN_SOME_LOCALE_FORM_RUNTIME)
63986408

63996409
# define IN_LC_ALL_COMPILETIME IN_LOCALE_COMPILETIME
64006410
# define IN_LC_ALL_RUNTIME IN_LOCALE_RUNTIME
64016411

6412+
/* the next 5 are actually used */
64026413
# define IN_LC_PARTIAL_COMPILETIME \
6403-
cBOOL(PL_hints & HINT_LOCALE_PARTIAL)
6414+
cBOOL(PL_hints & HINT_LOCALE_PARTIAL)
64046415
# define IN_LC_PARTIAL_RUNTIME \
6405-
(PL_curcop && CopHINTS_get(PL_curcop) & HINT_LOCALE_PARTIAL)
6406-
6407-
# define IN_LC_COMPILETIME(category) \
6408-
(IN_LC_ALL_COMPILETIME || (IN_LC_PARTIAL_COMPILETIME \
6409-
&& Perl__is_in_locale_category(aTHX_ TRUE, (category))))
6410-
# define IN_LC_RUNTIME(category) \
6411-
(IN_LC_ALL_RUNTIME || (IN_LC_PARTIAL_RUNTIME \
6412-
&& Perl__is_in_locale_category(aTHX_ FALSE, (category))))
6416+
cBOOL(PL_curcop && CopHINTS_get(PL_curcop) & HINT_LOCALE_PARTIAL)
6417+
6418+
# define IN_LC_COMPILETIME(category) \
6419+
(IN_LC_PARTIAL_COMPILETIME && Perl__is_in_locale_category(aTHX_ TRUE, (category)))
6420+
# define IN_LC_RUNTIME(category) \
6421+
(IN_LC_PARTIAL_RUNTIME && Perl__is_in_locale_category(aTHX_ FALSE, (category)))
64136422
# define IN_LC(category) \
6414-
(IN_LC_COMPILETIME(category) || IN_LC_RUNTIME(category))
6423+
(IN_LC_COMPILETIME(category) || IN_LC_RUNTIME(category))
6424+
64156425

64166426
# if defined (PERL_CORE) || defined (PERL_IN_XSUB_RE)
64176427

0 commit comments

Comments
 (0)