[v2,28/48] Turn allocate_value_contents into a method

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

Commit Message

Tom Tromey Feb. 10, 2023, 9:52 p.m. UTC
  This turns the static function allocate_value_contents into a private
method on value.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
---
 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 99ea97d3b35..fcc5481c20a 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;
 }
@@ -895,7 +894,7 @@  value::contents_raw ()
 {
   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
@@ -905,7 +904,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);
@@ -3784,7 +3783,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 d16b2d0d864..46d3a49c669 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -559,6 +559,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