[ccing bug-gnulib; this is about <https://bugs.gnu.org/42095>.]

> The latest changes made this code run even in the MinGW build, not
> sure why (perhaps because 'getrandom' uses 'open'?).

That's part of it. It's also needed for recent changes to the getloadavg module.
And I see that the at-internal module also depends on the 'open' module, I
presume because lib/openat-proc.c opens /proc/self/fd/NNN/, but this surely
won't work in mingw.

As I understand it the basic issue here is that we want O_CLOEXEC support even
on platforms that lack it, and we don't want all the calling software to play
games with "#ifdef O_CLOEXEC" and the like.

I attempted to work around this particular problem by installing the attached
workaround into Gnulib and updating Emacs accordingly. Please give it a try.
Perhaps this should be fixed more systematically in Gnulib instead of worked
around, but I suppose that might entail some merging between Emacs's and
Gnulib's ways of dealing with file names under MS-Windows and I'll leave it to
the MS-Windows experts to figure out how to do that, or whether they want to do
it at all.
>From a01be1645717a029e571fd0dbb42245f05aff88c Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Sun, 28 Jun 2020 13:18:11 -0700
Subject: [PATCH] =?UTF-8?q?getrandom:=20do=20not=20depend=20on=20=E2=80=98?=
 =?UTF-8?q?open=E2=80=99=20on=20mingw?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Similarly for at-internal, getloadavg.  These modules do not call
the ‘open’ function when they are compiled on mingw.  On mingw,
this avoids having to compile open.c when building Emacs, which
does its own thing with ‘open’.
* modules/at-internal, modules/getloadavg, modules/getrandom:
(Depends-on): Don’t depend on ‘open’ on mingw.
(Depends-on): Require AC_CANONICAL_HOST, for host_os.
* modules/getloadavg (Depends-on):
Depend on intprops, open, stdbool, stdlib only if compiling
getloadavg.c.
---
 ChangeLog           | 14 ++++++++++++++
 modules/at-internal |  3 ++-
 modules/getloadavg  |  9 +++++----
 modules/getrandom   |  3 ++-
 4 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 84a1bd472..c6e26120e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2020-06-28  Paul Eggert  <egg...@cs.ucla.edu>
+
+	getrandom: do not depend on ‘open’ on mingw
+	Similarly for at-internal, getloadavg.  These modules do not call
+	the ‘open’ function when they are compiled on mingw.  On mingw,
+	this avoids having to compile open.c when building Emacs, which
+	does its own thing with ‘open’.
+	* modules/at-internal, modules/getloadavg, modules/getrandom:
+	(Depends-on): Don’t depend on ‘open’ on mingw.
+	(Depends-on): Require AC_CANONICAL_HOST, for host_os.
+	* modules/getloadavg (Depends-on):
+	Depend on intprops, open, stdbool, stdlib only if compiling
+	getloadavg.c.
+
 2020-06-28  Bruno Haible  <br...@clisp.org>
 
 	doc: Add a note about sigprocmask vs. pthread_sigmask.
diff --git a/modules/at-internal b/modules/at-internal
index d58c9b0b4..2a37779f7 100644
--- a/modules/at-internal
+++ b/modules/at-internal
@@ -9,11 +9,12 @@ Depends-on:
 errno
 fcntl-h
 intprops
-open
+open       [case $host_os in mingw*) false;; *) :;; esac]
 sys_stat
 unistd
 
 configure.ac:
+AC_REQUIRE([AC_CANONICAL_HOST])
 
 Makefile.am:
 lib_SOURCES += openat-priv.h openat-proc.c
diff --git a/modules/getloadavg b/modules/getloadavg
index 8adb9a784..21955b782 100644
--- a/modules/getloadavg
+++ b/modules/getloadavg
@@ -7,12 +7,13 @@ m4/getloadavg.m4
 
 Depends-on:
 extensions
-intprops
-open
-stdbool
-stdlib
+intprops  [test $HAVE_GETLOADAVG = 0]
+open      [case $host_os in mingw*) false;; *) test $HAVE_GETLOADAVG = 0;; esac]
+stdbool   [test $HAVE_GETLOADAVG = 0]
+stdlib    [test $HAVE_GETLOADAVG = 0]
 
 configure.ac:
+AC_REQUIRE([AC_CANONICAL_HOST])
 gl_GETLOADAVG
 if test $HAVE_GETLOADAVG = 0; then
   AC_LIBOBJ([getloadavg])
diff --git a/modules/getrandom b/modules/getrandom
index 76437eb5a..f1c359706 100644
--- a/modules/getrandom
+++ b/modules/getrandom
@@ -9,9 +9,10 @@ Depends-on:
 sys_random
 fcntl-h             [test $HAVE_GETRANDOM = 0 || test $REPLACE_GETRANDOM = 1]
 minmax              [test $HAVE_GETRANDOM = 0 || test $REPLACE_GETRANDOM = 1]
-open                [test $HAVE_GETRANDOM = 0 || test $REPLACE_GETRANDOM = 1]
+open                [case $host_os in mingw*) false;; *) test $HAVE_GETRANDOM = 0 || test $REPLACE_GETRANDOM = 1;; esac]
 
 configure.ac:
+AC_REQUIRE([AC_CANONICAL_HOST])
 gl_FUNC_GETRANDOM
 if test $HAVE_GETRANDOM = 0 || test $REPLACE_GETRANDOM = 1; then
   AC_LIBOBJ([getrandom])
-- 
2.17.1

Reply via email to