Skip to content

Commit d36adde

Browse files
committed
Fix to compile under -DNO_LOCALE
Several problems with this compile option were not caught before 5.28 was frozen.
1 parent fdb7241 commit d36adde

File tree

8 files changed

+87
-34
lines changed

8 files changed

+87
-34
lines changed

embed.fnc

+2
Original file line numberDiff line numberDiff line change
@@ -2765,9 +2765,11 @@ s |bool |isa_lookup |NN HV *stash|NN const char * const name \
27652765
#endif
27662766

27672767
#if defined(PERL_IN_LOCALE_C)
2768+
# ifdef USE_LOCALE
27682769
sn |const char*|category_name |const int category
27692770
s |const char*|switch_category_locale_to_template|const int switch_category|const int template_category|NULLOK const char * template_locale
27702771
s |void |restore_switched_locale|const int category|NULLOK const char * const original_locale
2772+
# endif
27712773
# ifdef HAS_NL_LANGINFO
27722774
sn |const char*|my_nl_langinfo|const nl_item item|bool toggle
27732775
# else

embed.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1724,16 +1724,16 @@
17241724
#define unshare_hek_or_pvn(a,b,c,d) S_unshare_hek_or_pvn(aTHX_ a,b,c,d)
17251725
# endif
17261726
# if defined(PERL_IN_LOCALE_C)
1727-
#define category_name S_category_name
1728-
#define restore_switched_locale(a,b) S_restore_switched_locale(aTHX_ a,b)
17291727
#define save_to_buffer S_save_to_buffer
1730-
#define switch_category_locale_to_template(a,b,c) S_switch_category_locale_to_template(aTHX_ a,b,c)
17311728
# if defined(USE_LOCALE)
1729+
#define category_name S_category_name
17321730
#define new_collate(a) S_new_collate(aTHX_ a)
17331731
#define new_ctype(a) S_new_ctype(aTHX_ a)
17341732
#define new_numeric(a) S_new_numeric(aTHX_ a)
1733+
#define restore_switched_locale(a,b) S_restore_switched_locale(aTHX_ a,b)
17351734
#define set_numeric_radix(a) S_set_numeric_radix(aTHX_ a)
17361735
#define stdize_locale(a) S_stdize_locale(aTHX_ a)
1736+
#define switch_category_locale_to_template(a,b,c) S_switch_category_locale_to_template(aTHX_ a,b,c)
17371737
# if defined(USE_POSIX_2008_LOCALE)
17381738
#define emulate_setlocale S_emulate_setlocale
17391739
# endif

locale.c

+53-20
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,7 @@ S_locking_setlocale(pTHX_
12641264
}
12651265

12661266
#endif
1267+
#ifdef USE_LOCALE
12671268

12681269
STATIC void
12691270
S_set_numeric_radix(pTHX_ const bool use_locale)
@@ -1299,6 +1300,10 @@ S_set_numeric_radix(pTHX_ const bool use_locale)
12991300
}
13001301

13011302
# endif
1303+
#else
1304+
1305+
PERL_UNUSED_ARG(use_locale);
1306+
13021307
#endif /* USE_LOCALE_NUMERIC and can find the radix char */
13031308

13041309
}
@@ -1481,7 +1486,6 @@ S_new_ctype(pTHX_ const char *newctype)
14811486

14821487
#ifndef USE_LOCALE_CTYPE
14831488

1484-
PERL_ARGS_ASSERT_NEW_CTYPE;
14851489
PERL_UNUSED_ARG(newctype);
14861490
PERL_UNUSED_CONTEXT;
14871491

@@ -1994,6 +1998,8 @@ S_new_collate(pTHX_ const char *newcoll)
19941998

19951999
}
19962000

2001+
#endif
2002+
19972003
#ifdef WIN32
19982004

