[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
AS_CASE failure on Solaris /bin/sh
From: |
Eric Blake |
Subject: |
AS_CASE failure on Solaris /bin/sh |
Date: |
Thu, 30 Oct 2008 07:41:58 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.17) Gecko/20080914 Thunderbird/2.0.0.17 Mnenhy/0.7.5.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I noticed a testsuite failure on Solaris 10:
case `touch file; false` in #(
*) ;;
esac && test -f file && echo fifteen
was mistakenly silent. POSIX is not clear on this point (it requires that
the exit status of the case be that of the compound-list in the case that
matched, but in the case that matched, there is no compound-list).
Therefore, the test is slightly bogus. On the other hand, POSIX is clear
that when no case matches, the exit status be 0, so Solaris has a definite
bug:
$ bash -c 'case `false` in esac; echo $?'
0
$ /bin/sh -c 'case `false` in esac; echo $?'
255
$ bash -c 'case `false` in ?);; esac; echo $?'
0
$ /bin/sh -c 'case `false` in ?);; esac; echo $?'
255
When invoked with only one argument, AS_CASE always provided a default
case (although with an empty compound-list, so we are back to the question
of interpretation of POSIX). But when called with three arguments, where
the lone case does not match, it is possible to make AS_CASE demonstrate
the Solaris bug; and as long as we are working around the bug, we might as
well also work around the inconsistency of an empty case, by modifying
AS_CASE to guarantee that every matched case has a compound-list.
I'm committing this:
- --
Don't work too hard, make some time for fun as well!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkkJuaYACgkQ84KuGfSFAYBkFACcD8QwdvcJBX1iCkv/NosCifgD
suAAoLqZNKRdzUQRd2liOPRELFIYOhK+
=FCsx
-----END PGP SIGNATURE-----
>From a78b49741374d1f4f18fc6f19158c346caad36cf Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 30 Oct 2008 06:56:44 -0600
Subject: [PATCH] Work around Solaris /bin/sh case bug.
* lib/m4sugar/m4sh.m4 (_AS_CASE, _AS_CASE_DEFAULT): Always provide
a non-empty command list.
(AS_CASE): Always guarantee that a case will match.
* doc/autoconf.texi (Limitations of Builtins) <case>: Document the
Solaris bug, and mention AS_CASE.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 9 +++++++++
doc/autoconf.texi | 13 +++++++++++++
lib/m4sugar/m4sh.m4 | 11 +++++++----
3 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8d2cd25..e19a3f6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-10-30 Eric Blake <address@hidden>
+
+ Work around Solaris /bin/sh case bug.
+ * lib/m4sugar/m4sh.m4 (_AS_CASE, _AS_CASE_DEFAULT): Always provide
+ a non-empty command list.
+ (AS_CASE): Always guarantee that a case will match.
+ * doc/autoconf.texi (Limitations of Builtins) <case>: Document the
+ Solaris bug, and mention AS_CASE.
+
2008-10-30 Paolo Bonzini <address@hidden>
Require _AS_CR_PREPARE where appropriate.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 1a2f748..d2997ef 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -14842,6 +14842,19 @@ Limitations of Builtins
@error{}Syntax error: ";" unexpected (expecting ")")
@end example
+Posix requires @command{case} to give an exit status of 0 if no cases
+match. However, @command{/bin/sh} in Solaris 10 does not obey this
+rule. Meanwhile, it is unclear whether a case that matches, but
+contains no statements, must also change the exit status to 0. The M4sh
+macro @code{AS_CASE} works around these inconsistencies.
+
address@hidden
+$ @kbd{bash -c 'case `false` in ?) ;; esac; echo $?'}
+0
+$ @kbd{/bin/sh -c 'case `false` in ?) ;; esac; echo $?'}
+255
address@hidden example
+
@item @command{cd}
@c ---------------
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index a67c30d..1f1f599 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -492,16 +492,19 @@ _AS_UNSET_PREPARE
# | *) DEFAULT ;;
# | esac
# The shell comments are intentional, to work around people who don't
-# realize the impacts of using insufficient m4 quoting.
+# realize the impacts of using insufficient m4 quoting. This macro
+# always provides a default case, to work around a Solaris /bin/sh
+# bug regarding the exit status when no case matches.
m4_define([_AS_CASE],
[ address@hidden:@(]
- $1[)] $2 ;;])
+ $1[)] m4_default([$2], [:]) ;;])
m4_define([_AS_CASE_DEFAULT],
[ address@hidden:@(]
- *[)] $1 ;;])
+ *[)] m4_default([$1], [:]) ;;])
m4_defun([AS_CASE],
-[case $1 in[]m4_map_args_pair([_$0], [_$0_DEFAULT], m4_shift($@))
+[case $1 in[]m4_map_args_pair([_$0], [_$0_DEFAULT],
+ m4_shift(address@hidden(m4_eval([$# & 1]), [1], [,])))
esac])# AS_CASE
--
1.6.0.2
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- AS_CASE failure on Solaris /bin/sh,
Eric Blake <=