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

Commit e099e77

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 a04965a commit e099e77

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
@@ -5375,7 +5375,8 @@ EXTCONST char *const PL_phase_names[];
53755375
# define PL_amagic_generation PL_na
53765376
#endif /* !PERL_CORE */
53775377

5378-
#define PL_hints PL_compiling.cop_hints
5378+
#define PL_hints PL_compiling.cop_hints
5379+
#define PL_hints_hash PL_compiling.cop_hints_hash
53795380

53805381
END_EXTERN_C
53815382

@@ -5412,7 +5413,7 @@ END_EXTERN_C
54125413
#define HINT_STRICT_REFS 0x00000002 /* strict pragma */
54135414
#define HINT_LOCALE 0x00000004 /* locale pragma */
54145415
#define HINT_BYTES 0x00000008 /* bytes pragma */
5415-
#define HINT_LOCALE_PARTIAL 0x00000004 /* ignored. was a subset of categories */
5416+
#define HINT_LOCALE_PARTIAL 0x00000004 /* ignored. was 0x10 categories subset */
54165417
#define HINT_EXACT_ARITH 0x00000010 /* exact_arith pragma */
54175418

54185419
#define HINT_EXPLICIT_STRICT_REFS 0x00000020 /* strict.pm */
@@ -6382,39 +6383,48 @@ typedef struct am_table_short AMTS;
63826383

63836384
/* Returns TRUE if the plain locale pragma without a parameter is in effect
63846385
*/
6385-
# define IN_LOCALE_RUNTIME (PL_curcop \
6386-
&& CopHINTS_get(PL_curcop) & HINT_LOCALE)
6386+
# define IN_LOCALE_RUNTIME \
6387+
(PL_curcop \
6388+
&& CopHINTS_get(PL_curcop) & HINT_LOCALE \
6389+
&& !SvIVX(cophh_fetch_pvs(PL_curcop->cop_hints_hash, "locale", 0)) \
6390+
)
63876391

6388-
/* Returns TRUE if either form of the locale pragma is in effect */
6392+
/* Returns TRUE if either form of the locale pragma is in effect (unused) */
63896393
# define IN_SOME_LOCALE_FORM_RUNTIME \
6390-
cBOOL(CopHINTS_get(PL_curcop) & (HINT_LOCALE|HINT_LOCALE_PARTIAL))
6394+
cBOOL(CopHINTS_get(PL_curcop) & HINT_LOCALE)
63916395

6392-
# define IN_LOCALE_COMPILETIME cBOOL(PL_hints & HINT_LOCALE)
6396+
/* (used) */
6397+
# define IN_LOCALE_COMPILETIME \
6398+
cBOOL(PL_hints & HINT_LOCALE \
6399+
&& !SvIVX(cophh_fetch_pvs(PL_hints_hash, "locale", 0)))
6400+
/* (unused) */
63936401
# define IN_SOME_LOCALE_FORM_COMPILETIME \
6394-
cBOOL(PL_hints & (HINT_LOCALE|HINT_LOCALE_PARTIAL))
6402+
cBOOL(PL_hints & HINT_LOCALE)
63956403

6404+
/* Only for use locale; (used) */
63966405
# define IN_LOCALE \
63976406
(IN_PERL_COMPILETIME ? IN_LOCALE_COMPILETIME : IN_LOCALE_RUNTIME)
6407+
/* use locale ... ; (unused) */
63986408
# define IN_SOME_LOCALE_FORM \
63996409
(IN_PERL_COMPILETIME ? IN_SOME_LOCALE_FORM_COMPILETIME \
64006410
: IN_SOME_LOCALE_FORM_RUNTIME)
64016411

64026412
# define IN_LC_ALL_COMPILETIME IN_LOCALE_COMPILETIME
64036413
# define IN_LC_ALL_RUNTIME IN_LOCALE_RUNTIME
64046414

6415+
/* the next 5 are actually used */
64056416
# define IN_LC_PARTIAL_COMPILETIME \
6406-
cBOOL(PL_hints & HINT_LOCALE_PARTIAL)
6417+
cBOOL(PL_hints & HINT_LOCALE_PARTIAL)
64076418
# define IN_LC_PARTIAL_RUNTIME \
6408-
(PL_curcop && CopHINTS_get(PL_curcop) & HINT_LOCALE_PARTIAL)
6409-
6410-
# define IN_LC_COMPILETIME(category) \
6411-
(IN_LC_ALL_COMPILETIME || (IN_LC_PARTIAL_COMPILETIME \
6412-
&& Perl__is_in_locale_category(aTHX_ TRUE, (category))))
6413-
# define IN_LC_RUNTIME(category) \
6414-
(IN_LC_ALL_RUNTIME || (IN_LC_PARTIAL_RUNTIME \
6415-
&& Perl__is_in_locale_category(aTHX_ FALSE, (category))))
6419+
cBOOL(PL_curcop && CopHINTS_get(PL_curcop) & HINT_LOCALE_PARTIAL)
6420+
6421+
# define IN_LC_COMPILETIME(category) \
6422+
(IN_LC_PARTIAL_COMPILETIME && Perl__is_in_locale_category(aTHX_ TRUE, (category)))
6423+
# define IN_LC_RUNTIME(category) \
6424+
(IN_LC_PARTIAL_RUNTIME && Perl__is_in_locale_category(aTHX_ FALSE, (category)))
64166425
# define IN_LC(category) \
6417-
(IN_LC_COMPILETIME(category) || IN_LC_RUNTIME(category))
6426+
(IN_LC_COMPILETIME(category) || IN_LC_RUNTIME(category))
6427+
64186428

64196429
# if defined (PERL_CORE) || defined (PERL_IN_XSUB_RE)
64206430

0 commit comments

Comments
 (0)