19992005
STATIC char *
@@ -2139,11 +2145,20 @@ Perl_setlocale(const int category, const char * locale)
21392145
{
21402146
/* This wraps POSIX::setlocale() */
21412147

2148+
#ifdef NO_LOCALE
2149+
2150+
PERL_UNUSED_ARG(category);
2151+
PERL_UNUSED_ARG(locale);
2152+
2153+
return "C";
2154+
2155+
#else
2156+
21422157
const char * retval;
21432158
const char * newlocale;
21442159
dSAVEDERRNO;
2145-
DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
21462160
dTHX;
2161+
DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
21472162

21482163
#ifdef USE_LOCALE_NUMERIC
21492164

@@ -2262,6 +2277,8 @@ Perl_setlocale(const int category, const char * locale)
22622277

22632278
return retval;
22642279

2280+
#endif
2281+
22652282
}
22662283

22672284
PERL_STATIC_INLINE const char *
@@ -2414,13 +2431,16 @@ S_my_nl_langinfo(const int item, bool toggle)
24142431
dTHX;
24152432
const char * retval;
24162433

2434+
#ifdef USE_LOCALE_NUMERIC
2435+
24172436
/* We only need to toggle into the underlying LC_NUMERIC locale for these
24182437
* two items, and only if not already there */
24192438
if (toggle && (( item != RADIXCHAR && item != THOUSEP)
24202439
|| PL_numeric_underlying))
2421-
{
2440+
2441+
#endif /* No toggling needed if not using LC_NUMERIC */
2442+
24222443
toggle = FALSE;
2423-
}
24242444

24252445
#if defined(HAS_NL_LANGINFO) /* nl_langinfo() is available. */
24262446
# if ! defined(HAS_THREAD_SAFE_NL_LANGINFO_L) \
@@ -2468,6 +2488,8 @@ S_my_nl_langinfo(const int item, bool toggle)
24682488
do_free = TRUE;
24692489
}
24702490

2491+
# ifdef USE_LOCALE_NUMERIC
2492+
24712493
if (toggle) {
24722494
if (PL_underlying_numeric_obj) {
24732495
cur = PL_underlying_numeric_obj;
@@ -2478,6 +2500,8 @@ S_my_nl_langinfo(const int item, bool toggle)
24782500
}
24792501
}
24802502

2503+
# endif
2504+
24812505
/* We have to save it to a buffer, because the freelocale() just below
24822506
* can invalidate the internal one */
24832507
retval = save_to_buffer(nl_langinfo_l(item, cur),
@@ -5169,17 +5193,16 @@ Perl_my_strerror(pTHX_ const int errnum)
51695193
LOCALE_UNLOCK;
51705194

51715195
# endif /* End of doesn't have strerror_l */
5172-
#endif /* End of does have locale messages */
5173-
5174-
#ifdef DEBUGGING
5196+
# ifdef DEBUGGING
51755197

51765198
if (DEBUG_Lv_TEST) {
51775199
PerlIO_printf(Perl_debug_log, "Strerror returned; saving a copy: '");
51785200
print_bytes_for_locale(errstr, errstr + strlen(errstr), 0);
51795201
PerlIO_printf(Perl_debug_log, "'\n");
51805202
}
51815203

5182-
#endif
5204+
# endif
5205+
#endif /* End of does have locale messages */
51835206

51845207
SAVEFREEPV(errstr);
51855208
return errstr;
@@ -5301,10 +5324,17 @@ L<C<Perl_switch_to_global_locale>|perlapi/switch_to_global_locale>.
53015324
bool
53025325
Perl_sync_locale()
53035326
{
5327+
5328+
#ifndef USE_LOCALE
5329+
5330+
return TRUE;
5331+
5332+
#else
5333+
53045334
const char * newlocale;
53055335
dTHX;
53065336

5307-
#ifdef USE_POSIX_2008_LOCALE
5337+
# ifdef USE_POSIX_2008_LOCALE
53085338

53095339
bool was_in_global_locale = FALSE;
53105340
locale_t cur_obj = uselocale((locale_t) 0);
@@ -5316,11 +5346,11 @@ Perl_sync_locale()
53165346
* will affect the */
53175347
if (cur_obj == LC_GLOBAL_LOCALE) {
53185348

5319-
# ifdef HAS_QUERY_LOCALE
5349+
# ifdef HAS_QUERY_LOCALE
53205350

53215351
do_setlocale_c(LC_ALL, setlocale(LC_ALL, NULL));
53225352

5323-
# else
5353+
# else
53245354

53255355
unsigned int i;
53265356

@@ -5330,17 +5360,17 @@ Perl_sync_locale()
53305360
do_setlocale_r(categories[i], setlocale(categories[i], NULL));
53315361
}
53325362

5333-
# endif
5363+
# endif
53345364

53355365
was_in_global_locale = TRUE;
53365366
}
53375367

5338-
#else
5368+
# else
53395369

53405370
bool was_in_global_locale = TRUE;
53415371

5342-
#endif
5343-
#ifdef USE_LOCALE_CTYPE
5372+
# endif
5373+
# ifdef USE_LOCALE_CTYPE
53445374

53455375
newlocale = savepv(do_setlocale_c(LC_CTYPE, NULL));
53465376
DEBUG_Lv(PerlIO_printf(Perl_debug_log,
@@ -5349,8 +5379,8 @@ Perl_sync_locale()
53495379
new_ctype(newlocale);
53505380
Safefree(newlocale);
53515381

5352-
#endif /* USE_LOCALE_CTYPE */
5353-
#ifdef USE_LOCALE_COLLATE
5382+
# endif /* USE_LOCALE_CTYPE */
5383+
# ifdef USE_LOCALE_COLLATE
53545384

53555385
newlocale = savepv(do_setlocale_c(LC_COLLATE, NULL));
53565386
DEBUG_Lv(PerlIO_printf(Perl_debug_log,
@@ -5359,8 +5389,8 @@ Perl_sync_locale()
53595389
new_collate(newlocale);
53605390
Safefree(newlocale);
53615391

5362-
#endif
5363-
#ifdef USE_LOCALE_NUMERIC
5392+
# endif
5393+
# ifdef USE_LOCALE_NUMERIC
53645394

53655395
newlocale = savepv(do_setlocale_c(LC_NUMERIC, NULL));
53665396
DEBUG_Lv(PerlIO_printf(Perl_debug_log,
@@ -5369,9 +5399,12 @@ Perl_sync_locale()
53695399
new_numeric(newlocale);
53705400
Safefree(newlocale);
53715401

5372-
#endif /* USE_LOCALE_NUMERIC */
5402+
# endif /* USE_LOCALE_NUMERIC */
53735403

53745404
return was_in_global_locale;
5405+
5406+
#endif
5407+
53755408
}
53765409

53775410
#if defined(DEBUGGING) && defined(USE_LOCALE)

makedef.pl

+6
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,9 @@ sub readvar {
574574
PL_collxfrm_mult
575575
Perl_sv_collxfrm
576576
Perl_sv_collxfrm_flags
577+
PL_strxfrm_NUL_replacement
578+
PL_strxfrm_is_behaved
579+
PL_strxfrm_max_cp
577580
);
578581
}
579582

@@ -583,6 +586,9 @@ sub readvar {
583586
PL_numeric_name
584587
PL_numeric_radix_sv
585588
PL_numeric_standard
589+
PL_numeric_underlying
590+
PL_numeric_underlying_is_standard
591+
PL_underlying_numeric_obj
586592
);
587593
}
588594

perl.h

+3
Original file line numberDiff line numberDiff line change
@@ -5657,6 +5657,9 @@ typedef struct am_table_short AMTS;
56575657
# define IN_LC_COMPILETIME(category) 0
56585658
# define IN_LC_RUNTIME(category) 0
56595659
# define IN_LC(category) 0
5660+
# define _CHECK_AND_WARN_PROBLEMATIC_LOCALE
5661+
# define _CHECK_AND_OUTPUT_WIDE_LOCALE_UTF8_MSG(s, send)
5662+
# define _CHECK_AND_OUTPUT_WIDE_LOCALE_CP_MSG(c)
56605663
#endif
56615664

56625665

proto.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -4669,26 +4669,26 @@ PERL_CALLCONV SV* Perl_hfree_next_entry(pTHX_ HV *hv, STRLEN *indexp);
46694669
assert(hv); assert(indexp)
46704670
#endif
46714671
#if defined(PERL_IN_LOCALE_C)
4672-
STATIC const char* S_category_name(const int category);
4673-
STATIC void S_restore_switched_locale(pTHX_ const int category, const char * const original_locale);
46744672
#ifndef PERL_NO_INLINE_FUNCTIONS
46754673
PERL_STATIC_INLINE const char * S_save_to_buffer(const char * string, char **buf, Size_t *buf_size, const Size_t offset)
46764674
__attribute__warn_unused_result__;
46774675
#define PERL_ARGS_ASSERT_SAVE_TO_BUFFER \
46784676
assert(buf_size)
46794677
#endif
46804678

4681-
STATIC const char* S_switch_category_locale_to_template(pTHX_ const int switch_category, const int template_category, const char * template_locale);
46824679
# if defined(USE_LOCALE)
4680+
STATIC const char* S_category_name(const int category);
46834681
STATIC void S_new_collate(pTHX_ const char* newcoll);
46844682
STATIC void S_new_ctype(pTHX_ const char* newctype);
46854683
#define PERL_ARGS_ASSERT_NEW_CTYPE \
46864684
assert(newctype)
46874685
STATIC void S_new_numeric(pTHX_ const char* newnum);
4686+
STATIC void S_restore_switched_locale(pTHX_ const int category, const char * const original_locale);
46884687
STATIC void S_set_numeric_radix(pTHX_ const bool use_locale);
46894688
STATIC char* S_stdize_locale(pTHX_ char* locs);
46904689
#define PERL_ARGS_ASSERT_STDIZE_LOCALE \
46914690
assert(locs)
4691+
STATIC const char* S_switch_category_locale_to_template(pTHX_ const int switch_category, const int template_category, const char * template_locale);
46924692
# if defined(USE_POSIX_2008_LOCALE)
46934693
STATIC const char* S_emulate_setlocale(const int category, const char* locale, unsigned int index, const bool is_index_valid);
46944694
# endif

sv.c

+5
Original file line numberDiff line numberDiff line change
@@ -13330,10 +13330,15 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
1333013330

1333113331
SvTAINT(sv);
1333213332

13333+
#ifdef USE_LOCALE_NUMERIC
13334+
1333313335
if (lc_numeric_set) {
1333413336
RESTORE_LC_NUMERIC(); /* Done outside loop, so don't have to
1333513337
save/restore each iteration. */
1333613338
}
13339+
13340+
#endif
13341+
1333713342
}
1333813343

1333913344
/* =========================================================================

t/lib/warnings/regexec

+12-8
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ Use of \b{} or \B{} for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at -
215215
Use of \b{} or \B{} for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 17.
216216
########
217217
# NAME (?[ ]) in non-UTF-8 locale
218+
require '../loc_tools.pl';
219+
unless (locales_enabled()) {
220+
print("SKIPPED\n# locales not available\n"),exit;
221+
}
218222
eval { require POSIX; POSIX->import("locale_h") };
219223
if ($@) {
220224
print("SKIPPED\n# no POSIX\n"),exit;
@@ -229,14 +233,14 @@ setlocale(&POSIX::LC_CTYPE, "C");
229233
":" =~ /(?[ \: ])/;
230234
no warnings 'locale';
231235
EXPECT
232-
Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 9.
233-
Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 9.
234-
Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 10.
235-
Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 10.
236-
Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 11.
237-
Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 11.
238-
Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 12.
239-
Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 12.
236+
Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 13.
237+
Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 13.
238+
Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 14.
239+
Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 14.
240+
Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 15.
241+
Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 15.
242+
Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 16.
243+
Use of (?[ ]) for non-UTF-8 locale is wrong. Assuming a UTF-8 locale at - line 16.
240244
########
241245
# NAME (?[ ]) in UTF-8 locale
242246
require '../loc_tools.pl';

0 commit comments

Comments
 (0)