[v3,1/7] Use gdb::array_view for value_array

Message ID 20230829-cleanup-array-op-v3-1-0d0256c6a6ed@adacore.com
State New
Headers
Series Small cleanups in array_operation::evaluate |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 fail Patch failed to apply

Commit Message

Tom Tromey Aug. 29, 2023, 6:10 p.m. UTC
  This changes value_array to accept an array view.  I also replaced an
alloca with a std::vector in array_operation::evaluate.  This function
can work on any size of array, so it seems bad to use alloca.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
---
 gdb/eval.c      | 2 +-
 gdb/rust-lang.c | 2 +-
 gdb/valops.c    | 3 ++-
 gdb/value.h     | 2 +-
 4 files changed, 5 insertions(+), 4 deletions(-)
  

Patch

diff --git a/gdb/eval.c b/gdb/eval.c
index 457a6697923..00b9231a5b9 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -2515,7 +2515,7 @@  array_operation::evaluate (struct type *expect_type,
       return set;
     }
 
-  value **argvec = XALLOCAVEC (struct value *, nargs);
+  std::vector<value *> argvec (nargs);
   for (tem = 0; tem < nargs; tem++)
     {
       /* Ensure that array expressions are coerced into pointer
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 5eb33d0d3b7..f6e7d25f587 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1344,7 +1344,7 @@  eval_op_rust_array (struct type *expect_type, struct expression *exp,
 
       for (i = 0; i < copies; ++i)
 	eltvec[i] = elt;
-      return value_array (0, copies - 1, eltvec.data ());
+      return value_array (0, copies - 1, eltvec);
     }
   else
     {
diff --git a/gdb/valops.c b/gdb/valops.c
index ea9d9b38e74..1133049c54a 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1692,7 +1692,8 @@  value_ind (struct value *arg1)
    don't currently enforce any restriction on their types).  */
 
 struct value *
-value_array (int lowbound, int highbound, struct value **elemvec)
+value_array (int lowbound, int highbound,
+	     gdb::array_view<struct value *> elemvec)
 {
   int nelem;
   int idx;
diff --git a/gdb/value.h b/gdb/value.h
index e5c63dccbe2..ccf52199146 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1226,7 +1226,7 @@  inline struct value *value_string (const char *ptr, ssize_t count,
 }
 
 extern struct value *value_array (int lowbound, int highbound,
-				  struct value **elemvec);
+				  gdb::array_view<struct value *> elemvec);
 
 extern struct value *value_concat (struct value *arg1, struct value *arg2);