From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 09/14] Remove some cleanups from location.c
Date: Sat, 08 Apr 2017 20:12:00 -0000 [thread overview]
Message-ID: <20170408201208.2672-10-tom@tromey.com> (raw)
In-Reply-To: <20170408201208.2672-1-tom@tromey.com>
This removes some more cleanups from location.c by using
unique_xmalloc_ptr.
2017-04-07 Tom Tromey <tom@tromey.com>
* location.c (explicit_location_lex_one): Return a
unique_xmalloc_ptr.
(string_to_explicit_location): Update. Remove cleanups.
---
gdb/ChangeLog | 6 ++++++
gdb/location.c | 64 ++++++++++++++++++++++++----------------------------------
2 files changed, 32 insertions(+), 38 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 50869d7..f330664 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
2017-04-07 Tom Tromey <tom@tromey.com>
+ * location.c (explicit_location_lex_one): Return a
+ unique_xmalloc_ptr.
+ (string_to_explicit_location): Update. Remove cleanups.
+
+2017-04-07 Tom Tromey <tom@tromey.com>
+
* gnu-v3-abi.c (value_and_voffset_p): Remove typedef.
(compare_value_and_voffset): Change type. Update.
(compute_vtable_size): Change type of "offset_vec".
diff --git a/gdb/location.c b/gdb/location.c
index 877c1ed..8aa8bd5 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -420,7 +420,7 @@ event_location_to_string (struct event_location *location)
past any strings that it lexes. Returns a malloc'd copy of the
lexed string or NULL if no lexing was done. */
-static char *
+static gdb::unique_xmalloc_ptr<char>
explicit_location_lex_one (const char **inp,
const struct language_defn *language)
{
@@ -444,7 +444,8 @@ explicit_location_lex_one (const char **inp,
if (end == NULL)
error (_("Unmatched quote, %s."), start);
*inp = end + 1;
- return savestring (start + 1, *inp - start - 2);
+ return gdb::unique_xmalloc_ptr<char> (savestring (start + 1,
+ *inp - start - 2));
}
}
@@ -461,7 +462,8 @@ explicit_location_lex_one (const char **inp,
while (isdigit (*inp[0]))
++(*inp);
if (*inp[0] == '\0' || isspace (*inp[0]) || *inp[0] == ',')
- return savestring (start, *inp - start);
+ return gdb::unique_xmalloc_ptr<char> (savestring (start,
+ *inp - start));
/* Otherwise stop at the next occurrence of whitespace, '\0',
keyword, or ','. */
@@ -480,7 +482,7 @@ explicit_location_lex_one (const char **inp,
}
if (*inp - start > 0)
- return savestring (start, *inp - start);
+ return gdb::unique_xmalloc_ptr<char> (savestring (start, *inp - start));
return NULL;
}
@@ -511,9 +513,7 @@ string_to_explicit_location (const char **argp,
while ((*argp)[0] != '\0' && (*argp)[0] != ',')
{
int len;
- char *opt, *oarg;
const char *start;
- struct cleanup *opt_cleanup, *oarg_cleanup;
/* If *ARGP starts with a keyword, stop processing
options. */
@@ -524,44 +524,40 @@ string_to_explicit_location (const char **argp,
start = *argp;
/* Get the option string. */
- opt = explicit_location_lex_one (argp, language);
- opt_cleanup = make_cleanup (xfree, opt);
+ gdb::unique_xmalloc_ptr<char> opt
+ = explicit_location_lex_one (argp, language);
*argp = skip_spaces_const (*argp);
/* Get the argument string. */
- oarg = explicit_location_lex_one (argp, language);
- oarg_cleanup = make_cleanup (xfree, oarg);
+ gdb::unique_xmalloc_ptr<char> oarg
+ = explicit_location_lex_one (argp, language);
+ bool have_oarg = oarg != NULL;
*argp = skip_spaces_const (*argp);
/* Use the length of the option to allow abbreviations. */
- len = strlen (opt);
+ len = strlen (opt.get ());
/* All options have a required argument. Checking for this required
argument is deferred until later. */
- if (strncmp (opt, "-source", len) == 0)
- EL_EXPLICIT (location)->source_filename = oarg;
- else if (strncmp (opt, "-function", len) == 0)
- EL_EXPLICIT (location)->function_name = oarg;
- else if (strncmp (opt, "-line", len) == 0)
+ if (strncmp (opt.get (), "-source", len) == 0)
+ EL_EXPLICIT (location)->source_filename = oarg.release ();
+ else if (strncmp (opt.get (), "-function", len) == 0)
+ EL_EXPLICIT (location)->function_name = oarg.release ();
+ else if (strncmp (opt.get (), "-line", len) == 0)
{
- if (oarg != NULL)
- {
- EL_EXPLICIT (location)->line_offset
- = linespec_parse_line_offset (oarg);
- do_cleanups (oarg_cleanup);
- do_cleanups (opt_cleanup);
- continue;
- }
+ if (have_oarg)
+ EL_EXPLICIT (location)->line_offset
+ = linespec_parse_line_offset (oarg.get ());
}
- else if (strncmp (opt, "-label", len) == 0)
- EL_EXPLICIT (location)->label_name = oarg;
+ else if (strncmp (opt.get (), "-label", len) == 0)
+ EL_EXPLICIT (location)->label_name = oarg.release ();
/* Only emit an "invalid argument" error for options
that look like option strings. */
- else if (opt[0] == '-' && !isdigit (opt[1]))
+ else if (opt.get ()[0] == '-' && !isdigit (opt.get ()[1]))
{
if (!dont_throw)
- error (_("invalid explicit location argument, \"%s\""), opt);
+ error (_("invalid explicit location argument, \"%s\""), opt.get ());
}
else
{
@@ -569,8 +565,6 @@ string_to_explicit_location (const char **argp,
Stop parsing and return whatever explicit location was
parsed. */
*argp = start;
- discard_cleanups (oarg_cleanup);
- do_cleanups (opt_cleanup);
return location;
}
@@ -578,14 +572,8 @@ string_to_explicit_location (const char **argp,
case, it provides a much better user experience to issue
the "invalid argument" error before any missing
argument error. */
- if (oarg == NULL && !dont_throw)
- error (_("missing argument for \"%s\""), opt);
-
- /* The option/argument pair was successfully processed;
- oarg belongs to the explicit location, and opt should
- be freed. */
- discard_cleanups (oarg_cleanup);
- do_cleanups (opt_cleanup);
+ if (!have_oarg && !dont_throw)
+ error (_("missing argument for \"%s\""), opt.get ());
}
/* One special error check: If a source filename was given
--
2.9.3
next prev parent reply other threads:[~2017-04-08 20:12 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-08 20:12 [RFA 00/14] miscellaneous C++-ificiation Tom Tromey
2017-04-08 20:12 ` [RFA 03/14] Change find_pcs_for_symtab_line to return a std::vector Tom Tromey
2017-04-10 2:49 ` Simon Marchi
2017-04-08 20:12 ` [RFA 10/14] C++ify mi_parse Tom Tromey
2017-04-11 1:12 ` Simon Marchi
2017-04-08 20:12 ` Tom Tromey [this message]
2017-04-10 4:43 ` [RFA 09/14] Remove some cleanups from location.c Simon Marchi
2017-04-08 20:12 ` [RFA 14/14] Use std::vector in compile-loc2c.c Tom Tromey
2017-04-08 20:12 ` [RFA 02/14] Introduce command_line_up Tom Tromey
2017-04-10 2:36 ` Simon Marchi
2017-04-10 23:21 ` Tom Tromey
2017-04-08 20:12 ` [RFA 01/14] Introduce event_location_up Tom Tromey
2017-04-10 1:33 ` Simon Marchi
2017-04-10 23:19 ` Tom Tromey
2017-04-08 20:12 ` [RFA 06/14] Remove cleanup_iconv Tom Tromey
2017-04-10 3:56 ` Simon Marchi
2017-04-10 23:20 ` Tom Tromey
2017-04-08 20:12 ` [RFA 11/14] Use scoped_restore in more places Tom Tromey
2017-04-11 1:48 ` Simon Marchi
2017-04-08 20:12 ` [RFA 08/14] Remove some cleanups from gnu-v3-abi.c Tom Tromey
2017-04-10 4:09 ` Simon Marchi
2017-04-10 13:57 ` Tom Tromey
2017-04-08 20:13 ` [RFA 04/14] Introduce gdb_dlopen_up Tom Tromey
2017-04-10 3:13 ` Simon Marchi
2017-04-10 9:26 ` Pedro Alves
2017-04-10 23:31 ` Tom Tromey
2017-04-08 20:13 ` [RFA 12/14] Use std::vector in reread_symbols Tom Tromey
2017-04-11 1:59 ` Simon Marchi
2017-04-08 20:13 ` [RFA 13/14] Use std::vector in find_instruction_backward Tom Tromey
2017-04-08 20:22 ` [RFA 07/14] Fix up wchar_iterator comment Tom Tromey
2017-04-10 4:05 ` Simon Marchi
2017-04-10 23:29 ` Tom Tromey
2017-04-08 20:23 ` [RFA 05/14] Change increment_reading_symtab to return a scoped_restore Tom Tromey
2017-04-10 3:27 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170408201208.2672-10-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox