diff options
author | Tom Tromey <tom@tromey.com> | 2018-02-15 22:41:03 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-02-21 09:09:45 -0700 |
commit | 3eac2b654808f9e233885f910045eea9d2ca0aa0 (patch) | |
tree | 22d3276e46df79ab5506979101b94ee6ecdfb12e /gdb/completer.c | |
parent | 6ccb583f751e020a6db768d517c2dd3ba6d93cc4 (diff) | |
download | gdb-3eac2b654808f9e233885f910045eea9d2ca0aa0.zip gdb-3eac2b654808f9e233885f910045eea9d2ca0aa0.tar.gz gdb-3eac2b654808f9e233885f910045eea9d2ca0aa0.tar.bz2 |
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*.
Diffstat (limited to 'gdb/completer.c')
-rw-r--r-- | gdb/completer.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/gdb/completer.c b/gdb/completer.c index a71bd36..4de1bcf 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -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); } |