summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2021-04-20 21:24:15 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2021-04-20 22:09:21 -0700
commit9fb598fbad0fbf0b25ca5bde1526b954b2fd0a05 (patch)
tree7ff7a2469ae48a010d30a3ef070df6abdd20c62f
parent59dc7d0d84be079b882a20d61ac753100166dd8c (diff)
downloadm4-9fb598fbad0fbf0b25ca5bde1526b954b2fd0a05.tar.gz
maint: port to macOS 11.2.3 (arm64)
* m4/gnulib-cache.m4: Add fopen-gnu, replacing cloexec and fopen. Avoid getopt-posix-tests, since they are not needed for m4 and currently fail on macOS 11.2.3 (arm64). * src/builtin.c (m4_incr, m4_decr): Avoid undefined behavior on integer overflow that causes tests to fail on macOS. * src/debug.c (debug_set_output): * src/output.c (m4_tmpfile, m4_tmpopen): * src/path.c (m4_fopen): Use GNU fopen with "e" rather than set_cloexec_flag. This is simpler, and works around a Gnulib bug on macOS with fopen being replaced by rpl_fopen sometimes but not other times. * src/freeze.c (produce_frozen_state): Use GNU fopen with "e"; no need to expose the fd to subprocesses.
-rw-r--r--m4/gnulib-cache.m49
-rw-r--r--src/builtin.c14
-rw-r--r--src/debug.c6
-rw-r--r--src/freeze.c2
-rw-r--r--src/output.c9
-rw-r--r--src/path.c5
6 files changed, 21 insertions, 24 deletions
diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4
index 13c88156..5ba60b59 100644
--- a/m4/gnulib-cache.m4
+++ b/m4/gnulib-cache.m4
@@ -40,6 +40,7 @@
# --no-conditional-dependencies \
# --no-libtool \
# --macro-prefix=M4 \
+# --avoid=getopt-posix-tests \
# --avoid=lock-tests \
# --avoid=tls-tests \
# announce-gen \
@@ -51,7 +52,6 @@
# c-ctype \
# c-stack \
# clean-temp \
-# cloexec \
# close-stream \
# closein \
# config-h \
@@ -64,7 +64,7 @@
# fdl-1.3 \
# fflush \
# filenamecat \
-# fopen \
+# fopen-gnu \
# fopen-safer \
# fseeko \
# gendocs \
@@ -122,7 +122,6 @@ gl_MODULES([
c-ctype
c-stack
clean-temp
- cloexec
close-stream
closein
config-h
@@ -135,7 +134,7 @@ gl_MODULES([
fdl-1.3
fflush
filenamecat
- fopen
+ fopen-gnu
fopen-safer
fseeko
gendocs
@@ -182,7 +181,7 @@ gl_MODULES([
xvasprintf-posix
])
gl_WITH_CXX_TESTS
-gl_AVOID([lock-tests tls-tests])
+gl_AVOID([getopt-posix-tests lock-tests tls-tests])
gl_SOURCE_BASE([lib])
gl_M4_BASE([m4])
gl_PO_BASE([])
diff --git a/src/builtin.c b/src/builtin.c
index 494b3c5a..38da0b4a 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -1155,7 +1155,12 @@ m4_incr (struct obstack *obs, int argc, token_data **argv)
if (!numeric_arg (argv[0], ARG (1), &value))
return;
- shipout_int (obs, value + 1);
+ /* Minimize undefined C behavior on overflow. This code assumes
+ that the implementation-defined overflow when casting unsigned to
+ signed is a silent twos-complement wrap-around. */
+ uint32_t v = value;
+ int32_t w = v + 1;
+ shipout_int (obs, w);
}
static void
@@ -1169,7 +1174,12 @@ m4_decr (struct obstack *obs, int argc, token_data **argv)
if (!numeric_arg (argv[0], ARG (1), &value))
return;
- shipout_int (obs, value - 1);
+ /* Minimize undefined C behavior on overflow. This code assumes
+ that the implementation-defined overflow when casting unsigned to
+ signed is a silent twos-complement wrap-around. */
+ uint32_t v = value;
+ int32_t w = v - 1;
+ shipout_int (obs, w);
}
/* This section contains the macros "divert", "undivert" and "divnum" for
diff --git a/src/debug.c b/src/debug.c
index 069d34d4..a5e3052c 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -210,13 +210,9 @@ debug_set_output (const char *name)
debug_set_file (NULL);
else
{
- fp = fopen (name, "a");
+ fp = fopen (name, "ae");
if (fp == NULL)
return false;
-
- if (set_cloexec_flag (fileno (fp), true) != 0)
- M4ERROR ((warning_status, errno,
- "Warning: cannot protect debug file across forks"));
debug_set_file (fp);
}
return true;
diff --git a/src/freeze.c b/src/freeze.c
index 2a59a3aa..dca2e9cc 100644
--- a/src/freeze.c
+++ b/src/freeze.c
@@ -57,7 +57,7 @@ produce_frozen_state (const char *name)
symbol *bucket;
const builtin *bp;
- file = fopen (name, O_BINARY ? "wb" : "w");
+ file = fopen (name, O_BINARY ? "wbe" : "we");
if (!file)
m4_failure (errno, "cannot open `%s'", name);
diff --git a/src/output.c b/src/output.c
index 361bb5b7..42d7386b 100644
--- a/src/output.c
+++ b/src/output.c
@@ -224,15 +224,12 @@ m4_tmpfile (int divnum)
}
name = m4_tmpname (divnum);
register_temp_file (output_temp_dir, name);
- file = fopen_temp (name, O_BINARY ? "wb+" : "w+", false);
+ file = fopen_temp (name, O_BINARY ? "wb+e" : "w+e", false);
if (file == NULL)
{
unregister_temp_file (output_temp_dir, name);
m4_failure (errno, "cannot create temporary file for diversion");
}
- else if (set_cloexec_flag (fileno (file), true) != 0)
- M4ERROR ((warning_status, errno,
- "Warning: cannot protect diversion across forks"));
return file;
}
@@ -263,11 +260,9 @@ m4_tmpopen (int divnum, bool reread)
}
name = m4_tmpname (divnum);
/* We need update mode, to avoid truncation. */
- file = fopen_temp (name, O_BINARY ? "rb+" : "r+", false);
+ file = fopen_temp (name, O_BINARY ? "rb+e" : "r+e", false);
if (file == NULL)
m4_failure (errno, "cannot create temporary file for diversion");
- else if (set_cloexec_flag (fileno (file), true) != 0)
- m4_error (0, errno, _("cannot protect diversion across forks"));
/* Update mode starts at the beginning of the stream, but sometimes
we want the end. */
else if (!reread && fseeko (file, 0, SEEK_END) != 0)
diff --git a/src/path.c b/src/path.c
index f13f3289..b618c53d 100644
--- a/src/path.c
+++ b/src/path.c
@@ -110,7 +110,7 @@ add_include_directory (const char *dir)
static FILE *
m4_fopen (const char *file)
{
- FILE *fp = fopen (file, "r");
+ FILE *fp = fopen (file, "re");
if (fp)
{
struct stat st;
@@ -121,9 +121,6 @@ m4_fopen (const char *file)
errno = EISDIR;
return NULL;
}
- if (set_cloexec_flag (fd, true) != 0)
- M4ERROR ((warning_status, errno,
- "Warning: cannot protect input file across forks"));
}
return fp;
}