]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Use xalloc module from gnulib.
authorBruno Haible <bruno@clisp.org>
Sun, 4 Apr 2021 14:01:02 +0000 (16:01 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 9 Oct 2022 07:30:42 +0000 (09:30 +0200)
* gnulib-local/lib/xalloc.h: Remove file.
* gnulib-local/lib/xmalloc.c: Remove file.
* gnulib-local/lib/xstrdup.c: Remove file.
* gnulib-local/modules/xalloc: Remove file.
* gnulib-local/modules/xalloc-die: Remove file.
* gnulib-local/Makefile.am (EXTRA_DIST): Remove them.
* libtextstyle/lib/misc.c (xmalloc_exit_failure): Remove declaration.
(libtextstyle_set_failure_exit_code): Don't set xmalloc_exit_failure.

.gitignore
gnulib-local/Makefile.am
gnulib-local/lib/xalloc.h [deleted file]
gnulib-local/lib/xmalloc.c [deleted file]
gnulib-local/lib/xstrdup.c [deleted file]
gnulib-local/modules/xalloc [deleted file]
gnulib-local/modules/xalloc-die [deleted file]
libtextstyle/.gitignore
libtextstyle/lib/misc.c

index 73f6f61ba14f3a179c50f1fc3495a53071224e39..049c89be4de77f55bb52dfff9873747cfd9555cb 100644 (file)
@@ -83,6 +83,7 @@
 /gettext-tools/libgettextpo/c-strstr.c
 /gettext-tools/libgettextpo/c-strstr.h
 /gettext-tools/libgettextpo/c++defs.h
+/gettext-tools/libgettextpo/calloc.c
 /gettext-tools/libgettextpo/cloexec.c
 /gettext-tools/libgettextpo/cloexec.h
 /gettext-tools/libgettextpo/close.c
 /gettext-tools/libgettextpo/gl_xlist.h
 /gettext-tools/libgettextpo/hard-locale.c
 /gettext-tools/libgettextpo/hard-locale.h
+/gettext-tools/libgettextpo/ialloc.c
+/gettext-tools/libgettextpo/ialloc.h
 /gettext-tools/libgettextpo/iconv.c
 /gettext-tools/libgettextpo/iconv.in.h
 /gettext-tools/libgettextpo/iconv_close.c
 /gettext-tools/libgettextpo/rawmemchr.c
 /gettext-tools/libgettextpo/rawmemchr.valgrind
 /gettext-tools/libgettextpo/realloc.c
+/gettext-tools/libgettextpo/reallocarray.c
 /gettext-tools/libgettextpo/relocatable.c
 /gettext-tools/libgettextpo/relocatable.h
 /gettext-tools/libgettextpo/relocatable.valgrind
 /gettext-tools/libgettextpo/windows-rwlock.h
 /gettext-tools/libgettextpo/windows-tls.c
 /gettext-tools/libgettextpo/windows-tls.h
+/gettext-tools/libgettextpo/xalloc-die.c
 /gettext-tools/libgettextpo/xalloc-oversized.h
 /gettext-tools/libgettextpo/xalloc.h
 /gettext-tools/libgettextpo/xasprintf.c
index 298c4f6045e68584a3c559afff11878eff2f0e62..bcb23b098df0d2e5cf11a578eee06510dd9af6b6 100644 (file)
@@ -145,13 +145,10 @@ lib/obstack.h.diff \
 lib/progname.h.diff \
 lib/regex_internal.h.diff \
 lib/unistd.in.h.diff \
-lib/xalloc.h \
 lib/xerror.c \
 lib/xerror.h \
 lib/xgetcwd.c \
 lib/xgetcwd.h \
-lib/xmalloc.c \
-lib/xstrdup.c \
 m4/backupfile.m4 \
 m4/java.m4 \
 m4/libxml.m4 \
@@ -165,8 +162,6 @@ modules/libtextstyle-dummy \
 modules/libxml \
 modules/markup \
 modules/mem-hash-map \
-modules/xalloc \
-modules/xalloc-die \
 modules/xerror \
 modules/xgetcwd
 
diff --git a/gnulib-local/lib/xalloc.h b/gnulib-local/lib/xalloc.h
deleted file mode 100644 (file)
index 460d06c..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-/* malloc with out of memory checking.
-   Copyright (C) 2001-2004, 2006, 2019-2020 Free Software Foundation, Inc.
-   Written by Bruno Haible <haible@clisp.cons.org>, 2001.
-
-   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
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
-
-#ifndef _XALLOC_H
-#define _XALLOC_H
-
-#include <stddef.h>
-
-#include "noreturn.h"
-#include "xalloc-oversized.h"
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* Defined in xmalloc.c.  */
-
-/* Allocate SIZE bytes of memory dynamically, with error checking.  */
-extern void *xmalloc (size_t size);
-
-/* Allocate memory for NMEMB elements of SIZE bytes, with error checking.
-   SIZE must be > 0.  */
-extern void *xnmalloc (size_t nmemb, size_t size);
-
-/* Allocate SIZE bytes of memory dynamically, with error checking,
-   and zero it.  */
-extern void *xzalloc (size_t size);
-
-/* Allocate memory for NMEMB elements of SIZE bytes, with error checking,
-   and zero it.  */
-extern void *xcalloc (size_t nmemb, size_t size);
-
-/* Change the size of an allocated block of memory PTR to SIZE bytes,
-   with error checking.  If PTR is NULL, run xmalloc.  */
-extern void *xrealloc (void *ptr, size_t size);
-#ifdef __cplusplus
-}
-template <typename T>
-  inline T * xrealloc (T * ptr, size_t size)
-  {
-    return (T *) xrealloc ((void *) ptr, size);
-  }
-extern "C" {
-#endif
-
-/* If P is null, allocate a block of at least *PN bytes; otherwise,
-   reallocate P so that it contains more than *PN bytes.  *PN must be
-   nonzero unless P is null.  Set *PN to the new block's size, and
-   return the pointer to the new block.  *PN is never set to zero, and
-   the returned pointer is never null.  */
-extern void *x2realloc (void *ptr, size_t *pn);
-#ifdef __cplusplus
-}
-template <typename T>
-  inline T * x2realloc (T * ptr, size_t *pn)
-  {
-    return (T *) x2realloc ((void *) ptr, pn);
-  }
-extern "C" {
-#endif
-
-/* This function is always triggered when memory is exhausted.  It is
-   in charge of honoring the three previous items.  This is the
-   function to call when one wants the program to die because of a
-   memory allocation failure.  */
-_GL_NORETURN_FUNC extern void xalloc_die (void);
-
-/* In the following macros, T must be an elementary or structure/union or
-   typedef'ed type, or a pointer to such a type.  To apply one of the
-   following macros to a function pointer or array type, you need to typedef
-   it first and use the typedef name.  */
-
-/* Allocate an object of type T dynamically, with error checking.  */
-/* extern T *XMALLOC (typename T); */
-#define XMALLOC(T) \
-  ((T *) xmalloc (sizeof (T)))
-
-/* Allocate memory for NMEMB elements of type T, with error checking.  */
-/* extern T *XNMALLOC (size_t nmemb, typename T); */
-#if HAVE_INLINE
-/* xnmalloc performs a division and multiplication by sizeof (T).  Arrange to
-   perform the division at compile-time and the multiplication with a factor
-   known at compile-time.  */
-# define XNMALLOC(N,T) \
-   ((T *) (sizeof (T) == 1 \
-           ? xmalloc (N) \
-           : xnboundedmalloc(N, (size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / sizeof (T), sizeof (T))))
-static inline void *
-xnboundedmalloc (size_t n, size_t bound, size_t s)
-{
-  if (n > bound)
-    xalloc_die ();
-  return xmalloc (n * s);
-}
-#else
-# define XNMALLOC(N,T) \
-   ((T *) (sizeof (T) == 1 ? xmalloc (N) : xnmalloc (N, sizeof (T))))
-#endif
-
-/* Allocate an object of type T dynamically, with error checking,
-   and zero it.  */
-/* extern T *XZALLOC (typename T); */
-#define XZALLOC(T) \
-  ((T *) xzalloc (sizeof (T)))
-
-/* Allocate memory for NMEMB elements of type T, with error checking,
-   and zero it.  */
-/* extern T *XCALLOC (size_t nmemb, typename T); */
-#define XCALLOC(N,T) \
-  ((T *) xcalloc (N, sizeof (T)))
-
-/* Return a pointer to a new buffer of N bytes.  This is like xmalloc,
-   except it returns char *.  */
-#define xcharalloc(N) \
-  XNMALLOC (N, char)
-
-
-/* Defined in xstrdup.c.  */
-
-/* Return a newly allocated copy of the N bytes of memory starting at P.  */
-extern void *xmemdup (const void *p, size_t n);
-#ifdef __cplusplus
-}
-template <typename T>
-  inline T * xmemdup (const T * p, size_t n)
-  {
-    return (T *) xmemdup ((const void *) p, n);
-  }
-extern "C" {
-#endif
-
-/* Return a newly allocated copy of STRING.  */
-extern char *xstrdup (const char *string);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* _XALLOC_H */
diff --git a/gnulib-local/lib/xmalloc.c b/gnulib-local/lib/xmalloc.c
deleted file mode 100644 (file)
index a1456c5..0000000
+++ /dev/null
@@ -1,232 +0,0 @@
-/* xmalloc.c -- malloc with out of memory checking
-   Copyright (C) 1990-1996, 2000-2003, 2005-2007, 2012 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
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
-
-#include <config.h>
-
-/* Specification.  */
-#include "xalloc.h"
-
-#include <stdlib.h>
-
-#include "error.h"
-#include "gettext.h"
-
-#define _(str) gettext (str)
-
-
-/* Exit value when the requested amount of memory is not available.
-   The caller may set it to some other value.  */
-int xmalloc_exit_failure = EXIT_FAILURE;
-
-void
-xalloc_die ()
-{
-  error (xmalloc_exit_failure, 0, _("memory exhausted"));
-  /* _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. */
-  exit (EXIT_FAILURE);
-}
-
-static void *
-fixup_null_alloc (size_t n)
-{
-  void *p;
-
-  p = NULL;
-  if (n == 0)
-    p = malloc ((size_t) 1);
-  if (p == NULL)
-    xalloc_die ();
-  return p;
-}
-
-/* Allocate N bytes of memory dynamically, with error checking.  */
-
-void *
-xmalloc (size_t n)
-{
-  void *p;
-
-  p = malloc (n);
-  if (p == NULL)
-    p = fixup_null_alloc (n);
-  return p;
-}
-
-/* Allocate memory for NMEMB elements of SIZE bytes, with error checking.
-   SIZE must be > 0.  */
-
-void *
-xnmalloc (size_t nmemb, size_t size)
-{
-  size_t n;
-  void *p;
-
-  if (xalloc_oversized (nmemb, size))
-    xalloc_die ();
-  n = nmemb * size;
-  p = malloc (n);
-  if (p == NULL)
-    p = fixup_null_alloc (n);
-  return p;
-}
-
-/* Allocate SIZE bytes of memory dynamically, with error checking,
-   and zero it.  */
-
-void *
-xzalloc (size_t size)
-{
-  void *p;
-
-  p = xmalloc (size);
-  memset (p, 0, size);
-  return p;
-}
-
-/* Allocate memory for N elements of S bytes, with error checking,
-   and zero it.  */
-
-void *
-xcalloc (size_t n, size_t s)
-{
-  void *p;
-
-  p = calloc (n, s);
-  if (p == NULL)
-    p = fixup_null_alloc (n);
-  return p;
-}
-
-/* Change the size of an allocated block of memory P to N bytes,
-   with error checking.
-   If P is NULL, run xmalloc.  */
-
-void *
-xrealloc (void *p, size_t n)
-{
-  if (p == NULL)
-    return xmalloc (n);
-  p = realloc (p, n);
-  if (p == NULL)
-    p = fixup_null_alloc (n);
-  return p;
-}
-
-/* If P is null, allocate a block of at least *PN such objects;
-   otherwise, reallocate P so that it contains more than *PN objects
-   each of S bytes.  S must be nonzero.  Set *PN to the new number of
-   objects, and return the pointer to the new block.  *PN is never set
-   to zero, and the returned pointer is never null.
-
-   Repeated reallocations are guaranteed to make progress, either by
-   allocating an initial block with a nonzero size, or by allocating a
-   larger block.
-
-   In the following implementation, nonzero sizes are increased by a
-   factor of approximately 1.5 so that repeated reallocations have
-   O(N) overall cost rather than O(N**2) cost, but the
-   specification for this function does not guarantee that rate.
-
-   Here is an example of use:
-
-     int *p = NULL;
-     size_t used = 0;
-     size_t allocated = 0;
-
-     void
-     append_int (int value)
-       {
-         if (used == allocated)
-           p = x2nrealloc (p, &allocated, sizeof *p);
-         p[used++] = value;
-       }
-
-   This causes x2nrealloc to allocate a block of some nonzero size the
-   first time it is called.
-
-   To have finer-grained control over the initial size, set *PN to a
-   nonzero value before calling this function with P == NULL.  For
-   example:
-
-     int *p = NULL;
-     size_t used = 0;
-     size_t allocated = 0;
-     size_t allocated1 = 1000;
-
-     void
-     append_int (int value)
-       {
-         if (used == allocated)
-           {
-             p = x2nrealloc (p, &allocated1, sizeof *p);
-             allocated = allocated1;
-           }
-         p[used++] = value;
-       }
-
-   */
-
-static inline void *
-x2nrealloc (void *p, size_t *pn, size_t s)
-{
-  size_t n = *pn;
-
-  if (! p)
-    {
-      if (! n)
-        {
-          /* The approximate size to use for initial small allocation
-             requests, when the invoking code specifies an old size of
-             zero.  This is the largest "small" request for the GNU C
-             library malloc.  */
-          enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 };
-
-          n = DEFAULT_MXFAST / s;
-          n += !n;
-        }
-      if (xalloc_oversized (n, s))
-        xalloc_die ();
-    }
-  else
-    {
-      /* Set N = floor (1.5 * N) + 1 so that progress is made even if N == 0.
-         Check for overflow, so that N * S stays in both ptrdiff_t and
-         size_t range.  The check may be slightly conservative, but an
-         exact check isn't worth the trouble.  */
-      if ((PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : SIZE_MAX) / 3 * 2 / s
-          <= n)
-        xalloc_die ();
-      n += n / 2 + 1;
-    }
-
-  *pn = n;
-  return xrealloc (p, n * s);
-}
-
-/* If P is null, allocate a block of at least *PN bytes; otherwise,
-   reallocate P so that it contains more than *PN bytes.  *PN must be
-   nonzero unless P is null.  Set *PN to the new block's size, and
-   return the pointer to the new block.  *PN is never set to zero, and
-   the returned pointer is never null.  */
-
-void *
-x2realloc (void *p, size_t *pn)
-{
-  return x2nrealloc (p, pn, 1);
-}
diff --git a/gnulib-local/lib/xstrdup.c b/gnulib-local/lib/xstrdup.c
deleted file mode 100644 (file)
index 1b369e9..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/* xstrdup.c -- copy a string with out of memory checking
-   Copyright (C) 1990, 1996, 2000-2003, 2005-2006 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
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
-
-#include <config.h>
-
-/* Specification.  */
-#include "xalloc.h"
-
-#include <string.h>
-
-/* Return a newly allocated copy of the N bytes of memory starting at P.  */
-
-void *
-xmemdup (const void *p, size_t n)
-{
-  void *q = xmalloc (n);
-  memcpy (q, p, n);
-  return q;
-}
-
-/* Return a newly allocated copy of STRING.  */
-
-char *
-xstrdup (const char *string)
-{
-  return strcpy (XNMALLOC (strlen (string) + 1, char), string);
-}
diff --git a/gnulib-local/modules/xalloc b/gnulib-local/modules/xalloc
deleted file mode 100644 (file)
index deec4d4..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-Description:
-Memory allocation with out-of-memory checking.
-
-Files:
-lib/xalloc.h
-lib/xmalloc.c
-lib/xstrdup.c
-
-Depends-on:
-error
-gettext-h
-noreturn
-stdlib
-xalloc-oversized
-
-configure.ac:
-AC_REQUIRE([AC_C_INLINE])
-
-Makefile.am:
-lib_SOURCES += xalloc.h xmalloc.c xstrdup.c
-
-Include:
-"xalloc.h"
-
-License:
-GPL
-
-Maintainer:
-all
diff --git a/gnulib-local/modules/xalloc-die b/gnulib-local/modules/xalloc-die
deleted file mode 100644 (file)
index 4fe557c..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-Description:
-Report a memory allocation failure and exit.
-
-Files:
-
-Depends-on:
-xalloc
-
-configure.ac:
-
-Makefile.am:
-
-Include:
-"xalloc.h"
-
-License:
-GPL
-
-Maintainer:
-Bruno Haible
-
index fd47eea4bd1d90c47ad2a416b28f104b7a2c0014..f332b009aff26b074460ee968f35190d50b34429 100644 (file)
@@ -33,6 +33,7 @@
 /lib/c-strcase.h
 /lib/c-strcasecmp.c
 /lib/c-strncasecmp.c
+/lib/calloc.c
 /lib/cloexec.c
 /lib/cloexec.h
 /lib/close.c
@@ -93,6 +94,8 @@
 /lib/html-ostream.oo.h
 /lib/html-styled-ostream.oo.c
 /lib/html-styled-ostream.oo.h
+/lib/ialloc.c
+/lib/ialloc.h
 /lib/iconv-ostream.oo.c
 /lib/iconv-ostream.oo.h
 /lib/idx.h
 /lib/printf-parse.h
 /lib/raise.c
 /lib/read.c
+/lib/realloc.c
+/lib/reallocarray.c
 /lib/safe-read.c
 /lib/safe-read.h
 /lib/safe-write.c
 /lib/windows-rwlock.c
 /lib/windows-rwlock.h
 /lib/write.c
+/lib/xalloc-die.c
 /lib/xalloc-oversized.h
 /lib/xalloc.h
 /lib/xasprintf.c
index 866fd212f619603c565d1cab5017e8ff31a0cc76..6b1f0eb389830bfdbf6e7b8bfd92cb7898584523 100644 (file)
@@ -1,5 +1,5 @@
 /* Miscellaneous public API.
-   Copyright (C) 2019 Free Software Foundation, Inc.
+   Copyright (C) 2019, 2021 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2019.
 
    This program is free software: you can redistribute it and/or modify
@@ -25,8 +25,6 @@
 #include "fd-ostream.h"
 #include "exitfail.h"
 
-extern int xmalloc_exit_failure;
-
 
 styled_ostream_t
 styled_ostream_create (int fd, const char *filename, ttyctl_t tty_control,
@@ -47,5 +45,4 @@ void
 libtextstyle_set_failure_exit_code (int exit_code)
 {
   exit_failure = exit_code;
-  xmalloc_exit_failure = exit_code;
 }