aboutsummaryrefslogtreecommitdiff
path: root/gdb/rust-lang.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-02-02 20:58:12 -0700
committerTom Tromey <tom@tromey.com>2017-02-02 21:25:11 -0700
commit03c85b11b07452f2d7341b405a7fe70c74226505 (patch)
tree3d87dc1f816b12136c8d84ad0bb23647330b7617 /gdb/rust-lang.c
parent73dceb99fa57b79e83a6ed80aaad49d0e3e7da66 (diff)
downloadgdb-03c85b11b07452f2d7341b405a7fe70c74226505.zip
gdb-03c85b11b07452f2d7341b405a7fe70c74226505.tar.gz
gdb-03c85b11b07452f2d7341b405a7fe70c74226505.tar.bz2
Use std::string in Rust code
This changes a couple of spots in the Rust support to use std::string. In one spot this removes some manual memory management; in the other spot this allows the removal of a call to xstrdup. 2017-02-02 Tom Tromey <tom@tromey.com> * rust-lang.h (rust_crate_for_block): Update. * rust-lang.c (rust_crate_for_block): Return std::string. (rust_get_disr_info): Use std:;string, not gdb::unique_xmalloc_ptr. * rust-exp.y (crate_name): Update.
Diffstat (limited to 'gdb/rust-lang.c')
-rw-r--r--gdb/rust-lang.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index dd72cd9..17df6bb 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -51,19 +51,17 @@ rust_last_path_segment (const char * path)
return result + 1;
}
-/* Find the Rust crate for BLOCK. If no crate can be found, returns
- NULL. Otherwise, returns a newly allocated string that the caller
- is responsible for freeing. */
+/* See rust-lang.h. */
-char *
+std::string
rust_crate_for_block (const struct block *block)
{
const char *scope = block_scope (block);
if (scope[0] == '\0')
- return NULL;
+ return std::string ();
- return xstrndup (scope, cp_find_first_component (scope));
+ return std::string (scope, cp_find_first_component (scope));
}
/* Information about the discriminant/variant of an enum */
@@ -157,8 +155,8 @@ rust_get_disr_info (struct type *type, const gdb_byte *valaddr,
/* Optimized enums have only one field. */
member_type = TYPE_FIELD_TYPE (type, 0);
- gdb::unique_xmalloc_ptr<char> name (xstrdup (TYPE_FIELD_NAME (type, 0)));
- tail = name.get () + strlen (RUST_ENUM_PREFIX);
+ std::string name (TYPE_FIELD_NAME (type, 0));
+ tail = &name[0] + strlen (RUST_ENUM_PREFIX);
/* The location of the value that doubles as a discriminant is
stored in the name of the field, as