[Top][All Lists]
[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: |
Tue, 13 Mar 2007 14:29:15 +0100 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.94 (gnu/linux) |
Bruno Haible <address@hidden> writes:
> Simon Josefsson wrote:
>> I haven't been paying attention to the *printf discussions, but
>> looking at current CVS, shouldn't the vasprintf module use stdio.h for
>> the prototypes?
>
> Yes, you're right. Since, as Paul said, gnulib not only attempts to mimic
> POSIX APIs but also glibc APIs, and glibc declares vasprintf() and asprintf()
> in <stdio.h>, gnulib should do the same.
Right.
>> 2007-03-12 Simon Josefsson <address@hidden>
>>
>> * modules/vasprintf: Depend on stdio for prototypes, and remove
>> vasprintf.h.
>>
>> * lib/stdio_.h: Declare asprintf and vasprintf, from vasprintf.h.
>>
>> * lib/asprintf.c: Use stdio.h for prototypes.
>> * lib/vasprintf.c: Ditto.
>>
>> * lib/vasprintf.h: File removed.
>
> Correct but a few things are missing:
> - While moving the declarations to <stdio.h>, you dropped the specification
> comments. They are essential.
> - While moving the declarations to <stdio.h>, you dropped the
> #if !HAVE_VASPRINTF. When an implementation has the functions and they
> work fine, we don't want to risk a compilation error due to redeclaration
> of system functions. The declarations should be skipped in this case.
> - The '# if REPLACE_VASPRINTF' needs to be turned into a test of an
> AC_SUBSTed variable, so that the generated stdio.h doesn't need a
> config.h.
> - After you settled on the changes to lib/stdio_.h, modules/stdio and
> m4/stdio_h.m4 need to be updated accordingly.
> - Also update the callers:
> fgrep '"vasprintf.h"' lib/*.c tests/*.c
> shows a few places to update.
Thanks! How about this?
/Simon
2007-03-13 Simon Josefsson <address@hidden>
* m4/stdio_h.m4: Add stubs for vasprintf too.
* modules/stdio: Support vasprintf in sed command.
* modules/vasprintf: Depend on stdio for prototypes, and remove
vasprintf.h.
* lib/stdio_.h: Declare asprintf and vasprintf, based on
vasprintf.h.
* lib/asprintf.c: Use stdio.h for prototypes.
* lib/vasprintf.c: Ditto.
* lib/vasprintf.h: File removed.
* tests/test-vasprintf-posix.c: Use stdio.h instead of vasprintf.h.
* tests/test-vasprintf.c: Ditto.
* lib/xvasprintf.c: Ditto.
Index: ChangeLog
===================================================================
RCS file: /sources/gnulib/gnulib/ChangeLog,v
retrieving revision 1.1392
diff -u -p -r1.1392 ChangeLog
--- ChangeLog 12 Mar 2007 22:40:24 -0000 1.1392
+++ ChangeLog 13 Mar 2007 13:28:59 -0000
@@ -1,3 +1,24 @@
+2007-03-13 Simon Josefsson <address@hidden>
+
+ * m4/stdio_h.m4: Add stubs for vasprintf too.
+
+ * modules/stdio: Support vasprintf in sed command.
+
+ * modules/vasprintf: Depend on stdio for prototypes, and remove
+ vasprintf.h.
+
+ * lib/stdio_.h: Declare asprintf and vasprintf, based on
+ vasprintf.h.
+
+ * lib/asprintf.c: Use stdio.h for prototypes.
+ * lib/vasprintf.c: Ditto.
+
+ * lib/vasprintf.h: File removed.
+
+ * tests/test-vasprintf-posix.c: Use stdio.h instead of vasprintf.h.
+ * tests/test-vasprintf.c: Ditto.
+ * lib/xvasprintf.c: Ditto.
+
2007-03-12 Bruno Haible <address@hidden>
* tests/test-printf-frexp.c (main): Declare x as volatile.
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 13 Mar 2007 13:28:59 -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 13 Mar 2007 13:28:59 -0000
@@ -183,6 +183,22 @@ 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
+# endif
+# 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
+#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 13 Mar 2007 13:28:59 -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 13 Mar 2007 13:28:59 -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 13 Mar 2007 13:28:59 -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,6 @@ 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])
+ HAVE_DECL_VASPRINTF=1; AC_SUBST([HAVE_DECL_VASPRINTF])
+ 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 13 Mar 2007 13:28:59 -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,8 @@ 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|@''HAVE_DECL_VASPRINTF''@|$(HAVE_DECL_VASPRINTF)|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 13 Mar 2007 13:28:59 -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 13 Mar 2007 13:28:59 -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 13 Mar 2007 13:28:59 -0000
@@ -21,7 +21,7 @@
# include <config.h>
#endif
-#include "vasprintf.h"
+#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
- *printf declarations in stdio.h?, Simon Josefsson, 2007/03/12
- Re: *printf declarations in stdio.h?, Bruno Haible, 2007/03/12
- Re: *printf declarations in stdio.h?,
Simon Josefsson <=
- Re: *printf declarations in stdio.h?, Bruno Haible, 2007/03/19
- Re: *printf declarations in stdio.h?, Simon Josefsson, 2007/03/22
- Re: *printf declarations in stdio.h?, Bruno Haible, 2007/03/22
- Re: *printf declarations in stdio.h?, Simon Josefsson, 2007/03/27
- Re: *printf declarations in stdio.h?, Bruno Haible, 2007/03/27
- Re: *printf declarations in stdio.h?, Simon Josefsson, 2007/03/27
- Re: *printf declarations in stdio.h?, Bruno Haible, 2007/03/27
- Re: *printf declarations in stdio.h?, Simon Josefsson, 2007/03/27