summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2022-10-08 06:49:01 -0600
committerKarl Williamson <khw@cpan.org>2022-10-10 13:22:11 -0600
commitf41910bf9320ae3f1312f3e832504e8b03da3f00 (patch)
treef0d730d52ec211c288eda17a6020e4c41dd35d5d
parent7a615b719074d2537dcc9f9c87ef4b4795182579 (diff)
downloadperl-f41910bf9320ae3f1312f3e832504e8b03da3f00.tar.gz
handy.h: Set macro to false if can't ever be true
It's unlikely that perl will be compiled with out the LC_CTYPE locale category being enabled. But if it isn't, there is no sense in having per-interpreter variables for various conditions in it, and no sense having code that tests those variables. This commit changes a macro to always yield 'false' when this is disabled, adds a new similar macro, and changes some occurrences that test for a variable to use the macros instead of the variables. That way the compiler knows these to conditions can never be true.
-rw-r--r--handy.h8
-rw-r--r--intrpvar.h3
-rw-r--r--makedef.pl2
-rw-r--r--perl.h4
-rw-r--r--pp.c16
-rw-r--r--regexec.c6
-rw-r--r--utf8.c6
7 files changed, 26 insertions, 19 deletions
diff --git a/handy.h b/handy.h
index 26b9a8b28c..6dd1a71586 100644
--- a/handy.h
+++ b/handy.h
@@ -1880,7 +1880,13 @@ END_EXTERN_C
#define toUPPER_LATIN1_MOD(c) ((! FITS_IN_8_BITS(c)) \
? (c) \
: PL_mod_latin1_uc[ (U8) (c) ])
-#define IN_UTF8_CTYPE_LOCALE PL_in_utf8_CTYPE_locale
+#ifdef USE_LOCALE_CTYPE
+# define IN_UTF8_CTYPE_LOCALE PL_in_utf8_CTYPE_locale
+# define IN_UTF8_TURKIC_LOCALE PL_in_utf8_turkic_locale
+#else
+# define IN_UTF8_CTYPE_LOCALE false
+# define IN_UTF8_TURKIC_LOCALE false
+#endif
/* Use foo_LC_uvchr() instead of these for beyond the Latin1 range */
diff --git a/intrpvar.h b/intrpvar.h
index 578ac313ac..a975977729 100644
--- a/intrpvar.h
+++ b/intrpvar.h
@@ -391,10 +391,9 @@ PERLVARI(I, locale_mutex_depth, int, 0) /* Emulate general semaphore */
#ifdef USE_LOCALE_CTYPE
PERLVAR(I, warn_locale, SV *)
-#endif
-
PERLVAR(I, in_utf8_CTYPE_locale, bool)
PERLVAR(I, in_utf8_turkic_locale, bool)
+#endif
PERLVARA(I, colors,6, char *) /* values from PERL_RE_COLORS env var */
diff --git a/makedef.pl b/makedef.pl
index c0f8ee1282..36ae63e06b 100644
--- a/makedef.pl
+++ b/makedef.pl
@@ -557,6 +557,8 @@ unless ($define{USE_LOCALE_NUMERIC}) {
unless ($define{USE_LOCALE_CTYPE}) {
++$skip{$_} foreach qw(
PL_ctype_name
+ PL_in_utf8_CTYPE_locale
+ PL_in_utf8_turkic_locale
);
}
diff --git a/perl.h b/perl.h
index 5e614c89c6..4d3861d310 100644
--- a/perl.h
+++ b/perl.h
@@ -6918,7 +6918,7 @@ the plain locale pragma without a parameter (S<C<use locale>>) is in effect.
* string, and an end position which it won't try to read past */
# define _CHECK_AND_OUTPUT_WIDE_LOCALE_CP_MSG(cp) \
STMT_START { \
- if (! PL_in_utf8_CTYPE_locale && ckWARN(WARN_LOCALE)) { \
+ if (! IN_UTF8_CTYPE_LOCALE && ckWARN(WARN_LOCALE)) { \
Perl_warner(aTHX_ packWARN(WARN_LOCALE), \
"Wide character (U+%" UVXf ") in %s",\
(UV) cp, OP_DESC(PL_op)); \
@@ -6927,7 +6927,7 @@ the plain locale pragma without a parameter (S<C<use locale>>) is in effect.
# define _CHECK_AND_OUTPUT_WIDE_LOCALE_UTF8_MSG(s, send) \
STMT_START { /* Check if to warn before doing the conversion work */\
- if (! PL_in_utf8_CTYPE_locale && ckWARN(WARN_LOCALE)) { \
+ if (! IN_UTF8_CTYPE_LOCALE && ckWARN(WARN_LOCALE)) { \
UV cp = utf8_to_uvchr_buf((U8 *) (s), (U8 *) (send), NULL); \
Perl_warner(aTHX_ packWARN(WARN_LOCALE), \
"Wide character (U+%" UVXf ") in %s", \
diff --git a/pp.c b/pp.c
index 4253d46e57..f06f282de6 100644
--- a/pp.c
+++ b/pp.c
@@ -3846,7 +3846,7 @@ PP(pp_ucfirst)
* call to lowercase above has handled this. But SpecialCasing.txt
* says we are supposed to remove the COMBINING DOT ABOVE. We can
* tell if we have this situation if I ==> i in a turkic locale. */
- if ( UNLIKELY(PL_in_utf8_turkic_locale)
+ if ( UNLIKELY(IN_UTF8_TURKIC_LOCALE)
&& IN_LC_RUNTIME(LC_CTYPE)
&& (UNLIKELY(*s == 'I' && tmpbuf[0] == 'i')))
{
@@ -3890,7 +3890,7 @@ PP(pp_ucfirst)
#ifdef USE_LOCALE_CTYPE
if (IN_LC_RUNTIME(LC_CTYPE)) {
- if ( UNLIKELY(PL_in_utf8_turkic_locale)
+ if ( UNLIKELY(IN_UTF8_TURKIC_LOCALE)
&& ( (op_type == OP_LCFIRST && UNLIKELY(*s == 'I'))
|| (op_type == OP_UCFIRST && UNLIKELY(*s == 'i'))))
{
@@ -4292,7 +4292,7 @@ PP(pp_uc)
#ifdef USE_LOCALE_CTYPE
- && (LIKELY( ! PL_in_utf8_turkic_locale
+ && (LIKELY( ! IN_UTF8_TURKIC_LOCALE
|| ! IN_LC_RUNTIME(LC_CTYPE))
|| *s != 'i')
#endif
@@ -4398,7 +4398,7 @@ PP(pp_uc)
* its own loop */
#ifdef USE_LOCALE_CTYPE
- if ( UNLIKELY(PL_in_utf8_turkic_locale)
+ if ( UNLIKELY(IN_UTF8_TURKIC_LOCALE)
&& UNLIKELY(IN_LC_RUNTIME(LC_CTYPE)))
{
for (; s < send; s++) {
@@ -4464,7 +4464,7 @@ PP(pp_lc)
#ifdef USE_LOCALE_CTYPE
&& ( LIKELY(! IN_LC_RUNTIME(LC_CTYPE))
- || LIKELY(! PL_in_utf8_turkic_locale))
+ || LIKELY(! IN_UTF8_TURKIC_LOCALE))
#endif
@@ -4500,7 +4500,7 @@ PP(pp_lc)
/* Lowercasing in a Turkic locale can cause non-UTF-8 to need to become
* UTF-8 for the single case of the character 'I' */
- if ( UNLIKELY(PL_in_utf8_turkic_locale)
+ if ( UNLIKELY(IN_UTF8_TURKIC_LOCALE)
&& ! DO_UTF8(source)
&& (next_I = (U8 *) memchr(s, 'I', len)))
{
@@ -4557,7 +4557,7 @@ PP(pp_lc)
* and if so, do it. We know that there is a DOT because
* _toLOWER_utf8_flags() wouldn't have returned 'i' unless there
* was one in a proper position. */
- if ( UNLIKELY(PL_in_utf8_turkic_locale)
+ if ( UNLIKELY(IN_UTF8_TURKIC_LOCALE)
&& IN_LC_RUNTIME(LC_CTYPE))
{
if ( UNLIKELY(remove_dot_above)
@@ -4849,7 +4849,7 @@ PP(pp_fc)
for (; s < send; d++, s++) {
if ( UNLIKELY(*s == MICRO_SIGN)
#ifdef USE_LOCALE_CTYPE
- || ( UNLIKELY(PL_in_utf8_turkic_locale)
+ || ( UNLIKELY(IN_UTF8_TURKIC_LOCALE)
&& UNLIKELY(IN_LC_RUNTIME(LC_CTYPE))
&& UNLIKELY(*s == 'I'))
#endif
diff --git a/regexec.c b/regexec.c
index 3bd0e7b51a..13a3ca8991 100644
--- a/regexec.c
+++ b/regexec.c
@@ -4623,7 +4623,7 @@ S_setup_EXACTISH_ST(pTHX_ const regnode * const text_node,
if ( (op == EXACTF && utf8_target)
|| (op == EXACTFL && IN_UTF8_CTYPE_LOCALE))
{
- if (op == EXACTFL && PL_in_utf8_turkic_locale) {
+ if (op == EXACTFL && IN_UTF8_TURKIC_LOCALE) {
op = TURKISH;
}
else {
@@ -10823,7 +10823,7 @@ S_reginclass(pTHX_ regexp * const prog, const regnode * const n, const U8* const
}
else /* Failing that, hardcode the two tests for a Turkic
locale */
- if ( UNLIKELY(PL_in_utf8_turkic_locale)
+ if ( UNLIKELY(IN_UTF8_TURKIC_LOCALE)
&& isALPHA_FOLD_EQ(*p, 'i'))
{
/* Turkish locales have these hard-coded rules
@@ -10854,7 +10854,7 @@ S_reginclass(pTHX_ regexp * const prog, const regnode * const n, const U8* const
/* In a Turkic locale under folding, hard-code the I i case pair
* matches; these wouldn't have the ANYOF_HAS_EXTRA_RUNTIME_MATCHES
* flag set unless [Ii] were match possibilities */
- if (UNLIKELY(PL_in_utf8_turkic_locale) && ! match) {
+ if (UNLIKELY(IN_UTF8_TURKIC_LOCALE) && ! match) {
if (utf8_target) {
if (c == LATIN_CAPITAL_LETTER_I_WITH_DOT_ABOVE) {
if (ANYOF_BITMAP_TEST(n, 'i')) {
diff --git a/utf8.c b/utf8.c
index 28d8dae2dc..4de26a0211 100644
--- a/utf8.c
+++ b/utf8.c
@@ -3167,7 +3167,7 @@ Perl__to_uni_fold_flags(pTHX_ UV c, U8* p, STRLEN *lenp, U8 flags)
/* Treat a non-Turkic UTF-8 locale as not being in locale at all,
* except for potentially warning */
CHECK_AND_WARN_PROBLEMATIC_LOCALE_;
- if (IN_UTF8_CTYPE_LOCALE && ! PL_in_utf8_turkic_locale) {
+ if (IN_UTF8_CTYPE_LOCALE && ! IN_UTF8_TURKIC_LOCALE) {
flags &= ~FOLD_FLAGS_LOCALE;
}
else {
@@ -3720,7 +3720,7 @@ S_turkic_uc(pTHX_ const U8 * const p, const U8 * const e,
if (flags & (locale_flags)) { \
CHECK_AND_WARN_PROBLEMATIC_LOCALE_; \
if (IN_UTF8_CTYPE_LOCALE) { \
- if (UNLIKELY(PL_in_utf8_turkic_locale)) { \
+ if (UNLIKELY(IN_UTF8_TURKIC_LOCALE)) { \
UV ret = turkic(p, e, ustrp, lenp); \
if (ret) return ret; \
} \
@@ -4299,7 +4299,7 @@ Perl_foldEQ_utf8_flags(pTHX_ const char *s1, char **pe1, UV l1, bool u1,
if (flags & FOLDEQ_LOCALE) {
if (IN_UTF8_CTYPE_LOCALE) {
- if (UNLIKELY(PL_in_utf8_turkic_locale)) {
+ if (UNLIKELY(IN_UTF8_TURKIC_LOCALE)) {
flags_for_folder |= FOLD_FLAGS_LOCALE;
}
else {