This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch: allow multiple calls to VA_OPEN/VA_CLOSE, & convert concat.c
- To: gcc-patches at gcc dot gnu dot org
- Subject: Patch: allow multiple calls to VA_OPEN/VA_CLOSE, & convert concat.c
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Mon, 27 Aug 2001 07:58:29 -0400 (EDT)
- Cc: aj at suse dot de, dj at redhat dot com, zackw at panix dot com
This patch modifies VA_OPEN/VA_CLOSE to allow multiple invocations in
a single function. It does this by adding a layer of brackets to
enclose the va_list declaration and avoid having it appear multiple
times in the same scope. (I don't think there's anything magic about
having a single va_list when calling va_start more than once, is
there?)
Having done this, I was able to convert libiberty/concat.c to use it.
Given that a concat definition also lives in gcc/prefix.c currently
the libiberty one isn't much used. So I tested this patch with my own
copy of http://gcc.gnu.org/ml/gcc-patches/2001-08/msg01490.html to
ensure libiberty's concat still works after my modification.
Bootstrapped on solaris2.7. Ok to install?
--Kaveh
PS: I just realized that this patch perhaps removes some (one) of the
restrictions listed in the comments of ansidecl.h. I.e. not putting
statements before VA_OPEN. So I'll submit a separate patch to correct
that if this one is approved.
2001-08-26 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
include:
* ansidecl.h (VA_OPEN, VA_CLOSE): Allow multiple uses.
libiberty:
* concat.c (concat): Use VPARAMS, VA_OPEN, VA_FIXEDARG & VA_CLOSE.
diff -rup orig/egcs-CVS20010826/include/ansidecl.h egcs-CVS20010826/include/ansidecl.h
--- orig/egcs-CVS20010826/include/ansidecl.h Sat Aug 18 20:29:28 2001
+++ egcs-CVS20010826/include/ansidecl.h Sun Aug 26 23:50:29 2001
@@ -152,8 +152,8 @@ So instead we use the macro below and te
/* "struct Qdmy" swallows the semicolon after VA_OPEN/VA_FIXEDARG's
use without inhibiting further decls and without declaring an
actual variable. */
-#define VA_OPEN(AP, VAR) va_list AP; va_start(AP, VAR); { struct Qdmy
-#define VA_CLOSE(AP) } va_end(AP)
+#define VA_OPEN(AP, VAR) { va_list AP; va_start(AP, VAR); { struct Qdmy
+#define VA_CLOSE(AP) } va_end(AP); }
#define VA_FIXEDARG(AP, T, N) struct Qdmy
#undef const
@@ -199,8 +199,8 @@ So instead we use the macro below and te
#define VPARAMS(args) (va_alist) va_dcl
#define VA_START(va_list, var) va_start(va_list)
-#define VA_OPEN(AP, VAR) va_list AP; va_start(AP); { struct Qdmy
-#define VA_CLOSE(AP) } va_end(AP)
+#define VA_OPEN(AP, VAR) { va_list AP; va_start(AP); { struct Qdmy
+#define VA_CLOSE(AP) } va_end(AP); }
#define VA_FIXEDARG(AP, TYPE, NAME) TYPE NAME = va_arg(AP, TYPE)
/* some systems define these in header files for non-ansi mode */
diff -rup orig/egcs-CVS20010826/libiberty/concat.c egcs-CVS20010826/libiberty/concat.c
--- orig/egcs-CVS20010826/libiberty/concat.c Mon Jul 30 16:30:44 2001
+++ egcs-CVS20010826/libiberty/concat.c Sun Aug 26 23:44:13 2001
@@ -74,48 +74,29 @@ NOTES
# endif
# endif
-/* VARARGS */
-#ifdef ANSI_PROTOTYPES
char *
-concat (const char *first, ...)
-#else
-char *
-concat (va_alist)
- va_dcl
-#endif
+concat VPARAMS ((const char *first, ...))
{
register size_t length;
register char *newstr;
register char *end;
register const char *arg;
- va_list args;
-#ifndef ANSI_PROTOTYPES
- const char *first;
-#endif
/* First compute the size of the result and get sufficient memory. */
-#ifdef ANSI_PROTOTYPES
- va_start (args, first);
-#else
- va_start (args);
- first = va_arg (args, const char *);
-#endif
-
+ VA_OPEN (args, first);
+ VA_FIXEDARG (args, const char *, first);
+
length = 0;
for (arg = first; arg ; arg = va_arg (args, const char *))
length += strlen (arg);
- va_end (args);
+ VA_CLOSE (args);
newstr = (char *) xmalloc (length + 1);
/* Now copy the individual pieces to the result string. */
-#ifdef ANSI_PROTOTYPES
- va_start (args, first);
-#else
- va_start (args);
- first = va_arg (args, const char *);
-#endif
+ VA_OPEN (args, first);
+ VA_FIXEDARG (args, const char *, first);
end = newstr;
for (arg = first; arg ; arg = va_arg (args, const char *))
@@ -125,7 +106,7 @@ concat (va_alist)
end += length;
}
*end = '\000';
- va_end (args);
+ VA_CLOSE (args);
return newstr;
}