From: | Peter Eisentraut <peter(at)eisentraut(dot)org> |
---|---|
To: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | _CRT_glob stuff |
Date: | 2025-09-18 10:02:58 |
Message-ID: | 1053279b-da01-4eb4-b7a3-da6b5d8f73d1@eisentraut.org |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
When you compile on Windows with a sufficiently new gcc or clang you'll
get errors or warnings like this:
../src/common/exec.c:49:17: error: '_CRT_glob' initialized and declared
'extern' [-Werror]
49 | extern int _CRT_glob = 0; /* 0 turns off
globbing; 1 turns it on */
or
../src/common/exec.c:49:12: error: 'extern' variable has an initializer
[-Werror,-Wextern-initializer]
49 | extern int _CRT_glob = 0; /* 0 turns off
globbing; 1 turns it on */
| ^
../src/common/exec.c:49:12: error: no previous extern declaration for
non-static variable '_CRT_glob' [-Werror,-Wmissing-variable-declarations]
../src/common/exec.c:49:8: note: declare 'static' if the variable is not
intended to be used outside of this translation unit
49 | extern int _CRT_glob = 0; /* 0 turns off
globbing; 1 turns it on */
| ^
(You can test this out on non-Windows by disabling the #if around it in
src/common/exec.c.)
It took me a bit of research to figure out what
extern int foo = 0;
even means. It turns out that the "extern" is ignored in that case. So
I suggest we remove it from the code, to eliminate the confusion and the
warnings. And then we have to add in a real extern declaration (without
initializer) to satisfy -Wmissing-variable-declarations. So it should
look like
diff --git a/src/common/exec.c b/src/common/exec.c
index 8b690a10185..cca89f04074 100644
--- a/src/common/exec.c
+++ b/src/common/exec.c
@@ -46,7 +46,8 @@
/* Inhibit mingw CRT's auto-globbing of command line arguments */
#if defined(WIN32) && !defined(_MSC_VER)
-extern int _CRT_glob = 0; /* 0 turns off globbing; 1 turns it on */
+extern int _CRT_glob;
+int _CRT_glob = 0; /* 0 turns off globbing; 1 turns it
on */
#endif
/*
Here is some relevant documentation that suggests that this is the
correct approach:
https://github.com/mingw-w64/mingw-w64/blob/master/mingw-w64-headers/crt/_mingw.h.in#L476
This also says that the default is 0 anyway, so it's not clear whether
this is even useful anymore. The commit that introduced this (commit
b787c554c26) is from 2022, so it's not that long ago. (It appears to be
some old mingw vs. new mingw issue?)
From | Date | Subject | |
---|---|---|---|
Next Message | Ashutosh Bapat | 2025-09-18 10:24:32 | Re: Report bytes and transactions actually sent downtream |
Previous Message | Jonathan Abdiel Gonzalez Valdebenito | 2025-09-18 09:56:38 | Re: refactor backend type lists |