From 71866d70d8622197df5d043adfd0d91cb1e26c5a Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Fri, 17 Nov 2023 06:50:34 -0700 Subject: [PATCH] Fixup FAKE_MINGW This is used (by me) to partially emulate MingW on a *nix platform. It was passing all its tests, but I discovered that I had the wrong #if which was hence not enabling crucial parts of the emulation. --- intrpvar.h | 2 +- locale.c | 11 +++++++---- perl.h | 19 ++++++++++++------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/intrpvar.h b/intrpvar.h index e17ce3fb5c56..da376a4143c6 100644 --- a/intrpvar.h +++ b/intrpvar.h @@ -270,7 +270,7 @@ instead, or to use the C macro. =cut */ -PERLVAR(I, na, STRLEN) /* for use in SvPV when length is +PERLVARI(I, na, STRLEN, 0) /* for use in SvPV when length is Not Applicable */ /* stat stuff */ diff --git a/locale.c b/locale.c index db054169c7cf..632f37595b97 100644 --- a/locale.c +++ b/locale.c @@ -419,8 +419,6 @@ static int debug_initialization = 0; # undef P_CS_PRECEDES # undef CURRENCY_SYMBOL # define CP_UTF8 -1 -# undef _configthreadlocale -# define _configthreadlocale(arg) NOOP # define MultiByteToWideChar(cp, flags, byte_string, m1, wstring, req_size) \ (PERL_UNUSED_ARG(cp), \ @@ -430,6 +428,10 @@ static int debug_initialization = 0; (PERL_UNUSED_ARG(cp), \ wcsrtombs(byte_string, &(wstring), req_size, NULL) + 1) +# define strftime(buf, bufsize, fmt, mytm) \ + (instr(fmt, "%r") || instr(fmt, "%O") || instr(fmt, "%E") \ + ? 0 \ + : strftime(buf, bufsize, fmt, mytm)) # ifdef USE_LOCALE static const wchar_t * wsetlocale_buf = NULL; @@ -472,8 +474,8 @@ S_wsetlocale(const int category, const wchar_t * wlocale) Size_t string_size = wcslen(wresult) + 1; if (wsetlocale_buf_size == 0) { - Newx(wsetlocale_buf, string_size, wchar_t); - wsetlocale_buf_size = string_size; + Newx(wsetlocale_buf, 4096, wchar_t); + wsetlocale_buf_size = 4096; # ifdef MULTIPLICITY @@ -4228,6 +4230,7 @@ STATIC const char * S_wrap_wsetlocale(pTHX_ const int category, const char *locale) { PERL_ARGS_ASSERT_WRAP_WSETLOCALE; + DEBUG_L(PerlIO_printf(Perl_debug_log, "Entering wrap_wsetlocale, cat=%d locale=%s\n", category, locale)); /* Calls _wsetlocale(), converting the parameters/return to/from * Perl-expected forms as if plain setlocale() were being called instead. diff --git a/perl.h b/perl.h index 590c875bcfab..ab9f619c21bb 100644 --- a/perl.h +++ b/perl.h @@ -45,12 +45,6 @@ #include "config.h" -#ifndef WIN32 /* XXX temp */ -# define _configthreadlocale(x) (! cBOOL(x)) -# define _DISABLE_PER_THREAD_LOCALE 0 -# define _ENABLE_PER_THREAD_LOCALE 1 -#endif - /* This fakes up using Mingw for locale handling. In order to not define WIN32 * in this file (and hence throughout the code that isn't expecting it), this * doesn't define that, but defines the appropriate things that would otherwise @@ -61,8 +55,9 @@ # define NO_POSIX_2008_LOCALE # undef HAS_NL_LANGINFO # undef HAS_NL_LANGINFO_L +//# define NO_LOCALE_MESSAGES # undef _UCRT -# ifdef USE_LOCALE +# ifndef NO_LOCALE # define TS_W32_BROKEN_LOCALECONV # ifdef USE_THREADS # define EMULATE_THREAD_SAFE_LOCALES @@ -7182,6 +7177,16 @@ the plain locale pragma without a parameter (S>) is in effect. # endif # ifdef WIN32_USE_FAKE_OLD_MINGW_LOCALES + +# define _DISABLE_PER_THREAD_LOCALE 1 +# define _ENABLE_PER_THREAD_LOCALE 2 +# define configthreadlocale_(arg, na) \ + ({ assert(inRANGE(arg, 0, _ENABLE_PER_THREAD_LOCALE)); \ + const int old = na; \ + if (arg != 0) na = arg; \ + old; \ + }) +# define _configthreadlocale(arg) configthreadlocale_(arg, my_perl->Ina) \ /* This function is coerced by this Configure option into cleaning up * memory that is static to locale.c. So we call it at termination. Doing * it this way is kludgy but confines having to deal with this