From: Paul Eggert Date: Tue, 22 Jul 2003 22:10:55 +0000 (+0000) Subject: Sync with coreutils xalloc.h, xmalloc.c, xmemcoll.h, xmemcoll.c. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c7070eaa3051ed57fd67919ba59ca1892e21ccc;p=pspp Sync with coreutils xalloc.h, xmalloc.c, xmemcoll.h, xmemcoll.c. --- diff --git a/ChangeLog b/ChangeLog index da1db75654..594193f8e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-07-22 Paul Eggert + + * modules/xalloc (Depends-on): Add exitfail. + * modules/xmemcoll: Likewise. + 2003-07-20 Jim Meyering * modules/closeout (Depends-on): Add exitfail. diff --git a/lib/ChangeLog b/lib/ChangeLog index 5da039c136..758b7af155 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,22 @@ +2003-07-22 Paul Eggert + + * xalloc.h (XCALLOC, XREALLOC, CCLONE): Fix under- and + over-parenthesization in macros. + + Sync with coreutils. + + * xalloc.h (XMALLOC, XCALLOC, XREALLOC): Remove casts not + required by C99. + + Use `exit_failure' for xalloc and xmemcoll instead of their own + private exit-failure variables. + * xalloc.h (xalloc_exit_failure): Remove. + * xmalloc.c: Likewise. Include exitfail.h. + (xalloc_die): Use exit_failure instead of xalloc_exit_failure. + * xmemcoll.h (xmemcoll_exit_failure): Remove. + * xmemcoll.c: Likewise. Include exitfail.h. + (xmemcoll): Use exit_failure instead of xalloc_exit_failure. + 2003-07-18 Paul Eggert * closeout.h (close_stdout_set_status, close_stdout_status): Remove. diff --git a/lib/xalloc.h b/lib/xalloc.h index adebccd743..c6ca1174b2 100644 --- a/lib/xalloc.h +++ b/lib/xalloc.h @@ -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; @@ -57,10 +53,9 @@ void *xcalloc (size_t n, size_t s); void *xrealloc (void *p, size_t n); char *xstrdup (const char *str); -# define XMALLOC(Type, N_items) ((Type *) xmalloc (sizeof (Type) * (N_items))) -# define XCALLOC(Type, N_items) ((Type *) xcalloc (sizeof (Type), (N_items))) -# define XREALLOC(Ptr, Type, N_items) \ - ((Type *) xrealloc ((void *) (Ptr), sizeof (Type) * (N_items))) +# define XMALLOC(Type, N_items) xmalloc (sizeof (Type) * (N_items)) +# define XCALLOC(Type, N_items) xcalloc (sizeof (Type), N_items) +# define XREALLOC(Ptr, Type, N_items) xrealloc (Ptr, sizeof (Type) * (N_items)) /* Declare and alloc memory for VAR of type TYPE. */ # define NEW(Type, Var) Type *(Var) = XMALLOC (Type, 1) @@ -74,7 +69,7 @@ char *xstrdup (const char *str); /* Return a pointer to a malloc'ed copy of the array SRC of NUM elements. */ # define CCLONE(Src, Num) \ - (memcpy (xmalloc (sizeof (*Src) * (Num)), (Src), sizeof (*Src) * (Num))) + (memcpy (xmalloc (sizeof *(Src) * (Num)), Src, sizeof *(Src) * (Num))) /* Return a malloc'ed copy of SRC. */ # define CLONE(Src) CCLONE (Src, 1) diff --git a/lib/xmalloc.c b/lib/xmalloc.c index a1bcbdf91d..ead50393d3 100644 --- a/lib/xmalloc.c +++ b/lib/xmalloc.c @@ -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. */ diff --git a/lib/xmemcoll.c b/lib/xmemcoll.c index 7fe06b8cb3..0e30aef150 100644 --- a/lib/xmemcoll.c +++ b/lib/xmemcoll.c @@ -1,5 +1,5 @@ /* Locale-specific memory comparison. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -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 *s2, size_t s2len) { 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)); diff --git a/lib/xmemcoll.h b/lib/xmemcoll.h index 1b1a193ee6..2f422e8c1c 100644 --- a/lib/xmemcoll.h +++ b/lib/xmemcoll.h @@ -1,3 +1,2 @@ #include -extern int xmemcoll_exit_failure; int xmemcoll (char *, size_t, char *, size_t); diff --git a/modules/xalloc b/modules/xalloc index 0a45b0acbd..6c133a3c27 100644 --- a/modules/xalloc +++ b/modules/xalloc @@ -12,6 +12,7 @@ malloc realloc error gettext +exitfail configure.ac: gl_XALLOC diff --git a/modules/xmemcoll b/modules/xmemcoll index 4d3f2edd6b..7589b5239f 100644 --- a/modules/xmemcoll +++ b/modules/xmemcoll @@ -10,6 +10,7 @@ memcoll gettext error quotearg +exitfail configure.ac: