From 4fbeb868b1acf6c760a5ad23b3be3cc70c6afdb6 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Wed, 20 Nov 2024 15:22:23 +1300
Subject: [PATCH 1/3] Remove configure check for _configthreadlocale().

All modern Windows systems have _configthreadlocale().  It was
introduced in msvcrt80.dll as used by Visual Studio 2005.  Historically,
MinGW was stuck on even older msvcrt.dll, but added its own dummy
implementation years ago anyway, rendering the configure test useless.

We can handle MinGW's dummy implementation, but in practice we don't
encounter it anymore because MinGW uses ucrt by default.

Discussion: https://postgr.es/m/CWZBBRR6YA8D.8EHMDRGLCKCD%40neon.tech
---
 configure                                    | 11 -----------
 configure.ac                                 |  1 -
 meson.build                                  |  1 -
 src/include/pg_config.h.in                   |  3 ---
 src/interfaces/ecpg/ecpglib/descriptor.c     |  4 ++--
 src/interfaces/ecpg/ecpglib/ecpglib_extern.h |  2 +-
 src/interfaces/ecpg/ecpglib/execute.c        |  4 ++--
 7 files changed, 5 insertions(+), 21 deletions(-)

diff --git a/configure b/configure
index f58eae1baa8..728deeb30ff 100755
--- a/configure
+++ b/configure
@@ -15812,17 +15812,6 @@ fi
 
 # Win32 (really MinGW) support
 if test "$PORTNAME" = "win32"; then
-  for ac_func in _configthreadlocale
-do :
-  ac_fn_c_check_func "$LINENO" "_configthreadlocale" "ac_cv_func__configthreadlocale"
-if test "x$ac_cv_func__configthreadlocale" = xyes; then :
-  cat >>confdefs.h <<_ACEOF
-#define HAVE__CONFIGTHREADLOCALE 1
-_ACEOF
-
-fi
-done
-
   case " $LIBOBJS " in
   *" dirmod.$ac_objext "* ) ;;
   *) LIBOBJS="$LIBOBJS dirmod.$ac_objext"
diff --git a/configure.ac b/configure.ac
index 82c5009e3e8..b7aef8ac11e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1816,7 +1816,6 @@ fi
 
 # Win32 (really MinGW) support
 if test "$PORTNAME" = "win32"; then
-  AC_CHECK_FUNCS(_configthreadlocale)
   AC_LIBOBJ(dirmod)
   AC_LIBOBJ(kill)
   AC_LIBOBJ(open)
diff --git a/meson.build b/meson.build
index 5b0510cef78..2accff2c992 100644
--- a/meson.build
+++ b/meson.build
@@ -2614,7 +2614,6 @@ endif
 # XXX: Might be worth conditioning some checks on the OS, to avoid doing
 # unnecessary checks over and over, particularly on windows.
 func_checks = [
-  ['_configthreadlocale', {'skip': host_system != 'windows'}],
   ['backtrace_symbols', {'dependencies': [execinfo_dep]}],
   ['clock_gettime', {'dependencies': [rt_dep], 'define': false}],
   ['copyfile'],
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index cdd9a6e9355..130d0216d7d 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -529,9 +529,6 @@
 /* Define to 1 if your compiler understands __builtin_unreachable. */
 #undef HAVE__BUILTIN_UNREACHABLE
 
-/* Define to 1 if you have the `_configthreadlocale' function. */
-#undef HAVE__CONFIGTHREADLOCALE
-
 /* Define to 1 if you have __cpuid. */
 #undef HAVE__CPUID
 
diff --git a/src/interfaces/ecpg/ecpglib/descriptor.c b/src/interfaces/ecpg/ecpglib/descriptor.c
index ad279e245c4..56e2bc41531 100644
--- a/src/interfaces/ecpg/ecpglib/descriptor.c
+++ b/src/interfaces/ecpg/ecpglib/descriptor.c
@@ -490,7 +490,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
 		Assert(ecpg_clocale);
 		stmt.oldlocale = uselocale(ecpg_clocale);
 #else
-#ifdef HAVE__CONFIGTHREADLOCALE
+#ifdef WIN32
 		stmt.oldthreadlocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
 #endif
 		stmt.oldlocale = ecpg_strdup(setlocale(LC_NUMERIC, NULL), lineno);
@@ -510,7 +510,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
 			setlocale(LC_NUMERIC, stmt.oldlocale);
 			ecpg_free(stmt.oldlocale);
 		}
-#ifdef HAVE__CONFIGTHREADLOCALE
+#ifdef WIN32
 		if (stmt.oldthreadlocale != -1)
 			(void) _configthreadlocale(stmt.oldthreadlocale);
 #endif
diff --git a/src/interfaces/ecpg/ecpglib/ecpglib_extern.h b/src/interfaces/ecpg/ecpglib/ecpglib_extern.h
index bad3cd9920b..75cc68275bd 100644
--- a/src/interfaces/ecpg/ecpglib/ecpglib_extern.h
+++ b/src/interfaces/ecpg/ecpglib/ecpglib_extern.h
@@ -77,7 +77,7 @@ struct statement
 	locale_t	oldlocale;
 #else
 	char	   *oldlocale;
-#ifdef HAVE__CONFIGTHREADLOCALE
+#ifdef WIN32
 	int			oldthreadlocale;
 #endif
 #endif
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c
index c578c21cf66..466d5600f9b 100644
--- a/src/interfaces/ecpg/ecpglib/execute.c
+++ b/src/interfaces/ecpg/ecpglib/execute.c
@@ -1995,7 +1995,7 @@ ecpg_do_prologue(int lineno, const int compat, const int force_indicator,
 		return false;
 	}
 #else
-#ifdef HAVE__CONFIGTHREADLOCALE
+#ifdef WIN32
 	stmt->oldthreadlocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
 #endif
 	stmt->oldlocale = ecpg_strdup(setlocale(LC_NUMERIC, NULL), lineno);
@@ -2219,7 +2219,7 @@ ecpg_do_epilogue(struct statement *stmt)
 #else
 	if (stmt->oldlocale)
 		setlocale(LC_NUMERIC, stmt->oldlocale);
-#ifdef HAVE__CONFIGTHREADLOCALE
+#ifdef WIN32
 
 	/*
 	 * This is a bit trickier than it looks: if we failed partway through
-- 
2.39.5 (Apple Git-154)

