Skip to content

Commit

Permalink
Fixup FAKE_MINGW
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
khwilliamson committed Feb 2, 2024
1 parent 6ce2564 commit 71866d7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion intrpvar.h
Expand Up @@ -270,7 +270,7 @@ instead, or to use the C<SvPV_nolen> 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 */
Expand Down
11 changes: 7 additions & 4 deletions locale.c
Expand Up @@ -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), \
Expand All @@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
19 changes: 12 additions & 7 deletions perl.h
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -7182,6 +7177,16 @@ the plain locale pragma without a parameter (S<C<use locale>>) 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
Expand Down

0 comments on commit 71866d7

Please sign in to comment.