This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[patch] fix declaration of obsavestring
- From: David Carlton <carlton at math dot stanford dot edu>
- To: gdb-patches at sources dot redhat dot com
- Date: 10 Oct 2002 13:03:51 -0700
- Subject: [patch] fix declaration of obsavestring
I recently wanted to use obsavestring, and I noticed that its
declaration wasn't as good as it could be: the first argument might as
well be a const char *, and there should be an opaque declaration for
struct obstack somewhere.
Here's a patch for that; it seems obvious, so I'll commit it in a few
days if nobody objects.
David Carlton
carlton@math.stanford.edu
2002-10-09 David Carlton <carlton@math.stanford.edu>
* symfile.h: Add opaque declaration for struct obstack.
Declare obsavestring to take a const char *.
* symfile.c (obsavestring): Make first argument a const char *.
Index: symfile.h
===================================================================
RCS file: /cvs/src/src/gdb/symfile.h,v
retrieving revision 1.13
diff -u -p -r1.13 symfile.h
--- symfile.h 22 Apr 2002 10:19:04 -0000 1.13
+++ symfile.h 9 Oct 2002 16:13:35 -0000
@@ -25,6 +25,10 @@
/* This file requires that you first include "bfd.h". */
+/* Opaque declarations. */
+
+struct obstack;
+
/* Partial symbols are stored in the psymbol_cache and pointers to them
are kept in a dynamically grown array that is obtained from malloc and
grown as necessary via realloc. Each objfile typically has two of these,
@@ -208,7 +212,7 @@ extern void sort_symtab_syms (struct sym
(and add a null character at the end in the copy).
Returns the address of the copy. */
-extern char *obsavestring (char *, int, struct obstack *);
+extern char *obsavestring (const char *, int, struct obstack *);
/* Concatenate strings S1, S2 and S3; return the new string.
Space is found in the symbol_obstack. */
Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.69
diff -u -p -r1.69 symfile.c
--- symfile.c 20 Sep 2002 14:58:58 -0000 1.69
+++ symfile.c 9 Oct 2002 16:13:31 -0000
@@ -299,16 +299,16 @@ sort_symtab_syms (register struct symtab
may be part of a larger string and we are only saving a substring. */
char *
-obsavestring (char *ptr, int size, struct obstack *obstackp)
+obsavestring (const char *ptr, int size, struct obstack *obstackp)
{
register char *p = (char *) obstack_alloc (obstackp, size + 1);
/* Open-coded memcpy--saves function call time. These strings are usually
short. FIXME: Is this really still true with a compiler that can
inline memcpy? */
{
- register char *p1 = ptr;
+ register const char *p1 = ptr;
register char *p2 = p;
- char *end = ptr + size;
+ const char *end = ptr + size;
while (p1 != end)
*p2++ = *p1++;
}