This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[patch/rfc] bcache return a const buffer
- From: Andrew Cagney <ac131313 at redhat dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Fri, 07 Nov 2003 19:02:45 -0500
- Subject: [patch/rfc] bcache return a const buffer
Hello,
This patch makes the returned buffer from bcache() const. It then adds
a deprecated_bcache() method that returns a non-const buffer.
Symtab is updated to use the non-const method. Notably macrotab didn't
need an update!
Baring comments, I'll commit in a week.
Andrew
PS: For the record, I tried fixing the const problems but tripped up on
this code: http://sources.redhat.com/ml/gdb/2003-11/msg00032.html
2003-11-07 Andrew Cagney <cagney@redhat.com>
* bcache.c (deprecated_bcache): New function.
(bcache_data): New function.
(bcache): Call bcache data.
* symfile.c (add_psymbol_to_list): Use deprecated_bcache.
(add_psymbol_with_dem_name_to_list): Ditto.
* bcache.h (deprecated_bcache): Declare.
(bcache): Make returned buffer constant.
Index: bcache.c
===================================================================
RCS file: /cvs/src/src/gdb/bcache.c,v
retrieving revision 1.11
diff -u -r1.11 bcache.c
--- bcache.c 3 Nov 2003 17:03:11 -0000 1.11
+++ bcache.c 7 Nov 2003 23:56:34 -0000
@@ -184,8 +184,8 @@
/* Find a copy of the LENGTH bytes at ADDR in BCACHE. If BCACHE has
never seen those bytes before, add a copy of them to BCACHE. In
either case, return a pointer to BCACHE's copy of that string. */
-void *
-bcache (const void *addr, int length, struct bcache *bcache)
+static void *
+bcache_data (const void *addr, int length, struct bcache *bcache)
{
int hash_index;
struct bstring *s;
@@ -222,6 +222,17 @@
}
}
+void *
+deprecated_bcache (const void *addr, int length, struct bcache *bcache)
+{
+ return bcache_data (addr, length, bcache);
+}
+
+const void *
+bcache (const void *addr, int length, struct bcache *bcache)
+{
+ return bcache_data (addr, length, bcache);
+}
/* Allocating and freeing bcaches. */
Index: bcache.h
===================================================================
RCS file: /cvs/src/src/gdb/bcache.h,v
retrieving revision 1.6
diff -u -r1.6 bcache.h
--- bcache.h 12 Jul 2002 15:23:10 -0000 1.6
+++ bcache.h 7 Nov 2003 23:56:34 -0000
@@ -68,8 +68,13 @@
/* Find a copy of the LENGTH bytes at ADDR in BCACHE. If BCACHE has
never seen those bytes before, add a copy of them to BCACHE. In
- either case, return a pointer to BCACHE's copy of that string. */
-extern void *bcache (const void *addr, int length, struct bcache *bcache);
+ either case, return a pointer to BCACHE's copy of that string.
+ Since the cached value is ment to be read-only, return a const
+ buffer. */
+extern void *deprecated_bcache (const void *addr, int length,
+ struct bcache *bcache);
+extern const void *bcache (const void *addr, int length,
+ struct bcache *bcache);
/* Free all the storage used by BCACHE. */
extern void bcache_xfree (struct bcache *bcache);
Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.111
diff -u -r1.111 symfile.c
--- symfile.c 29 Oct 2003 18:29:07 -0000 1.111
+++ symfile.c 7 Nov 2003 23:56:36 -0000
@@ -2680,7 +2680,8 @@
SYMBOL_SET_NAMES (&psymbol, buf, namelength, objfile);
/* Stash the partial symbol away in the cache */
- psym = bcache (&psymbol, sizeof (struct partial_symbol), objfile->psymbol_cache);
+ psym = deprecated_bcache (&psymbol, sizeof (struct partial_symbol),
+ objfile->psymbol_cache);
/* Save pointer to partial symbol in psymtab, growing symtab if needed. */
if (list->next >= list->list + list->size)
@@ -2717,7 +2718,8 @@
memcpy (buf, name, namelength);
buf[namelength] = '\0';
- DEPRECATED_SYMBOL_NAME (&psymbol) = bcache (buf, namelength + 1, objfile->psymbol_cache);
+ DEPRECATED_SYMBOL_NAME (&psymbol) = deprecated_bcache (buf, namelength + 1,
+ objfile->psymbol_cache);
buf = alloca (dem_namelength + 1);
memcpy (buf, dem_name, dem_namelength);
@@ -2728,7 +2730,7 @@
case language_c:
case language_cplus:
SYMBOL_CPLUS_DEMANGLED_NAME (&psymbol) =
- bcache (buf, dem_namelength + 1, objfile->psymbol_cache);
+ deprecated_bcache (buf, dem_namelength + 1, objfile->psymbol_cache);
break;
/* FIXME What should be done for the default case? Ignoring for now. */
}
@@ -2749,7 +2751,8 @@
SYMBOL_INIT_LANGUAGE_SPECIFIC (&psymbol, language);
/* Stash the partial symbol away in the cache */
- psym = bcache (&psymbol, sizeof (struct partial_symbol), objfile->psymbol_cache);
+ psym = deprecated_bcache (&psymbol, sizeof (struct partial_symbol),
+ objfile->psymbol_cache);
/* Save pointer to partial symbol in psymtab, growing symtab if needed. */
if (list->next >= list->list + list->size)