replace XCALLOC with XCNEWVEC or XCNEW
authorTom Tromey <tromey@redhat.com>
Sat, 28 Dec 2013 22:32:27 +0000 (15:32 -0700)
committerTom Tromey <tromey@redhat.com>
Mon, 13 Jan 2014 14:31:29 +0000 (07:31 -0700)
This removes XCALLOC and replaces it either with XCNEWVEC, or, if the
number of elements being requested was 1, with XCNEW.

2014-01-13  Tom Tromey  <tromey@redhat.com>

* defs.h (XCALLOC): Remove.
* bcache.c (bcache_xmalloc): Use XCNEW, not XCALLOC.
(print_bcache_statistics): Use XCNEWVEC, not XCALLOC.
* dwarf2loc.c (allocate_piece_closure): Likewise.
* elfread.c (elf_symfile_segments): Likewise.
(elf_symfile_segments): Likewise.
* gdbtypes.c (copy_type_recursive): Likewise.
* i386-tdep.c (i386_gdbarch_init): Use XCNEW, not XCALLOC.
* jit.c (jit_frame_sniffer): Use XCNEWVEC, not XCALLOC.
* minsyms.c (prim_record_minimal_symbol_full): Use XCNEW, not
XCALLOC.
* mt-tdep.c (mt_gdbarch_init): Likewise.
* opencl-lang.c (allocate_lval_closure): Use XCNEWVEC, not
XCALLOC.
* psymtab.c (psymbol_compare): Use XCNEW, not XCALLOC.
* regcache.c (regcache_xmalloc_1): Use XCNEWVEC, not XCALLOC.
* registry.c (registry_alloc_data): Likewise.
* rs6000-tdep.c (rs6000_gdbarch_init): Use XCNEW, not XCALLOC.
* s390-linux-tdep.c (s390_gdbarch_init): Likewise.
* serial.c (serial_fdopen_ops): Likewise.
* solib-aix.c (solib_aix_get_section_offsets): Use XCNEWVEC, not
XCALLOC.
* spu-tdep.c (spu_gdbarch_init): Use XCNEW, not XCALLOC.
* symfile.c (default_symfile_segments): Use XCNEW and XCNEWVEC,
not XCALLOC.

20 files changed:
gdb/ChangeLog
gdb/bcache.c
gdb/defs.h
gdb/dwarf2loc.c
gdb/elfread.c
gdb/gdbtypes.c
gdb/i386-tdep.c
gdb/jit.c
gdb/minsyms.c
gdb/mt-tdep.c
gdb/opencl-lang.c
gdb/psymtab.c
gdb/regcache.c
gdb/registry.c
gdb/rs6000-tdep.c
gdb/s390-linux-tdep.c
gdb/serial.c
gdb/solib-aix.c
gdb/spu-tdep.c
gdb/symfile.c

index a55e19db2dd2dcda677a0c032144a1611735a691..2247c790c7d08795e4d77e6618eae9a3c9886dfc 100644 (file)
@@ -1,3 +1,31 @@
+2014-01-13  Tom Tromey  <tromey@redhat.com>
+
+       * defs.h (XCALLOC): Remove.
+       * bcache.c (bcache_xmalloc): Use XCNEW, not XCALLOC.
+       (print_bcache_statistics): Use XCNEWVEC, not XCALLOC.
+       * dwarf2loc.c (allocate_piece_closure): Likewise.
+       * elfread.c (elf_symfile_segments): Likewise.
+       (elf_symfile_segments): Likewise.
+       * gdbtypes.c (copy_type_recursive): Likewise.
+       * i386-tdep.c (i386_gdbarch_init): Use XCNEW, not XCALLOC.
+       * jit.c (jit_frame_sniffer): Use XCNEWVEC, not XCALLOC.
+       * minsyms.c (prim_record_minimal_symbol_full): Use XCNEW, not
+       XCALLOC.
+       * mt-tdep.c (mt_gdbarch_init): Likewise.
+       * opencl-lang.c (allocate_lval_closure): Use XCNEWVEC, not
+       XCALLOC.
+       * psymtab.c (psymbol_compare): Use XCNEW, not XCALLOC.
+       * regcache.c (regcache_xmalloc_1): Use XCNEWVEC, not XCALLOC.
+       * registry.c (registry_alloc_data): Likewise.
+       * rs6000-tdep.c (rs6000_gdbarch_init): Use XCNEW, not XCALLOC.
+       * s390-linux-tdep.c (s390_gdbarch_init): Likewise.
+       * serial.c (serial_fdopen_ops): Likewise.
+       * solib-aix.c (solib_aix_get_section_offsets): Use XCNEWVEC, not
+       XCALLOC.
+       * spu-tdep.c (spu_gdbarch_init): Use XCNEW, not XCALLOC.
+       * symfile.c (default_symfile_segments): Use XCNEW and XCNEWVEC,
+       not XCALLOC.
+
 2014-01-13  Tom Tromey  <tromey@redhat.com>
 
        * defs.h (XMALLOC): Remove.
