Skip to content

Commit 7de8159

Browse files
committed
Clean up perl.h/makedef.pl common logic
This has gotten two twisty little mazy over time. Clean it up, add comments, and make sure the logic is the same on both.
1 parent d52dd96 commit 7de8159

File tree

2 files changed

+62
-41
lines changed

2 files changed

+62
-41
lines changed

makedef.pl

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ BEGIN
107107
}
108108
close(CFG);
109109

110+
#==========================================================================
110111
# perl.h logic duplication begins
111112

112113
if ($define{USE_ITHREADS}) {
@@ -143,33 +144,45 @@ BEGIN
143144
if ($define{USE_ITHREADS} && ! $define{NO_LOCALE_THREADS}) {
144145
$define{USE_LOCALE_THREADS} = 1;
145146
}
146-
if (! $define{HAS_SETLOCALE} && $define{HAS_POSIX_2008_LOCALE}) {
147+
148+
if ( $define{HAS_POSIX_2008_LOCALE}
149+
&& ( ! $define{HAS_SETLOCALE} || ( $define{USE_LOCALE_THREADS}
150+
&& ! $define{NO_POSIX_2008_LOCALE})))
151+
{
147152
$define{USE_POSIX_2008_LOCALE} = 1;
148-
$define{USE_THREAD_SAFE_LOCALE} = 1;
149153
}
150-
elsif ( ($define{USE_LOCALE_THREADS} || $define{USE_THREAD_SAFE_LOCALE})
151-
&& ( $define{HAS_POSIX_2008_LOCALE}
152-
|| ($ARGS{PLATFORM} eq 'win32' && ( $cctype !~ /\D/
153-
&& $cctype >= 80)))
154-
&& ! $define{NO_THREAD_SAFE_LOCALE})
154+
155+
if ($define{USE_LOCALE_THREADS} && ! $define{NO_THREAD_SAFE_LOCALE})
156+
{
157+
if ( $define{USE_POSIX_2008_LOCALE}
158+
|| ($ARGS{PLATFORM} eq 'win32' && ( $cctype !~ /\D/
159+
&& $cctype >= 80)))
160+
{
161+
$define{USE_THREAD_SAFE_LOCALE} = 1;
162+
}
163+
}
164+
165+
if ($define{USE_POSIX_2008_LOCALE} && $define{HAS_QUERYLOCALE})
155166
{
156-
$define{USE_THREAD_SAFE_LOCALE} = 1 unless $define{USE_THREAD_SAFE_LOCALE};
157-
$define{USE_POSIX_2008_LOCALE} = 1 if $define{HAS_POSIX_2008_LOCALE};
167+
$define{USE_QUERYLOCALE} = 1;
168+
169+
# Don't need glibc only code from perl.h
158170
}
159171

160-
if ( ($define{USE_POSIX_2008_LOCALE} && ! $define{HAS_QUERYLOCALE}))
172+
if ($define{USE_POSIX_2008_LOCALE} && ! $define{USE_QUERYLOCALE})
161173
{
162174
$define{USE_PL_CURLOCALES} = 1;
163175
}
164176

165-
if ( $ARGS{PLATFORM} eq 'win32'
166-
&& $define{USE_THREAD_SAFE_LOCALE}
167-
&& $cctype < 140)
177+
if ($ARGS{PLATFORM} eq 'win32' && $define{USE_THREAD_SAFE_LOCALE})
168178
{
169-
$define{TS_W32_BROKEN_LOCALECONV} = 1;
179+
if ($cctype < 140) {
180+
$define{TS_W32_BROKEN_LOCALECONV} = 1;
181+
}
170182
}
171183

172184
# perl.h logic duplication ends
185+
#==========================================================================
173186

174187
print STDERR "Defines: (" . join(' ', sort keys %define) . ")\n"
175188
unless $ARGS{PLATFORM} eq 'test';

perl.h

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,10 @@ violations are fatal.
10641064

10651065
#include "perl_langinfo.h" /* Needed for _NL_LOCALE_NAME */
10661066

1067+
/* =========================================================================
1068+
* The defines from here to the following ===== line are unfortunately
1069+
* duplicated in makedef.pl, and changes here MUST also be made there */
1070+
10671071
/* If not forbidden, we enable locale handling if either 1) the POSIX 2008
10681072
* functions are available, or 2) just the setlocale() function. This logic is
10691073
* repeated in t/loc_tools.pl and makedef.pl; The three should be kept in
@@ -1215,35 +1219,32 @@ violations are fatal.
12151219
# define LC_ALL_INDEX_ PERL_DUMMY_TOD_ + 1
12161220
# endif
12171221

1218-
/* XXX The next few defines are unfortunately duplicated in makedef.pl, and
1219-
* changes here MUST also be made there */
12201222

12211223
# if defined(USE_ITHREADS) && ! defined(NO_LOCALE_THREADS)
12221224
# define USE_LOCALE_THREADS
12231225
# endif
1224-
# if ! defined(HAS_SETLOCALE) && defined(HAS_POSIX_2008_LOCALE)
1225-
# define USE_POSIX_2008_LOCALE
1226-
# ifdef USE_LOCALE_THREADS
1227-
# define USE_THREAD_SAFE_LOCALE
1228-
# endif
1229-
/* If compiled with
1230-
* -DUSE_THREAD_SAFE_LOCALE, will do so even
1231-
* on unthreaded builds */
1232-
# elif (defined(USE_LOCALE_THREADS) || defined(USE_THREAD_SAFE_LOCALE)) \
1233-
&& ( defined(HAS_POSIX_2008_LOCALE) \
1234-
|| (defined(WIN32) && defined(_MSC_VER))) \
1235-
&& ! defined(NO_THREAD_SAFE_LOCALE)
1236-
# ifndef USE_THREAD_SAFE_LOCALE
1226+
1227+
/* Use POSIX 2008 locales if available, and no alternative exists
1228+
* ('setlocale()' is the alternative); or is threaded and not forbidden to
1229+
* use them */
1230+
# if defined(HAS_POSIX_2008_LOCALE) && ( ! defined(HAS_SETLOCALE) \
1231+
|| ( defined(USE_LOCALE_THREADS) \
1232+
&& ! defined(NO_POSIX_2008_LOCALE)))
1233+
# define USE_POSIX_2008_LOCALE
1234+
# endif
1235+
1236+
/* On threaded builds, use thread-safe locales if they are available and not
1237+
* forbidden. Availability is when we are using POSIX 2008 locales, or
1238+
* Windows for quite a few releases now. */
1239+
# if defined(USE_LOCALE_THREADS) && ! defined(NO_THREAD_SAFE_LOCALE)
1240+
# if defined(USE_POSIX_2008_LOCALE) || (defined(WIN32) && defined(_MSC_VER))
12371241
# define USE_THREAD_SAFE_LOCALE
12381242
# endif
1239-
# ifdef HAS_POSIX_2008_LOCALE
1240-
# define USE_POSIX_2008_LOCALE
1241-
# endif
12421243
# endif
12431244

12441245
# include "perl_langinfo.h" /* Needed for _NL_LOCALE_NAME */
12451246

1246-
/* Allow use of glib's undocumented querylocale() equivalent if asked for, and
1247+
/* Allow use of glibc's undocumented querylocale() equivalent if asked for, and
12471248
* appropriate */
12481249
# ifdef USE_POSIX_2008_LOCALE
12491250
# if defined(HAS_QUERYLOCALE) \
@@ -1262,21 +1263,28 @@ violations are fatal.
12621263
# endif
12631264
# endif
12641265

1266+
/* POSIX 2008 has no means of finding out the current locale without a
1267+
* querylocale; so must keep track of it ourselves */
12651268
# if (defined(USE_POSIX_2008_LOCALE) && ! defined(USE_QUERYLOCALE))
12661269
# define USE_PL_CURLOCALES
12671270
# endif
12681271

1269-
/* Microsoft documentation reads in the change log for VS 2015:
1270-
* "The localeconv function declared in locale.h now works correctly when
1271-
* per-thread locale is enabled. In previous versions of the library, this
1272-
* function would return the lconv data for the global locale, not the
1273-
* thread's locale."
1274-
*/
1275-
# if defined(WIN32) && defined(USE_THREAD_SAFE_LOCALE) && _MSC_VER < 1900
1276-
# define TS_W32_BROKEN_LOCALECONV
1272+
# if defined(WIN32) && defined(USE_THREAD_SAFE_LOCALE)
1273+
1274+
/* Microsoft documentation reads in the change log for VS 2015: "The
1275+
* localeconv function declared in locale.h now works correctly when
1276+
* per-thread locale is enabled. In previous versions of the library, this
1277+
* function would return the lconv data for the global locale, not the
1278+
* thread's locale." */
1279+
# if _MSC_VER < 1900
1280+
# define TS_W32_BROKEN_LOCALECONV
1281+
# endif
12771282
# endif
12781283
#endif
12791284

1285+
/* end of makedef.pl logic duplication
1286+
* ========================================================================= */
1287+
12801288
#ifdef PERL_CORE
12811289

12821290
/* Both typedefs are used in locale.c only, but defined here so that embed.fnc

0 commit comments

Comments
 (0)