Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Tom Tromey <tromey@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [patch 1/3] Make obconcat use stdarg
Date: Fri, 30 Apr 2010 19:07:00 -0000	[thread overview]
Message-ID: <20100430190737.GA13525@host0.dyn.jankratochvil.net> (raw)
In-Reply-To: <m31vdwzsxy.fsf@fleche.redhat.com>

On Fri, 30 Apr 2010 20:38:49 +0200, Tom Tromey wrote:
> I think it is better to just do the copying in a single loop.
> Obstacks already handle growing objects well enough, there's no need to
> work around this.

True, fixed.


Thanks,
Jan


2010-04-30  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* defs.h (ATTR_SENTINEL): New.
	* dwarf2read.c (typename_concat): Use NULL-terminated stdarg list for
	the obconcat call.
	* mdebugread.c (parse_symbol): Likewise.
	* stabsread.c (define_symbol, read_member_functions, read_cpp_abbrev):
	Likewise.
	* symfile.c (obconcat): Replace the s1, s2 and s3 parameters by `...'.
	New variable ap.  Remove variables len and val.
	* symfile.h (obconcat): Likewise for the prototype.

--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -304,6 +304,14 @@ struct cleanup
 #endif
 #endif
 
+#ifndef ATTR_SENTINEL
+#if defined(__GNUC__) && __GNUC__ >= 4
+#define ATTR_SENTINEL __attribute__ ((sentinel))
+#else
+#define ATTR_SENTINEL		/* nothing */
+#endif
+#endif
+
 /* Be conservative and use enum bitfields only with GCC.
    This is copied from gcc 3.3.1, system.h.  */
 
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -9223,7 +9223,7 @@ typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
   else
     {
       /* We have an obstack.  */
-      return obconcat (obs, prefix, sep, suffix);
+      return obconcat (obs, prefix, sep, suffix, NULL);
     }
 }
 
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -998,8 +998,8 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 	if (sh->iss == 0 || name[0] == '.' || name[0] == '\0')
 	  TYPE_TAG_NAME (t) = NULL;
 	else
-	  TYPE_TAG_NAME (t) = obconcat (&current_objfile->objfile_obstack,
-					"", "", name);
+	  TYPE_TAG_NAME (t) = obconcat (&current_objfile->objfile_obstack, name,
+					NULL);
 
 	TYPE_CODE (t) = type_code;
 	TYPE_LENGTH (t) = sh->value;
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -1280,9 +1280,9 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
           SYMBOL_VALUE (struct_sym) = valu;
           SYMBOL_DOMAIN (struct_sym) = STRUCT_DOMAIN;
           if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
-            TYPE_NAME (SYMBOL_TYPE (sym))
-              = obconcat (&objfile->objfile_obstack, "", "",
-                          SYMBOL_LINKAGE_NAME (sym));
+            TYPE_NAME (SYMBOL_TYPE (sym)) = obconcat (&objfile->objfile_obstack,
+						      SYMBOL_LINKAGE_NAME (sym),
+						      NULL);
           add_symbol_to_list (struct_sym, &file_symbols);
         }
       
@@ -1307,9 +1307,9 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
       SYMBOL_VALUE (sym) = valu;
       SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
       if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
-	TYPE_TAG_NAME (SYMBOL_TYPE (sym))
-	  = obconcat (&objfile->objfile_obstack, "", "",
-		      SYMBOL_LINKAGE_NAME (sym));
+	TYPE_TAG_NAME (SYMBOL_TYPE (sym)) = obconcat (&objfile->objfile_obstack,
+						      SYMBOL_LINKAGE_NAME (sym),
+						      NULL);
       add_symbol_to_list (sym, &file_symbols);
 
       if (synonym)
@@ -1322,9 +1322,9 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
 	  SYMBOL_VALUE (typedef_sym) = valu;
 	  SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
 	  if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
-	    TYPE_NAME (SYMBOL_TYPE (sym))
-	      = obconcat (&objfile->objfile_obstack, "", "",
-			  SYMBOL_LINKAGE_NAME (sym));
+	    TYPE_NAME (SYMBOL_TYPE (sym)) = obconcat (&objfile->objfile_obstack,
+						      SYMBOL_LINKAGE_NAME (sym),
+						      NULL);
 	  add_symbol_to_list (typedef_sym, &file_symbols);
 	}
       break;
@@ -2610,8 +2610,8 @@ read_member_functions (struct field_info *fip, char **pp, struct type *type,
 	      make_cleanup (xfree, destr_fnlist);
 	      memset (destr_fnlist, 0, sizeof (struct next_fnfieldlist));
 	      destr_fnlist->fn_fieldlist.name
-		= obconcat (&objfile->objfile_obstack, "", "~",
-			    new_fnlist->fn_fieldlist.name);
+		= obconcat (&objfile->objfile_obstack, "~",
+			    new_fnlist->fn_fieldlist.name, NULL);
 
 	      destr_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
 		obstack_alloc (&objfile->objfile_obstack,
@@ -2748,8 +2748,8 @@ read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
 	  {
 		  name = "";
 	  }
-	  fip->list->field.name =
-	    obconcat (&objfile->objfile_obstack, vptr_name, name, "");
+	  fip->list->field.name = obconcat (&objfile->objfile_obstack,
+					    vptr_name, name, NULL);
 	  break;
 
 	case 'b':		/* $vb -- a virtual bsomethingorother */
@@ -2761,15 +2761,14 @@ read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
 			 symnum);
 	      name = "FOO";
 	    }
-	  fip->list->field.name =
-	    obconcat (&objfile->objfile_obstack, vb_name, name, "");
+	  fip->list->field.name = obconcat (&objfile->objfile_obstack, vb_name,
+					    name, NULL);
 	  break;
 
 	default:
 	  invalid_cpp_abbrev_complaint (*pp);
-	  fip->list->field.name =
-	    obconcat (&objfile->objfile_obstack,
-		      "INVALID_CPLUSPLUS_ABBREV", "", "");
+	  fip->list->field.name = obconcat (&objfile->objfile_obstack,
+					    "INVALID_CPLUSPLUS_ABBREV", NULL);
 	  break;
 	}
 
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -212,19 +212,28 @@ obsavestring (const char *ptr, int size, struct obstack *obstackp)
   return p;
 }
 
-/* Concatenate strings S1, S2 and S3; return the new string.  Space is found
-   in the obstack pointed to by OBSTACKP.  */
+/* Concatenate NULL terminated variable argument list of `const char *' strings;
+   return the new string.  Space is found in the OBSTACKP  */
 
 char *
-obconcat (struct obstack *obstackp, const char *s1, const char *s2,
-	  const char *s3)
-{
-  int len = strlen (s1) + strlen (s2) + strlen (s3) + 1;
-  char *val = (char *) obstack_alloc (obstackp, len);
-  strcpy (val, s1);
-  strcat (val, s2);
-  strcat (val, s3);
-  return val;
+obconcat (struct obstack *obstackp, ...)
+{
+  va_list ap;
+
+  va_start (ap, obstackp);
+  for (;;)
+    {
+      const char *s = va_arg (ap, const char *);
+
+      if (s == NULL)
+	break;
+
+      obstack_grow_str (obstackp, s);
+    }
+  va_end (ap);
+  obstack_1grow (obstackp, 0);
+
+  return obstack_finish (obstackp);
 }
 
 /* True if we are reading a symbol table. */
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -458,11 +458,10 @@ extern struct partial_symtab *start_psymtab_common (struct objfile *,
 
 extern char *obsavestring (const char *, int, struct obstack *);
 
-/* Concatenate strings S1, S2 and S3; return the new string.  Space is
-   found in the OBSTACKP  */
+/* Concatenate NULL terminated variable argument list of `const char *' strings;
+   return the new string.  Space is found in the OBSTACKP  */
 
-extern char *obconcat (struct obstack *obstackp, const char *, const char *,
-		       const char *);
+extern char *obconcat (struct obstack *obstackp, ...) ATTR_SENTINEL;
 
 			/*   Variables   */
 


  reply	other threads:[~2010-04-30 19:07 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-30 18:16 Jan Kratochvil
2010-04-30 18:38 ` Tom Tromey
2010-04-30 19:07   ` Jan Kratochvil [this message]
2010-04-30 19:09 ` Mark Kettenis
2010-04-30 22:18   ` `sentinel' gcc-3.x/OpenBSD compat. [Re: [patch 1/3] Make obconcat use stdarg] Jan Kratochvil
2010-05-01  0:10     ` Pedro Alves
2010-05-02 12:04       ` [patch] ATTR_* -> ATTRIBUTE_* unification [Re: `sentinel' gcc-3.x/OpenBSD compat.] Jan Kratochvil
2010-05-02 15:33         ` Pedro Alves
2010-05-02 21:37           ` Jan Kratochvil
2010-05-02 23:20             ` [patch] ATTR_NORETURN -> ATTRIBUTE_NORETURN unification [Re: [patch] ATTR_* -> ATTRIBUTE_* unification] Jan Kratochvil
2010-05-02 23:42               ` Pedro Alves
2010-05-02 23:53                 ` Jan Kratochvil
2010-05-03  7:18                   ` Pierre Muller
2010-05-03  7:44                     ` Jan Kratochvil
2010-05-04  6:34                       ` Pierre Muller
2010-05-04 15:28                         ` Joel Brobecker
     [not found]                   ` <6652.26431233368$1272871093@news.gmane.org>
2010-05-03 18:15                     ` Tom Tromey
2010-05-01  6:07     ` `sentinel' gcc-3.x/OpenBSD compat. [Re: [patch 1/3] Make obconcat use stdarg] Eli Zaretskii
2010-05-02  6:49       ` Jan Kratochvil
2010-05-01  8:53     ` Mark Kettenis
2010-05-07 16:58       ` Jan Kratochvil
2010-05-07 22:34         ` Tom Tromey
2010-05-08  4:59           ` Jan Kratochvil
2010-05-02  7:52   ` [patch 1/3] Make obconcat use stdarg Jan Kratochvil
2010-05-03 18:25     ` Tom Tromey
2010-05-03 20:19     ` Mark Kettenis
2010-05-03 21:00       ` Pedro Alves
2010-05-04 21:03         ` Mark Kettenis
2010-05-07 14:31           ` Jan Kratochvil
2010-05-07 14:36             ` Pedro Alves
2010-05-07 14:44               ` Jan Kratochvil
2010-05-07 14:44             ` Mark Kettenis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100430190737.GA13525@host0.dyn.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox