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.
This commit is contained in:
parent
73dceb99fa
commit
03c85b11b0
4 changed files with 20 additions and 16 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
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.
|
||||||
|
|
||||||
2017-02-02 Pedro Alves <palves@redhat.com>
|
2017-02-02 Pedro Alves <palves@redhat.com>
|
||||||
|
|
||||||
* disasm-selftests.c (print_one_insn_test): Move the "verbose"
|
* disasm-selftests.c (print_one_insn_test): Move the "verbose"
|
||||||
|
|
|
@ -941,16 +941,15 @@ rust_concat3 (const char *s1, const char *s2, const char *s3)
|
||||||
static const struct rust_op *
|
static const struct rust_op *
|
||||||
crate_name (const struct rust_op *name)
|
crate_name (const struct rust_op *name)
|
||||||
{
|
{
|
||||||
char *crate = rust_crate_for_block (expression_context_block);
|
std::string crate = rust_crate_for_block (expression_context_block);
|
||||||
struct stoken result;
|
struct stoken result;
|
||||||
|
|
||||||
gdb_assert (name->opcode == OP_VAR_VALUE);
|
gdb_assert (name->opcode == OP_VAR_VALUE);
|
||||||
|
|
||||||
if (crate == NULL)
|
if (crate.empty ())
|
||||||
error (_("Could not find crate for current location"));
|
error (_("Could not find crate for current location"));
|
||||||
result = make_stoken (obconcat (&work_obstack, "::", crate, "::",
|
result = make_stoken (obconcat (&work_obstack, "::", crate.c_str (), "::",
|
||||||
name->left.sval.ptr, (char *) NULL));
|
name->left.sval.ptr, (char *) NULL));
|
||||||
xfree (crate);
|
|
||||||
|
|
||||||
return ast_path (result, name->right.params);
|
return ast_path (result, name->right.params);
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,19 +51,17 @@ rust_last_path_segment (const char * path)
|
||||||
return result + 1;
|
return result + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find the Rust crate for BLOCK. If no crate can be found, returns
|
/* See rust-lang.h. */
|
||||||
NULL. Otherwise, returns a newly allocated string that the caller
|
|
||||||
is responsible for freeing. */
|
|
||||||
|
|
||||||
char *
|
std::string
|
||||||
rust_crate_for_block (const struct block *block)
|
rust_crate_for_block (const struct block *block)
|
||||||
{
|
{
|
||||||
const char *scope = block_scope (block);
|
const char *scope = block_scope (block);
|
||||||
|
|
||||||
if (scope[0] == '\0')
|
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 */
|
/* 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. */
|
/* Optimized enums have only one field. */
|
||||||
member_type = TYPE_FIELD_TYPE (type, 0);
|
member_type = TYPE_FIELD_TYPE (type, 0);
|
||||||
|
|
||||||
gdb::unique_xmalloc_ptr<char> name (xstrdup (TYPE_FIELD_NAME (type, 0)));
|
std::string name (TYPE_FIELD_NAME (type, 0));
|
||||||
tail = name.get () + strlen (RUST_ENUM_PREFIX);
|
tail = &name[0] + strlen (RUST_ENUM_PREFIX);
|
||||||
|
|
||||||
/* The location of the value that doubles as a discriminant is
|
/* The location of the value that doubles as a discriminant is
|
||||||
stored in the name of the field, as
|
stored in the name of the field, as
|
||||||
|
|
|
@ -35,10 +35,9 @@ extern int rust_tuple_type_p (struct type *type);
|
||||||
/* Return true if TYPE is a tuple struct type; otherwise false. */
|
/* Return true if TYPE is a tuple struct type; otherwise false. */
|
||||||
extern int rust_tuple_struct_type_p (struct type *type);
|
extern int rust_tuple_struct_type_p (struct type *type);
|
||||||
|
|
||||||
/* Given a block, find the name of the block's crate. The name must
|
/* Given a block, find the name of the block's crate. Returns an empty
|
||||||
be freed by the caller. Returns NULL if no crate name can be
|
stringif no crate name can be found. */
|
||||||
found. */
|
extern std::string rust_crate_for_block (const struct block *block);
|
||||||
extern char *rust_crate_for_block (const struct block *block);
|
|
||||||
|
|
||||||
/* Create a new slice type. NAME is the name of the type. ELT_TYPE
|
/* Create a new slice type. NAME is the name of the type. ELT_TYPE
|
||||||
is the type of the elements of the slice. USIZE_TYPE is the Rust
|
is the type of the elements of the slice. USIZE_TYPE is the Rust
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue