mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-08-06 06:45:56 +08:00
Remove a cleanup from parse_expression_for_completion
This removes a cleanup from parse_expression_for_completion, by changing various expression-completion functions to use gdb::unique_xmalloc_ptry rather than explicit malloc+free. Regression tested by the buildbot. gdb/ChangeLog 2018-02-21 Tom Tromey <tom@tromey.com> * value.h: (extract_field_op): Update. * eval.c (extract_field_op): Return a const char *. * expression.h (parse_expression_for_completion): Update. * completer.c (complete_expression): Update. (add_struct_fields): Make fieldname const. * parse.c (expout_completion_name): Now a unique_xmalloc_ptr. (mark_completion_tag, parse_exp_in_context_1): Update. (parse_expression_for_completion): Change "name" to unique_xmalloc_ptr*.
This commit is contained in:
@ -962,7 +962,7 @@ location_completer_handle_brkchars (struct cmd_list_element *ignore,
|
||||
|
||||
static void
|
||||
add_struct_fields (struct type *type, completion_list &output,
|
||||
char *fieldname, int namelen)
|
||||
const char *fieldname, int namelen)
|
||||
{
|
||||
int i;
|
||||
int computed_type_name = 0;
|
||||
@ -1016,12 +1016,11 @@ complete_expression (completion_tracker &tracker,
|
||||
const char *text, const char *word)
|
||||
{
|
||||
struct type *type = NULL;
|
||||
char *fieldname;
|
||||
gdb::unique_xmalloc_ptr<char> fieldname;
|
||||
enum type_code code = TYPE_CODE_UNDEF;
|
||||
|
||||
/* Perform a tentative parse of the expression, to see whether a
|
||||
field completion is required. */
|
||||
fieldname = NULL;
|
||||
TRY
|
||||
{
|
||||
type = parse_expression_for_completion (text, &fieldname, &code);
|
||||
@ -1032,7 +1031,7 @@ complete_expression (completion_tracker &tracker,
|
||||
}
|
||||
END_CATCH
|
||||
|
||||
if (fieldname && type)
|
||||
if (fieldname != nullptr && type)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
@ -1045,25 +1044,20 @@ complete_expression (completion_tracker &tracker,
|
||||
if (TYPE_CODE (type) == TYPE_CODE_UNION
|
||||
|| TYPE_CODE (type) == TYPE_CODE_STRUCT)
|
||||
{
|
||||
int flen = strlen (fieldname);
|
||||
completion_list result;
|
||||
|
||||
add_struct_fields (type, result, fieldname, flen);
|
||||
xfree (fieldname);
|
||||
add_struct_fields (type, result, fieldname.get (),
|
||||
strlen (fieldname.get ()));
|
||||
tracker.add_completions (std::move (result));
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (fieldname && code != TYPE_CODE_UNDEF)
|
||||
else if (fieldname != nullptr && code != TYPE_CODE_UNDEF)
|
||||
{
|
||||
struct cleanup *cleanup = make_cleanup (xfree, fieldname);
|
||||
|
||||
collect_symbol_completion_matches_type (tracker, fieldname, fieldname,
|
||||
code);
|
||||
do_cleanups (cleanup);
|
||||
collect_symbol_completion_matches_type (tracker, fieldname.get (),
|
||||
fieldname.get (), code);
|
||||
return;
|
||||
}
|
||||
xfree (fieldname);
|
||||
|
||||
complete_files_symbols (tracker, text, word);
|
||||
}
|
||||
|
Reference in New Issue
Block a user