make obstack object allocators more type-safe
authorTom Tromey <tromey@redhat.com>
Fri, 13 Jun 2014 19:08:23 +0000 (13:08 -0600)
committerTom Tromey <tromey@redhat.com>
Fri, 20 Jun 2014 14:44:19 +0000 (08:44 -0600)
This changes OBSTACK_ZALLOC and OBSTACK_CALLOC to cast their value to
the correct type.  This is more type-safe and also is more in line
with the other object-allocation macros in libiberty.h.

Making this change revealed one trivial error in dwarf2read.c.
On the whole that seems pretty good to me.

Tested by rebuilding.

2014-06-20  Tom Tromey  <tromey@redhat.com>

* dwarf2read.c (dw2_get_real_path): Use correct type in
OBSTACK_CALLOC.
* gdb_obstack.h (OBSTACK_ZALLOC, OBSTACK_CALLOC): Cast result.

gdb/ChangeLog
gdb/dwarf2read.c
gdb/gdb_obstack.h

index 1fc54b2..be26dc9 100644 (file)
@@ -1,3 +1,9 @@
+2014-06-20  Tom Tromey  <tromey@redhat.com>
+
+       * dwarf2read.c (dw2_get_real_path): Use correct type in
+       OBSTACK_CALLOC.
+       * gdb_obstack.h (OBSTACK_ZALLOC, OBSTACK_CALLOC): Cast result.
+
 2014-06-20  Gary Benson  <gbenson@redhat.com>
 
        * common/gdb_thread_db.h: Moved to nat.  All includes updated.
index 9a9f5aa..ba64256 100644 (file)
@@ -3297,7 +3297,7 @@ dw2_get_real_path (struct objfile *objfile,
 {
   if (qfn->real_names == NULL)
     qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack,
-                                     qfn->num_file_names, char *);
+                                     qfn->num_file_names, const char *);
 
   if (qfn->real_names[index] == NULL)
     qfn->real_names[index] = gdb_realpath (qfn->file_names[index]);
index 0b39400..ec2dd97 100644 (file)
 /* Utility macros - wrap obstack alloc into something more robust.  */
 
 #define OBSTACK_ZALLOC(OBSTACK,TYPE) \
-  (memset (obstack_alloc ((OBSTACK), sizeof (TYPE)), 0, sizeof (TYPE)))
+  ((TYPE *) memset (obstack_alloc ((OBSTACK), sizeof (TYPE)), 0, sizeof (TYPE)))
 
 #define OBSTACK_CALLOC(OBSTACK,NUMBER,TYPE) \
-  (memset (obstack_alloc ((OBSTACK), (NUMBER) * sizeof (TYPE)), \
-          0, (NUMBER) * sizeof (TYPE)))
+  ((TYPE *) memset (obstack_alloc ((OBSTACK), (NUMBER) * sizeof (TYPE)), \
+                   0, (NUMBER) * sizeof (TYPE)))
 
 /* Unless explicitly specified, GDB obstacks always use xmalloc() and
    xfree().  */