]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
xasprintf.c: New file.
authorUros Bizjak <ubizjak@gmail.com>
Wed, 24 Dec 2014 16:22:51 +0000 (17:22 +0100)
committerUros Bizjak <uros@gcc.gnu.org>
Wed, 24 Dec 2014 16:22:51 +0000 (17:22 +0100)
libiberty/ChangeLog:

* xasprintf.c: New file.
* Makefile.in (CFILES): Add xasprintf.c.
(REQUIRED_OFILES): Add xasprintf.$(objext).
(xasprintf.$(objext)): New target.
* functions.texi: Regenerate.

include/ChangeLog:

* libiberty.h (xasprintf): Declare.

gcc/ChangeLog:

* gengtype.h (xasprintf): Remove declaration.
* gengtype.c (xasprintf): Remove.

Co-Authored-By: Ben Elliston <bje@au.ibm.com>
Co-Authored-By: Manuel López-Ibáñez <manu@gcc.gnu.org>
From-SVN: r219060

gcc/ChangeLog
gcc/gengtype.c
gcc/gengtype.h
include/ChangeLog
include/libiberty.h
libiberty/ChangeLog
libiberty/Makefile.in
libiberty/functions.texi
libiberty/xasprintf.c [new file with mode: 0644]

index 259e2af9f989768b6dc9f1d6c1ae57055ba5b38c..d2870d6b21dc0e6f985cd9de4ac25d2dc543b6a1 100644 (file)
@@ -1,3 +1,8 @@
+2014-12-24  Uros Bizjak  <ubizjak@gmail.com>
+
+       * gengtype.h (xasprintf): Remove declaration.
+       * gengtype.c (xasprintf): Remove.
+
 2014-12-24  Nick Clifton  <nickc@redhat.com>
 
        PR target/64160
index 3f9ad0b3463934f81b594a65197eaa8a5f1ad1db..e87bea0ab4665e63116f9e34a211335d5d14829a 100644 (file)
@@ -119,23 +119,6 @@ error_at_line (const struct fileloc *pos, const char *msg, ...)
 
   va_end (ap);
 }
-
-/* asprintf, but produces fatal message on out-of-memory.  */
-char *
-xasprintf (const char *format, ...)
-{
-  int n;
-  char *result;
-  va_list ap;
-
-  va_start (ap, format);
-  n = vasprintf (&result, format, ap);
-  if (result == NULL || n < 0)
-    fatal ("out of memory");
-  va_end (ap);
-
-  return result;
-}
 \f
 /* Locate the ultimate base class of struct S.  */
 
index e4596039a01ee209e652afa01267e8d28cc17319..3da57e844405e8f4516557a8e12bd5d7121d8b23 100644 (file)
@@ -418,9 +418,6 @@ void write_state (const char* path);
 extern void error_at_line
 (const struct fileloc *pos, const char *msg, ...) ATTRIBUTE_PRINTF_2;
 
-/* Like asprintf, but calls fatal() on out of memory.  */
-extern char *xasprintf (const char *, ...) ATTRIBUTE_PRINTF_1;
-
 /* Constructor routines for types.  */
 extern void do_typedef (const char *s, type_p t, struct fileloc *pos);
 extern void do_scalar_typedef (const char *s, struct fileloc *pos);
index 1d5f7013321a9d0257d2a2332aae1c5d100ab9d3..dbf2554238d7278a3556c697c75e8ffa3f338f54 100644 (file)
@@ -1,3 +1,9 @@
+2014-12-24  Uros Bizjak  <ubizjak@gmail.com>
+           Ben Elliston  <bje@au.ibm.com>
+           Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       * libiberty.h (xasprintf): Declare.
+
 2014-12-11  Uros Bizjak  <ubizjak@gmail.com>
             Ben Elliston  <bje@au.ibm.com>
             Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
index b9694f0f093843df12dca29f8e98b7d4bfb6bf41..aa0d92c8c20bba3c2e76fc12dabca3ca5bba265a 100644 (file)
@@ -629,6 +629,11 @@ extern int pwait (int, int *, int);
 extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2;
 #endif
 
+/* Like asprintf but allocates memory without fail. This works like
+   xmalloc.  */
+
+extern char *xasprintf (const char *, ...) ATTRIBUTE_MALLOC ATTRIBUTE_PRINTF_1;
+
 #if !HAVE_DECL_VASPRINTF
 /* Like vsprintf but provides a pointer to malloc'd storage, which
    must be freed by the caller.  */
index e4a8ce81b2584e7215486eef519f13e7fde15572..ac2387552edfc897fceec66c1cbf576ea63bf834 100644 (file)
@@ -1,3 +1,13 @@
+2014-12-24  Uros Bizjak  <ubizjak@gmail.com>
+           Ben Elliston  <bje@au.ibm.com>
+           Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       * xasprintf.c: New file.
+       * Makefile.in (CFILES): Add xasprintf.c.
+       (REQUIRED_OFILES): Add xasprintf.$(objext).
+       (xasprintf.$(objext)): New target.
+       * functions.texi: Regenerate.
+
 2014-12-11  Uros Bizjak  <ubizjak@gmail.com>
             Ben Elliston  <bje@au.ibm.com>
             Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
index e7e17af226cd77d7a4ff0d0fe36ae7bacb4bd2ee..f06cc69a973bcf39235febce84a2d7fad7130eed 100644 (file)
@@ -158,8 +158,8 @@ CFILES = alloca.c argv.c asprintf.c atexit.c                                \
        vasprintf.c vfork.c vfprintf.c vprintf.c vprintf-support.c      \
         vsnprintf.c vsprintf.c                                         \
        waitpid.c                                                       \
-       xatexit.c xexit.c xmalloc.c xmemdup.c xstrdup.c xstrerror.c     \
-        xstrndup.c xvasprintf.c
+       xasprintf.c xatexit.c xexit.c xmalloc.c xmemdup.c xstrdup.c     \
+        xstrerror.c xstrndup.c xvasprintf.c
 
 # These are always included in the library.  The first four are listed
 # first and by compile time to optimize parallel builds.
@@ -190,9 +190,10 @@ REQUIRED_OFILES =                                                  \
        ./splay-tree.$(objext) ./stack-limit.$(objext)                  \
        ./strerror.$(objext) ./strsignal.$(objext)                      \
        ./timeval-utils.$(objext) ./unlink-if-ordinary.$(objext)        \
-       ./xatexit.$(objext) ./xexit.$(objext) ./xmalloc.$(objext)       \
-       ./xmemdup.$(objext) ./xstrdup.$(objext) ./xstrerror.$(objext)   \
-       ./xstrndup.$(objext) ./xvasprintf.$(objext)
+       ./xasprintf.$(objext) ./xatexit.$(objext) ./xexit.$(objext)     \
+       ./xmalloc.$(objext) ./xmemdup.$(objext) ./xstrdup.$(objext)     \
+       ./xstrerror.$(objext) ./xstrndup.$(objext)                      \
+       ./xvasprintf.$(objext)
 
 # These are all the objects that configure may add to the library via
 # $funcs or EXTRA_OFILES.  This list exists here only for "make
@@ -1618,6 +1619,16 @@ $(CONFIGURED_OFILES): stamp-picdir stamp-noasandir
        else true; fi
        $(COMPILE.c) $(srcdir)/waitpid.c $(OUTPUT_OPTION)
 
+./xasprintf.$(objext): $(srcdir)/xasprintf.c config.h $(INCDIR)/ansidecl.h \
+       $(INCDIR)/libiberty.h
+       if [ x"$(PICFLAG)" != x ]; then \
+         $(COMPILE.c) $(PICFLAG) $(srcdir)/xasprintf.c -o pic/$@; \
+       else true; fi
+       if [ x"$(NOASANFLAG)" != x ]; then \
+         $(COMPILE.c) $(PICFLAG) $(NOASANFLAG) $(srcdir)/xasprintf.c -o noasan/$@; \
+       else true; fi
+       $(COMPILE.c) $(srcdir)/xasprintf.c $(OUTPUT_OPTION)
+
 ./xatexit.$(objext): $(srcdir)/xatexit.c config.h $(INCDIR)/ansidecl.h \
        $(INCDIR)/libiberty.h
        if [ x"$(PICFLAG)" != x ]; then \
index 39064b4166ce862a3601bbf970603ba393230ad3..b5f4e809d063bca7e5c22a997b6001796ea82b75 100644 (file)
@@ -1923,6 +1923,15 @@ if an error occurred while writing to FILE.
 
 @end deftypefn
 
+@c xasprintf.c:31
+@deftypefn Replacement char* xasprintf (const char *@var{format}, ...)
+
+Print to allocated string without fail.  If @code{xasprintf} fails,
+this will print a message to @code{stderr} (using the name set by
+@code{xmalloc_set_program_name}, if any) and then call @code{xexit}.
+
+@end deftypefn
+
 @c xatexit.c:11
 @deftypefun int xatexit (void (*@var{fn}) (void))
 
diff --git a/libiberty/xasprintf.c b/libiberty/xasprintf.c
new file mode 100644 (file)
index 0000000..4f72bb2
--- /dev/null
@@ -0,0 +1,50 @@
+/* Implement the xasprintf function.
+   Copyright (C) 2014 Free Software Foundation, Inc.
+   Contributed by Manuel Lopez-Ibanez.
+
+This file is part of the libiberty library.
+Libiberty is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+Libiberty 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with libiberty; see the file COPYING.LIB.  If not, write
+to the Free Software Foundation, Inc., 51 Franklin Street - Fifth
+Floor, Boston, MA 02110-1301, USA.  */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "ansidecl.h"
+#include "libiberty.h"
+
+#include <stdarg.h>
+
+/*
+
+@deftypefn Replacement char* xasprintf (const char *@var{format}, ...)
+
+Print to allocated string without fail.  If @code{xasprintf} fails,
+this will print a message to @code{stderr} (using the name set by
+@code{xmalloc_set_program_name}, if any) and then call @code{xexit}.
+
+@end deftypefn
+
+*/
+
+char *
+xasprintf (const char *fmt, ...)
+{
+  char *buf;
+  va_list ap;
+  va_start (ap, fmt);
+  buf = xvasprintf (fmt, ap);
+  va_end (ap);
+  return buf;
+}