On 10/24/21 2:26 AM, Eli Zaretskii wrote:
Let me turn the table and ask why that declaration of strdup is at all
needed in Gnulib's string.h when it's used in MinGW builds?

It's so that apps can be checked better statically. For example, the contrived code:

   return strcmp (x, strdup (x));

getts a diagnostic about a memory leak. This can be helpful regardless of whether Gnulib's strdup substitute code is used.

The Gnulib wrapper here is merely mimicking what glibc does; it's not a Gnulib invention.


ntlib cannot include config.h,
due to various redefinitions and redirections we do in ms-w32.h for
Emacs.

I now see Emacs has a symbol DEFER_MS_W3_H to deal with this glitch. So how about the attached patch instead? If it doesn't suffice, presumably something like DEFER_MS_W3_H would suffice.

>From 878c4c0d20bb94d9af8cb4161b1a7cbf73c7ba90 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Sat, 23 Oct 2021 20:35:18 -0700
Subject: [PATCH] Include <config.h> first in MS-Windows source

---
 lib-src/ntlib.c | 3 +++
 nt/addpm.c      | 4 ++++
 nt/cmdproxy.c   | 3 +++
 nt/ddeclient.c  | 3 +++
 nt/preprep.c    | 3 +++
 nt/runemacs.c   | 3 +++
 6 files changed, 19 insertions(+)

diff --git a/lib-src/ntlib.c b/lib-src/ntlib.c
index bcbc006431..f1c68cb1b2 100644
--- a/lib-src/ntlib.c
+++ b/lib-src/ntlib.c
@@ -20,6 +20,9 @@ Copyright (C) 1994, 2001-2021 Free Software Foundation, Inc.
 You should have received a copy of the GNU General Public License
 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
 
+#define DEFER_MS_W3_H
+#include <config.h>
+
 #include <windows.h>
 #include <stdlib.h>
 #include <stdio.h>
diff --git a/nt/addpm.c b/nt/addpm.c
index f54a6ea9f7..f07e4c2c5a 100644
--- a/nt/addpm.c
+++ b/nt/addpm.c
@@ -34,6 +34,10 @@
    installed, then the DDE fallback for creating icons the Windows 3.1
    progman way will be used instead, but that is prone to lockups
    caused by other applications not servicing their message queues.  */
+
+#define DEFER_MS_W3_H
+#include <config.h>
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <malloc.h>
diff --git a/nt/cmdproxy.c b/nt/cmdproxy.c
index 224f68b1e8..2bc03673d5 100644
--- a/nt/cmdproxy.c
+++ b/nt/cmdproxy.c
@@ -27,6 +27,9 @@
 You should have received a copy of the GNU General Public License
 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
 
+#define DEFER_MS_W3_H
+#include <config.h>
+
 #include <windows.h>
 
 #include <stdarg.h>  /* va_args */
diff --git a/nt/ddeclient.c b/nt/ddeclient.c
index c577bfcfa9..1c1f7679ea 100644
--- a/nt/ddeclient.c
+++ b/nt/ddeclient.c
@@ -16,6 +16,9 @@
 You should have received a copy of the GNU General Public License
 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
 
+#define DEFER_MS_W3_H
+#include <config.h>
+
 #include <windows.h>
 #include <ddeml.h>
 #include <stdlib.h>
diff --git a/nt/preprep.c b/nt/preprep.c
index 78ed1c3238..48c55ef221 100644
--- a/nt/preprep.c
+++ b/nt/preprep.c
@@ -21,6 +21,9 @@
      based on code from addsection.c
 */
 
+#define DEFER_MS_W3_H
+#include <config.h>
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
diff --git a/nt/runemacs.c b/nt/runemacs.c
index 308e856be2..cce4904d88 100644
--- a/nt/runemacs.c
+++ b/nt/runemacs.c
@@ -40,6 +40,9 @@ Copyright (C) 2001-2021 Free Software Foundation, Inc.
 
 /* #define CHOOSE_NEWEST_EXE */
 
+#define DEFER_MS_W3_H
+#include <config.h>
+
 #include <windows.h>
 #include <string.h>
 #include <malloc.h>
-- 
2.31.1

Reply via email to