[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-gnulib] too many FOO_exit_failure variables
From: |
Paul Eggert |
Subject: |
[Bug-gnulib] too many FOO_exit_failure variables |
Date: |
17 Jul 2003 22:00:34 -0700 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
I ran into this problem when fixing the exit status of GNU 'expr'.
Currently gnulib has several modules that each define their
own FOO_exit_failure variable. For example, a program that
invokes xmalloc and xmemcoll, and which wants to exit with status 2
if there is a failure, must do this at startup:
xalloc_exit_failure = 2;
xmemcoll_exit_failure = 2;
This doesn't scale well as the number of modules grows.
How about if we have just a single exit_failure variable, so that
programs worried about fatal-error exit status can set just that
variable. The exitfail module already provides this variable.
Here's a proposal to help standardize on 'exit_failure', by switching
xalloc and xmemcoll to use that variable. This change requires
rewriting existing applications that need to exit with status other
than 1 on failure. However, the changes are easy to write, and
there's a compile-time error if you forget to make the change, so I
don't see a major upgrade issue.
This proposal omits obstack, since it's taken from libc and I'm
trying to minimize changes to libc modules for now. But I'd like
to convert obstack at some point, as well.
2003-07-17 Paul Eggert <address@hidden>
* lib/xalloc.h (xalloc_exit_failure): Remove.
* lib/xmalloc.c (xalloc_exit_failure): Likewise.
(xalloc_die): Use exit_failure instead.
* lib/xmemcoll.h (xmemcoll_exit_failure): Remove.
* lib/xmemcoll.c (xmemcoll_exit_failure): Likewise.
(xmemcoll): Use exit_failure instead.
* lib/xmalloc.c, lib/xmemcoll.c: Include "exitfail.h".
* modules/xalloc, modules/xmemcoll: Depend on exitfail.
Index: lib/xalloc.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/xalloc.h,v
retrieving revision 1.15
diff -p -u -r1.15 xalloc.h
--- lib/xalloc.h 18 Jun 2003 05:52:19 -0000 1.15
+++ lib/xalloc.h 18 Jul 2003 04:55:18 -0000
@@ -32,11 +32,6 @@
# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
# endif
-/* Exit value when the requested amount of memory is not available.
- It is initialized to EXIT_FAILURE, but the caller may set it to
- some other value. */
-extern int xalloc_exit_failure;
-
/* If this pointer is non-zero, run the specified function upon each
allocation failure. It is initialized to zero. */
extern void (*xalloc_fail_func) (void);
@@ -47,7 +42,8 @@ extern void (*xalloc_fail_func) (void);
extern char const xalloc_msg_memory_exhausted[];
/* This function is always triggered when memory is exhausted. It is
- in charge of honoring the three previous items. This is the
+ in charge of honoring the two previous items. It exits with status
+ exit_failure (defined in exitfail.h). This is the
function to call when one wants the program to die because of a
memory allocation failure. */
extern void xalloc_die (void) ATTRIBUTE_NORETURN;
Index: lib/xmalloc.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/xmalloc.c,v
retrieving revision 1.24
diff -p -u -r1.24 xmalloc.c
--- lib/xmalloc.c 18 Jun 2003 05:52:19 -0000 1.24
+++ lib/xmalloc.c 18 Jul 2003 04:55:18 -0000
@@ -37,6 +37,7 @@ void free ();
#define N_(msgid) msgid
#include "error.h"
+#include "exitfail.h"
#include "xalloc.h"
#ifndef EXIT_FAILURE
@@ -53,10 +54,6 @@ void free ();
"you must run the autoconf test for a GNU libc compatible realloc"
#endif
-/* Exit value when the requested amount of memory is not available.
- The caller may set it to some other value. */
-int xalloc_exit_failure = EXIT_FAILURE;
-
/* If non NULL, call this function when memory is exhausted. */
void (*xalloc_fail_func) (void) = 0;
@@ -69,7 +66,7 @@ xalloc_die (void)
{
if (xalloc_fail_func)
(*xalloc_fail_func) ();
- error (xalloc_exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted));
+ error (exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted));
/* The `noreturn' cannot be given to error, since it may return if
its first argument is 0. To help compilers understand the
xalloc_die does terminate, call exit. */
Index: lib/xmemcoll.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/xmemcoll.c,v
retrieving revision 1.2
diff -p -u -r1.2 xmemcoll.c
--- lib/xmemcoll.c 5 Nov 2002 21:45:29 -0000 1.2
+++ lib/xmemcoll.c 18 Jul 2003 04:55:18 -0000
@@ -32,14 +32,11 @@ extern int errno;
#define _(msgid) gettext (msgid)
#include "error.h"
+#include "exitfail.h"
#include "memcoll.h"
#include "quotearg.h"
#include "xmemcoll.h"
-/* Exit value when xmemcoll fails.
- The caller may set it to some other value. */
-int xmemcoll_exit_failure = EXIT_FAILURE;
-
/* Compare S1 (with length S1LEN) and S2 (with length S2LEN) according
to the LC_COLLATE locale. S1 and S2 do not overlap, and are not
adjacent. Temporarily modify the bytes after S1 and S2, but
@@ -56,7 +53,7 @@ xmemcoll (char *s1, size_t s1len, char *
{
error (0, collation_errno, _("string comparison failed"));
error (0, 0, _("Set LC_ALL='C' to work around the problem."));
- error (xmemcoll_exit_failure, 0,
+ error (exit_failure, 0,
_("The strings compared were %s and %s."),
quotearg_n_style_mem (0, locale_quoting_style, s1, s1len),
quotearg_n_style_mem (1, locale_quoting_style, s2, s2len));
Index: lib/xmemcoll.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/xmemcoll.h,v
retrieving revision 1.2
diff -p -u -r1.2 xmemcoll.h
--- lib/xmemcoll.h 4 Jun 2003 19:22:29 -0000 1.2
+++ lib/xmemcoll.h 18 Jul 2003 04:55:18 -0000
@@ -1,3 +1,2 @@
#include <stddef.h>
-extern int xmemcoll_exit_failure;
int xmemcoll (char *, size_t, char *, size_t);
Index: modules/xalloc
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/xalloc,v
retrieving revision 1.3
diff -p -u -r1.3 xalloc
--- modules/xalloc 20 Jan 2003 10:02:38 -0000 1.3
+++ modules/xalloc 18 Jul 2003 04:55:19 -0000
@@ -12,6 +12,7 @@ malloc
realloc
error
gettext
+exitfail
configure.ac:
gl_XALLOC
Index: modules/xmemcoll
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/xmemcoll,v
retrieving revision 1.3
diff -p -u -r1.3 xmemcoll
--- modules/xmemcoll 20 Jan 2003 10:02:38 -0000 1.3
+++ modules/xmemcoll 18 Jul 2003 04:55:19 -0000
@@ -10,6 +10,7 @@ memcoll
gettext
error
quotearg
+exitfail
configure.ac:
- [Bug-gnulib] too many FOO_exit_failure variables,
Paul Eggert <=
- Re: [Bug-gnulib] too many FOO_exit_failure variables, Bruno Haible, 2003/07/18
- Re: [Bug-gnulib] too many FOO_exit_failure variables, Paul Eggert, 2003/07/18
- Re: [Bug-gnulib] too many FOO_exit_failure variables, Bruno Haible, 2003/07/18
- Re: [Bug-gnulib] too many FOO_exit_failure variables, Paul Eggert, 2003/07/18
- Re: [Bug-gnulib] too many FOO_exit_failure variables, Jim Meyering, 2003/07/19
- Re: [Bug-gnulib] too many FOO_exit_failure variables, Bruno Haible, 2003/07/20
- Re: [Bug-gnulib] too many FOO_exit_failure variables, Jim Meyering, 2003/07/20
Re: [Bug-gnulib] too many FOO_exit_failure variables, Paul Eggert, 2003/07/22