bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: *printf declarations in stdio.h?


From: Simon Josefsson
Subject: Re: *printf declarations in stdio.h?
Date: Thu, 22 Mar 2007 14:26:26 +0100
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.95 (gnu/linux)

Bruno Haible <address@hidden> writes:

> Better but still incomplete:
>
>> +# if @REPLACE_VASPRINTF@ || address@hidden@
>> +  /* Write formatted output to a string dynamically allocated with malloc().
>> +     If the memory allocation succeeds, store the address of the string in
>> +     *RESULT and return the number of resulting bytes, excluding the 
>> trailing
>> +     NUL.  Upon memory allocation error, or some other error, return -1.  */
>> +  extern int asprintf (char **result, const char *format, ...)
>> +    __attribute__ ((__format__ (__printf__, 2, 3)));
>> +  extern int vasprintf (char **result, const char *format, va_list args)
>> +    __attribute__ ((__format__ (__printf__, 2, 0)));
>> +# endif

I thought I had answered this, but can't find anything in the archives...

> Why here you use @HAVE_DECL_VASPRINTF@ where the original code used
> HAVE_VASPRINTF? Did you encounter a platform which has the same vasprintf()
> but doesn't declare it? vasprintf is not a standardized, therefore I can well
> imagine a platform which has a vasprintf that returns a 'char *' instead
> of 'int' - then testing HAVE_VASPRINTF is safer.

Nope, just a mistake.  I copy'n'paste'd from the other existing code
in stdio_.h instead of copying the code from vasprintf.h.

> And I don't see any m4/* code that would set the shell variable HAVE_VASPRINTF
> or HAVE_DECL_VASPRINTF to 0. It is only ever set to 1, which is not the
> intent.

I removed the HAVE*_VASPRINTF code in m4/stdio.m4 and modules/stdio
though, since it wasn't used.  There is REPLACE_VASPRINTF, which is
similar to the other uses in stdio_.h.

Updated patch below.

/Simon

Index: lib/asprintf.c
===================================================================
RCS file: /sources/gnulib/gnulib/lib/asprintf.c,v
retrieving revision 1.4
diff -u -p -r1.4 asprintf.c
--- lib/asprintf.c      14 Sep 2006 14:18:36 -0000      1.4
+++ lib/asprintf.c      22 Mar 2007 13:25:43 -0000
@@ -1,5 +1,5 @@
 /* Formatted output to strings.
-   Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2002, 2006, 2007 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
@@ -18,7 +18,7 @@
 #include <config.h>
 
 /* Specification.  */
-#include "vasprintf.h"
+#include <stdio.h>
 
 #include <stdarg.h>
 
Index: lib/stdio_.h
===================================================================
RCS file: /sources/gnulib/gnulib/lib/stdio_.h,v
retrieving revision 1.13
diff -u -p -r1.13 stdio_.h
--- lib/stdio_.h        10 Mar 2007 11:24:15 -0000      1.13
+++ lib/stdio_.h        22 Mar 2007 13:25:43 -0000
@@ -183,6 +183,20 @@ extern int vsprintf (char *str, const ch
      vsprintf (b, f, a))
 #endif
 
+#if @GNULIB_VASPRINTF@
+# if @REPLACE_VASPRINTF@
+#  define asprintf rpl_asprintf
+#  define vasprintf rpl_vasprintf
+  /* Write formatted output to a string dynamically allocated with malloc().
+     If the memory allocation succeeds, store the address of the string in
+     *RESULT and return the number of resulting bytes, excluding the trailing
+     NUL.  Upon memory allocation error, or some other error, return -1.  */
+  extern int asprintf (char **result, const char *format, ...)
+    __attribute__ ((__format__ (__printf__, 2, 3)));
+  extern int vasprintf (char **result, const char *format, va_list args)
+    __attribute__ ((__format__ (__printf__, 2, 0)));
+# endif
+#endif
 
 #ifdef __cplusplus
 }
Index: lib/vasprintf.c
===================================================================
RCS file: /sources/gnulib/gnulib/lib/vasprintf.c,v
retrieving revision 1.8
diff -u -p -r1.8 vasprintf.c
--- lib/vasprintf.c     14 Sep 2006 14:18:36 -0000      1.8
+++ lib/vasprintf.c     22 Mar 2007 13:25:43 -0000
@@ -1,5 +1,5 @@
 /* Formatted output to strings.
-   Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2002, 2006, 2007 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
@@ -18,7 +18,7 @@
 #include <config.h>
 
 /* Specification.  */
-#include "vasprintf.h"
+#include <stdio.h>
 
 #include <errno.h>
 #include <limits.h>
Index: lib/xvasprintf.c
===================================================================
RCS file: /sources/gnulib/gnulib/lib/xvasprintf.c,v
retrieving revision 1.6
diff -u -p -r1.6 xvasprintf.c
--- lib/xvasprintf.c    6 Nov 2006 13:03:10 -0000       1.6
+++ lib/xvasprintf.c    22 Mar 2007 13:25:43 -0000
@@ -1,5 +1,5 @@
 /* vasprintf and asprintf with out-of-memory checking.
-   Copyright (C) 1999, 2002-2004, 2006 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2002-2004, 2006, 2007 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
@@ -23,8 +23,8 @@
 #include <errno.h>
 #include <limits.h>
 #include <string.h>
+#include <stdio.h>
 
-#include "vasprintf.h"
 #include "xalloc.h"
 
 /* Checked size_t computations.  */
Index: m4/stdio_h.m4
===================================================================
RCS file: /sources/gnulib/gnulib/m4/stdio_h.m4,v
retrieving revision 1.9
diff -u -p -r1.9 stdio_h.m4
--- m4/stdio_h.m4       10 Mar 2007 01:20:26 -0000      1.9
+++ m4/stdio_h.m4       22 Mar 2007 13:25:43 -0000
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 2
+# stdio_h.m4 serial 3
 dnl Copyright (C) 2007 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -29,6 +29,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   GNULIB_VPRINTF_POSIX=0;  AC_SUBST([GNULIB_VPRINTF_POSIX])
   GNULIB_VSNPRINTF=0;      AC_SUBST([GNULIB_VSNPRINTF])
   GNULIB_VSPRINTF_POSIX=0; AC_SUBST([GNULIB_VSPRINTF_POSIX])
+  GNULIB_VASPRINTF=0;      AC_SUBST([GNULIB_VASPRINTF])
   dnl Assume proper GNU behavior unless another module says otherwise.
   REPLACE_FPRINTF=0;       AC_SUBST([REPLACE_FPRINTF])
   REPLACE_VFPRINTF=0;      AC_SUBST([REPLACE_VFPRINTF])
@@ -40,4 +41,5 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   HAVE_DECL_VSNPRINTF=1;   AC_SUBST([HAVE_DECL_VSNPRINTF])
   REPLACE_SPRINTF=0;       AC_SUBST([REPLACE_SPRINTF])
   REPLACE_VSPRINTF=0;      AC_SUBST([REPLACE_VSPRINTF])
+  REPLACE_VASPRINTF=0;     AC_SUBST([REPLACE_VASPRINTF])
 ])
Index: modules/stdio
===================================================================
RCS file: /sources/gnulib/gnulib/modules/stdio,v
retrieving revision 1.9
diff -u -p -r1.9 stdio
--- modules/stdio       10 Mar 2007 01:20:26 -0000      1.9
+++ modules/stdio       22 Mar 2007 13:25:44 -0000
@@ -29,6 +29,7 @@ stdio.h: stdio_.h
              -e 's|@''GNULIB_VPRINTF_POSIX''@|$(GNULIB_VPRINTF_POSIX)|g' \
              -e 's|@''GNULIB_VSNPRINTF''@|$(GNULIB_VSNPRINTF)|g' \
              -e 's|@''GNULIB_VSPRINTF_POSIX''@|$(GNULIB_VSPRINTF_POSIX)|g' \
+             -e 's|@''GNULIB_VASPRINTF''@|$(GNULIB_VASPRINTF)|g' \
              -e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \
              -e 's|@''REPLACE_VFPRINTF''@|$(REPLACE_VFPRINTF)|g' \
              -e 's|@''REPLACE_PRINTF''@|$(REPLACE_PRINTF)|g' \
@@ -39,6 +40,7 @@ stdio.h: stdio_.h
              -e 's|@''HAVE_DECL_VSNPRINTF''@|$(HAVE_DECL_VSNPRINTF)|g' \
              -e 's|@''REPLACE_SPRINTF''@|$(REPLACE_SPRINTF)|g' \
              -e 's|@''REPLACE_VSPRINTF''@|$(REPLACE_VSPRINTF)|g' \
+             -e 's|@''REPLACE_VASPRINTF''@|$(REPLACE_VASPRINTF)|g' \
              -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
              < $(srcdir)/stdio_.h; \
        } > address@hidden
Index: modules/vasprintf
===================================================================
RCS file: /sources/gnulib/gnulib/modules/vasprintf,v
retrieving revision 1.4
diff -u -p -r1.4 vasprintf
--- modules/vasprintf   13 Oct 2006 12:40:23 -0000      1.4
+++ modules/vasprintf   22 Mar 2007 13:25:44 -0000
@@ -2,13 +2,13 @@ Description:
 vsprintf with automatic memory allocation.
 
 Files:
-lib/vasprintf.h
 lib/vasprintf.c
 lib/asprintf.c
 m4/vasprintf.m4
 
 Depends-on:
 vasnprintf
+stdio
 
 configure.ac:
 gl_FUNC_VASPRINTF
@@ -16,7 +16,7 @@ gl_FUNC_VASPRINTF
 Makefile.am:
 
 Include:
-"vasprintf.h"
+<stdio.h>
 
 License:
 LGPL
Index: tests/test-vasprintf-posix.c
===================================================================
RCS file: /sources/gnulib/gnulib/tests/test-vasprintf-posix.c,v
retrieving revision 1.2
diff -u -p -r1.2 test-vasprintf-posix.c
--- tests/test-vasprintf-posix.c        5 Mar 2007 03:20:23 -0000       1.2
+++ tests/test-vasprintf-posix.c        22 Mar 2007 13:25:44 -0000
@@ -21,7 +21,7 @@
 # include <config.h>
 #endif
 
-#include "vasprintf.h"
+#include <stdio.h>
 
 #include <stdarg.h>
 #include <stddef.h>
Index: tests/test-vasprintf.c
===================================================================
RCS file: /sources/gnulib/gnulib/tests/test-vasprintf.c,v
retrieving revision 1.2
diff -u -p -r1.2 test-vasprintf.c
--- tests/test-vasprintf.c      5 Mar 2007 00:28:36 -0000       1.2
+++ tests/test-vasprintf.c      22 Mar 2007 13:25:44 -0000
@@ -21,7 +21,7 @@
 # include <config.h>
 #endif
 
-#include "vasprintf.h"
+#include <stdio.h>
 
 #include <stdarg.h>
 #include <stdlib.h>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]