index 3d1280a61fa57d686cb99366678d73f2bfb4b2f7..99e9184ef6d0bb156028554cb6ece63f6ac1d121 100644 (file)
@@ -313,7 +313,7 @@ bcache_xmalloc (unsigned long (*hash_function)(const void *, int length),
                                        int length))
 {
   /* Allocate the bcache pre-zeroed.  */
-  struct bcache *b = XCALLOC (1, struct bcache);
+  struct bcache *b = XCNEW (struct bcache);
 
   if (hash_function)
     b->hash_function = hash_function;
@@ -372,8 +372,8 @@ print_bcache_statistics (struct bcache *c, char *type)
      lengths, and measure chain lengths.  */
   {
     unsigned int b;
-    int *chain_length = XCALLOC (c->num_buckets + 1, int);
-    int *entry_size = XCALLOC (c->unique_count + 1, int);
+    int *chain_length = XCNEWVEC (int, c->num_buckets + 1);
+    int *entry_size = XCNEWVEC (int, c->unique_count + 1);
     int stringi = 0;
 
     occupied_buckets = 0;
index a4770efb9b2ce78067efae7fd9c9e60356f05789..a7ce88a78310697003f5f4c82411992d4bc348d5 100644 (file)
@@ -553,11 +553,6 @@ enum val_prettyformat
 
 extern int longest_to_int (LONGEST);
 
-/* Utility macros to allocate typed memory.  Avoids errors like:
-   struct foo *foo = xmalloc (sizeof struct bar); and memset (foo,
-   sizeof (struct foo), 0).  */
-#define XCALLOC(NMEMB, TYPE) ((TYPE*) xcalloc ((NMEMB), sizeof (TYPE)))
-
 #include "common-utils.h"
 
 /* List of known OS ABIs.  If you change this, make sure to update the
index 6185a6b4e2501c120e4305a0dfce70bf96608f98..99a18a95ed68844e160a2e262ed3cbd861e5bea3 100644 (file)
@@ -1421,7 +1421,7 @@ allocate_piece_closure (struct dwarf2_per_cu_data *per_cu,
   c->per_cu = per_cu;
   c->n_pieces = n_pieces;
   c->addr_size = addr_size;
-  c->pieces = XCALLOC (n_pieces, struct dwarf_expr_piece);
+  c->pieces = XCNEWVEC (struct dwarf_expr_piece, n_pieces);
 
   memcpy (c->pieces, pieces, n_pieces * sizeof (struct dwarf_expr_piece));
   for (i = 0; i < n_pieces; ++i)
index 4f27aff19e1234ad86b9e55f74f02a860fc6024b..d43a1f74ffd5dded921e8a83ae6f6063410e21c5 100644 (file)
@@ -107,8 +107,8 @@ elf_symfile_segments (bfd *abfd)
 
   data = XCNEW (struct symfile_segment_data);
   data->num_segments = num_segments;
-  data->segment_bases = XCALLOC (num_segments, CORE_ADDR);
-  data->segment_sizes = XCALLOC (num_segments, CORE_ADDR);
+  data->segment_bases = XCNEWVEC (CORE_ADDR, num_segments);
+  data->segment_sizes = XCNEWVEC (CORE_ADDR, num_segments);
 
   for (i = 0; i < num_segments; i++)
     {
@@ -117,7 +117,7 @@ elf_symfile_segments (bfd *abfd)
     }
 
   num_sections = bfd_count_sections (abfd);
-  data->segment_info = XCALLOC (num_sections, int);
+  data->segment_info = XCNEWVEC (int, num_sections);
 
   for (i = 0, sect = abfd->sections; sect != NULL; i++, sect = sect->next)
     {
index e02b66c7aacb9211714784c7992bec5b182a47d9..042c17d4c6b66c5cf1787a118239bcb457a09955 100644 (file)
@@ -3700,7 +3700,7 @@ copy_type_recursive (struct objfile *objfile,
       int i, nfields;
 
       nfields = TYPE_NFIELDS (type);
-      TYPE_FIELDS (new_type) = XCALLOC (nfields, struct field);
+      TYPE_FIELDS (new_type) = XCNEWVEC (struct field, nfields);
       for (i = 0; i < nfields; i++)
        {
          TYPE_FIELD_ARTIFICIAL (new_type, i) = 
index 9d1d9e0ad5611b799a3cab1f9df36c9f5896534f..4a5f652b168d79facacf9dbec413620a38f612a5 100644 (file)
@@ -7819,7 +7819,7 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
     return arches->gdbarch;
 
   /* Allocate space for the new architecture.  */
-  tdep = XCALLOC (1, struct gdbarch_tdep);
+  tdep = XCNEW (struct gdbarch_tdep);
   gdbarch = gdbarch_alloc (&info, tdep);
 
   /* General-purpose registers.  */
index ebbee5418e03882c7b8131cfaa1948eb37cd9363..546b3b62eaa02b805c295a0cdf270a943ba65f9f 100644 (file)
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -1184,8 +1184,8 @@ jit_frame_sniffer (const struct frame_unwind *self,
   *cache = XCNEW (struct jit_unwind_private);
   priv_data = *cache;
   priv_data->registers =
-    XCALLOC (gdbarch_num_regs (get_frame_arch (this_frame)),
-             struct gdb_reg_value *);
+    XCNEWVEC (struct gdb_reg_value *,        
+             gdbarch_num_regs (get_frame_arch (this_frame)));
   priv_data->this_frame = this_frame;
 
   callbacks.priv_data = priv_data;
index ee9575c8fa527a6daf41e09563feecc04a4260db..c7ae981605c4662dfc1138bc0bd0eab31f986f1b 100644 (file)
@@ -935,7 +935,7 @@ prim_record_minimal_symbol_full (const char *name, int name_len, int copy_name,
 
   if (msym_bunch_index == BUNCH_SIZE)
     {
-      new = XCALLOC (1, struct msym_bunch);
+      new = XCNEW (struct msym_bunch);
       msym_bunch_index = 0;
       new->next = msym_bunch;
       msym_bunch = new;
index 2072528c899ff1bd36421258ed5cdb93671d45fc..e3786e815ea8afb8dfd64e0095d52a4510a22055 100644 (file)
@@ -1149,7 +1149,7 @@ mt_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* None found, create a new architecture from the information
      provided.  */
-  tdep = XCALLOC (1, struct gdbarch_tdep);
+  tdep = XCNEW (struct gdbarch_tdep);
   gdbarch = gdbarch_alloc (&info, tdep);
 
   set_gdbarch_float_format (gdbarch, floatformats_ieee_single);
index 4bcaf7ecaecf8cf056f98fc94c7b2e11b017eb2c..2dd76fac36eeb4694e4611d3ba62595f99bf758d 100644 (file)
@@ -160,7 +160,7 @@ allocate_lval_closure (int *indices, int n, struct value *val)
 
   c->refc = 1;
   c->n = n;
-  c->indices = XCALLOC (n, int);
+  c->indices = XCNEWVEC (int, n);
   memcpy (c->indices, indices, n * sizeof (int));
   value_incref (val); /* Increment the reference counter of the value.  */
   c->val = val;
index 34e833c04c1a82ae044af60ea4a5e3e6b7de7c6c..56fe409ae689e8e95e17a68b82a18016d1c884f7 100644 (file)
@@ -1530,7 +1530,7 @@ psymbol_compare (const void *addr1, const void *addr2, int length)
 struct psymbol_bcache *
 psymbol_bcache_init (void)
 {
-  struct psymbol_bcache *bcache = XCALLOC (1, struct psymbol_bcache);
+  struct psymbol_bcache *bcache = XCNEW (struct psymbol_bcache);
   bcache->bcache = bcache_xmalloc (psymbol_hash, psymbol_compare);
   return bcache;
 }
index 1ddf9b025aef19d0ce44982202352d42044f75dd..8b588c60050b66d68605545491248ed588f16b4c 100644 (file)
@@ -223,16 +223,16 @@ regcache_xmalloc_1 (struct gdbarch *gdbarch, struct address_space *aspace,
   if (readonly_p)
     {
       regcache->registers
-       = XCALLOC (descr->sizeof_cooked_registers, gdb_byte);
+       = XCNEWVEC (gdb_byte, descr->sizeof_cooked_registers);
       regcache->register_status
-       = XCALLOC (descr->sizeof_cooked_register_status, signed char);
+       = XCNEWVEC (signed char, descr->sizeof_cooked_register_status);
     }
   else
     {
       regcache->registers
-       = XCALLOC (descr->sizeof_raw_registers, gdb_byte);
+       = XCNEWVEC (gdb_byte, descr->sizeof_raw_registers);
       regcache->register_status
-       = XCALLOC (descr->sizeof_raw_register_status, signed char);
+       = XCNEWVEC (signed char, descr->sizeof_raw_register_status);
     }
   regcache->aspace = aspace;
   regcache->ptid = minus_one_ptid;
index ed614b9ba6458f6058c262211ce0cc9a6e52d9f3..2fd60335e88d1adb99efd5f109666078b26e809b 100644 (file)
@@ -51,7 +51,7 @@ registry_alloc_data (struct registry_data_registry *registry,
 {
   gdb_assert (fields->data == NULL);
   fields->num_data = registry->num_registrations;
-  fields->data = XCALLOC (fields->num_data, void *);
+  fields->data = XCNEWVEC (void *, fields->num_data);
 }
 
 void
index 0008f843db850891f83e0f74396230414b1af1e9..d7416e5a2dcaecb6f0f4cc761ecd53820301c624 100644 (file)
@@ -3954,7 +3954,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        - "set arch"            trust blindly
        - GDB startup           useless but harmless */
 
-  tdep = XCALLOC (1, struct gdbarch_tdep);
+  tdep = XCNEW (struct gdbarch_tdep);
   tdep->wordsize = wordsize;
   tdep->soft_float = soft_float;
   tdep->vector_abi = vector_abi;
index 69befcfa4c51aad7fb4fcab41c37d0aa61affd82..b75c86a5789e97808d223e402ed08dac699912cd 100644 (file)
@@ -3196,7 +3196,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
     }
 
   /* Otherwise create a new gdbarch for the specified machine type.  */
-  tdep = XCALLOC (1, struct gdbarch_tdep);
+  tdep = XCNEW (struct gdbarch_tdep);
   tdep->abi = tdep_abi;
   gdbarch = gdbarch_alloc (&info, tdep);
 
index c87875fc96b7c415791aebbef194fa1d886072b6..2b1ecedae38801f17fe6db66c7bd08f3f94cb4c9 100644 (file)
@@ -263,7 +263,7 @@ serial_fdopen_ops (const int fd, const struct serial_ops *ops)
   if (!ops)
     return NULL;
 
-  scb = XCALLOC (1, struct serial);
+  scb = XCNEW (struct serial);
 
   scb->ops = ops;
 
index 8f335f6a76c3649fc342bc15dc4bc870d3496dea..78d2753d46780fe90a59f05eca6b8572813b73c2 100644 (file)
@@ -470,7 +470,7 @@ solib_aix_get_section_offsets (struct objfile *objfile,
   bfd *abfd = objfile->obfd;
   int i;
 
-  offsets = XCALLOC (objfile->num_sections, struct section_offsets);
+  offsets = XCNEWVEC (struct section_offsets, objfile->num_sections);
 
   /* .text */
 
index 4d745d9ad746a0481a47d0b39f8d28b8ad7ea38b..f096a2ebbc3b2380de21e404411f48d739ed3b33 100644 (file)
@@ -2658,7 +2658,7 @@ spu_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
     }
 
   /* None found, so create a new architecture.  */
-  tdep = XCALLOC (1, struct gdbarch_tdep);
+  tdep = XCNEW (struct gdbarch_tdep);
   tdep->id = id;
   gdbarch = gdbarch_alloc (&info, tdep);
 
index 02471a4f9b28fbc8ab4aef28999d4c83ee6f38e3..a8bc3d8a5d31d4e100d3c46be5fd5dbd5919707a 100644 (file)
@@ -801,11 +801,11 @@ default_symfile_segments (bfd *abfd)
 
   data = XCNEW (struct symfile_segment_data);
   data->num_segments = 1;
-  data->segment_bases = XCALLOC (1, CORE_ADDR);
-  data->segment_sizes = XCALLOC (1, CORE_ADDR);
+  data->segment_bases = XCNEW (CORE_ADDR);
+  data->segment_sizes = XCNEW (CORE_ADDR);
 
   num_sections = bfd_count_sections (abfd);
-  data->segment_info = XCALLOC (num_sections, int);
+  data->segment_info = XCNEWVEC (int, num_sections);
 
   for (i = 0, sect = abfd->sections; sect != NULL; i++, sect = sect->next)
     {
This page took 0.04035 seconds and 4 git commands to generate.