[23/27] Use 'new' for block and global_block

Message ID 20230120214618.3236224-24-tom@tromey.com
State New
Headers
Series C++-ify struct block |

Commit Message

Tom Tromey Jan. 20, 2023, 9:46 p.m. UTC
  This changes block and global_block to add initializers, and then to
use 'new' for allocation.
---
 gdb/block.c |  6 ++----
 gdb/block.h | 20 ++++++++++----------
 2 files changed, 12 insertions(+), 14 deletions(-)
  

Patch

diff --git a/gdb/block.c b/gdb/block.c
index 0870793dcd4..8f15cdf23f8 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -389,9 +389,7 @@  block::global_block () const
 struct block *
 allocate_block (struct obstack *obstack)
 {
-  struct block *bl = OBSTACK_ZALLOC (obstack, struct block);
-
-  return bl;
+  return new (obstack) struct block;
 }
 
 /* Allocate a global block.  */
@@ -399,7 +397,7 @@  allocate_block (struct obstack *obstack)
 struct block *
 allocate_global_block (struct obstack *obstack)
 {
-  struct global_block *bl = OBSTACK_ZALLOC (obstack, struct global_block);
+  struct global_block *bl = new (obstack) struct global_block;
 
   return &bl->block;
 }
diff --git a/gdb/block.h b/gdb/block.h
index 6ccf3766d8f..9a60140581d 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -105,7 +105,7 @@  struct blockranges
    This implies that within the body of one function
    the blocks appear in the order of a depth-first tree walk.  */
 
-struct block
+struct block : public allocate_on_obstack
 {
   /* Return this block's start address.  */
   CORE_ADDR start () const
@@ -273,13 +273,13 @@  struct block
 
   /* Addresses in the executable code that are in this block.  */
 
-  CORE_ADDR m_start;
-  CORE_ADDR m_end;
+  CORE_ADDR m_start = 0;
+  CORE_ADDR m_end = 0;
 
   /* The symbol that names this block, if the block is the body of a
      function (real or inlined); otherwise, zero.  */
 
-  struct symbol *m_function;
+  struct symbol *m_function = nullptr;
 
   /* The `struct block' for the containing block, or 0 if none.
 
@@ -287,22 +287,22 @@  struct block
      case of C) is the STATIC_BLOCK.  The superblock of the
      STATIC_BLOCK is the GLOBAL_BLOCK.  */
 
-  const struct block *m_superblock;
+  const struct block *m_superblock = nullptr;
 
   /* This is used to store the symbols in the block.  */
 
-  struct multidictionary *m_multidict;
+  struct multidictionary *m_multidict = nullptr;
 
   /* Contains information about namespace-related info relevant to this block:
      using directives and the current namespace scope.  */
 
-  struct block_namespace_info *m_namespace_info;
+  struct block_namespace_info *m_namespace_info = nullptr;
 
   /* Address ranges for blocks with non-contiguous ranges.  If this
      is NULL, then there is only one range which is specified by
      startaddr and endaddr above.  */
 
-  struct blockranges *m_ranges;
+  struct blockranges *m_ranges = nullptr;
 
 private:
 
@@ -314,7 +314,7 @@  struct block
 /* The global block is singled out so that we can provide a back-link
    to the compunit symtab.  */
 
-struct global_block
+struct global_block : public allocate_on_obstack
 {
   /* The block.  */
 
@@ -322,7 +322,7 @@  struct global_block
 
   /* This holds a pointer to the compunit symtab holding this block.  */
 
-  struct compunit_symtab *compunit_symtab;
+  struct compunit_symtab *compunit_symtab = nullptr;
 };
 
 struct blockvector