Revert "Blind attempt to fix _configthreadlocale() failures on MinGW."
authorThomas Munro <[email protected]>
Wed, 27 Nov 2024 09:56:41 +0000 (22:56 +1300)
committerThomas Munro <[email protected]>
Wed, 27 Nov 2024 10:20:10 +0000 (23:20 +1300)
This reverts commit 2cf91ccb73ce888c44e3751548fb7c77e87335f2.

When using the old msvcrt.dll, MinGW would supply its own dummy version
of _configthreadlocale() that just returns -1 if you try to use it.  For
a time we tolerated that to shut the build farm up.  We would fall back
to code that was enough for the tests to pass, but it would surely have
risked crashing a real multithreaded program.

We don't need that kludge anymore, because we can count on ucrt.  We
expect the real _configthreadlocale() to be present, and the ECPG tests
will now fail if it isn't.  The workaround was dead code and it's time
to revert it.

(A later  still under review proposes to remove this use of
_configthreadlocale() completely but we're unwinding this code in
steps.)

Reviewed-by: Peter Eisentraut <[email protected]>
Discussion: https://postgr.es/m/d9e7731c-ca1b-477c-9298-fa51e135574a%40eisentraut.org

src/interfaces/ecpg/ecpglib/descriptor.c
src/interfaces/ecpg/ecpglib/execute.c

index 56e2bc41531d78d7de0a84ffc36582d6a9d03923..aee888432f0a610c08e13660e430be9fd5706213 100644 (file)
@@ -512,7 +512,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
        }
 #ifdef WIN32
        if (stmt.oldthreadlocale != -1)
-           (void) _configthreadlocale(stmt.oldthreadlocale);
+           _configthreadlocale(stmt.oldthreadlocale);
 #endif
 #endif
    }
index 466d5600f9b95c743567bb92d13a4b76762b1cc2..b5089eac787c2ab29ca94b9fc8cb90ac6006696b 100644 (file)
@@ -1977,9 +1977,7 @@ ecpg_do_prologue(int lineno, const int compat, const int force_indicator,
     * Make sure we do NOT honor the locale for numeric input/output since the
     * database wants the standard decimal point.  If available, use
     * uselocale() for this because it's thread-safe.  Windows doesn't have
-    * that, but it usually does have _configthreadlocale().  In some versions
-    * of MinGW, _configthreadlocale() exists but always returns -1 --- so
-    * treat that situation as if the function doesn't exist.
+    * that, but it does have _configthreadlocale().
     */
 #ifdef HAVE_USELOCALE
 
@@ -1997,6 +1995,11 @@ ecpg_do_prologue(int lineno, const int compat, const int force_indicator,
 #else
 #ifdef WIN32
    stmt->oldthreadlocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
+   if (stmt->oldthreadlocale == -1)
+   {
+       ecpg_do_epilogue(stmt);
+       return false;
+   }
 #endif
    stmt->oldlocale = ecpg_strdup(setlocale(LC_NUMERIC, NULL), lineno);
    if (stmt->oldlocale == NULL)
@@ -2218,17 +2221,12 @@ ecpg_do_epilogue(struct statement *stmt)
        uselocale(stmt->oldlocale);
 #else
    if (stmt->oldlocale)
+   {
        setlocale(LC_NUMERIC, stmt->oldlocale);
 #ifdef WIN32
-
-   /*
-    * This is a bit trickier than it looks: if we failed partway through
-    * statement initialization, oldthreadlocale could still be 0.  But that's
-    * okay because a call with 0 is defined to be a no-op.
-    */
-   if (stmt->oldthreadlocale != -1)
-       (void) _configthreadlocale(stmt->oldthreadlocale);
+       _configthreadlocale(stmt->oldthreadlocale);
 #endif
+   }
 #endif
 
    free_statement(stmt);