[28/47] Turn allocate_value_contents into a method

Message ID 20230209-submit-value-fixups-2023-v1-28-55dc2794dbb9@tromey.com
State New
Headers
Series Use methods for struct value |

Commit Message

Tom Tromey Feb. 9, 2023, 9:38 p.m. UTC
  This turns the static function allocate_value_contents into a private
method on value.
---
 gdb/value.c | 21 ++++++++++-----------
 gdb/value.h |  6 ++++++
 2 files changed, 16 insertions(+), 11 deletions(-)
  

Patch

diff --git a/gdb/value.c b/gdb/value.c
index 57f57f38b26..77315a1a337 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -821,16 +821,15 @@  check_type_length_before_alloc (const struct type *type)
     }
 }
 
-/* Allocate the contents of VAL if it has not been allocated yet.  */
+/* See value.h.  */
 
-static void
-allocate_value_contents (struct value *val)
+void
+value::allocate_contents ()
 {
-  if (!val->m_contents)
+  if (!m_contents)
     {
-      check_type_length_before_alloc (val->m_enclosing_type);
-      val->m_contents.reset
-	((gdb_byte *) xzalloc (val->m_enclosing_type->length ()));
+      check_type_length_before_alloc (m_enclosing_type);
+      m_contents.reset ((gdb_byte *) xzalloc (m_enclosing_type->length ()));
     }
 }
 
@@ -839,7 +838,7 @@  value::allocate (struct type *type)
 {
   struct value *val = value::allocate_lazy (type);
 
-  allocate_value_contents (val);
+  val->allocate_contents ();
   val->m_lazy = 0;
   return val;
 }
@@ -896,7 +895,7 @@  value::contents_raw ()
   struct gdbarch *arch = get_arch ();
   int unit_size = gdbarch_addressable_memory_unit_size (arch);
 
-  allocate_value_contents (this);
+  this->allocate_contents ();
 
   ULONGEST length = type ()->length ();
   return gdb::make_array_view
@@ -906,7 +905,7 @@  value::contents_raw ()
 gdb::array_view<gdb_byte>
 value::contents_all_raw ()
 {
-  allocate_value_contents (this);
+  this->allocate_contents ();
 
   ULONGEST length = enclosing_type ()->length ();
   return gdb::make_array_view (m_contents.get (), length);
@@ -3785,7 +3784,7 @@  void
 value::fetch_lazy ()
 {
   gdb_assert (lazy ());
-  allocate_value_contents (this);
+  this->allocate_contents ();
   /* A value is either lazy, or fully fetched.  The
      availability/validity is only established as we try to fetch a
      value.  */
diff --git a/gdb/value.h b/gdb/value.h
index 23fffb18158..e3574b3a169 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -561,6 +561,12 @@  struct value
      treated pretty much the same, except not-saved registers have a
      different string representation and related error strings.  */
   std::vector<range> m_optimized_out;
+
+private:
+
+  /* Allocate the contents of this value if it has not been allocated
+     yet.  */
+  void allocate_contents ();
 };
 
 /* Returns value_type or value_enclosing_type depending on