From patchwork Sat Apr 8 20:12:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 19911 Received: (qmail 18328 invoked by alias); 8 Apr 2017 20:12:21 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 18211 invoked by uid 89); 8 Apr 2017 20:12:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=4448, 4207 X-HELO: gproxy7-pub.mail.unifiedlayer.com Received: from gproxy7-pub.mail.unifiedlayer.com (HELO gproxy7-pub.mail.unifiedlayer.com) (70.40.196.235) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Sat, 08 Apr 2017 20:12:18 +0000 Received: (qmail 9003 invoked by uid 0); 8 Apr 2017 20:12:18 -0000 Received: from unknown (HELO CMOut01) (10.0.90.82) by gproxy7.mail.unifiedlayer.com with SMTP; 8 Apr 2017 20:12:18 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id 5wCF1v00E2f2jeq01wCJYA; Sat, 08 Apr 2017 14:12:18 -0600 X-Authority-Analysis: v=2.2 cv=cpDrqxwi c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=AzvcPWV-tVgA:10 a=zstS-IiYAAAA:8 a=9VdPqL1-xKZAv86zmW4A:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-65-226.hlrn.qwest.net ([75.166.65.226]:43578 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1cwwiU-0003Fw-Uz; Sat, 08 Apr 2017 14:12:15 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 09/14] Remove some cleanups from location.c Date: Sat, 8 Apr 2017 14:12:03 -0600 Message-Id: <20170408201208.2672-10-tom@tromey.com> In-Reply-To: <20170408201208.2672-1-tom@tromey.com> References: <20170408201208.2672-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1cwwiU-0003Fw-Uz X-Source-Sender: 75-166-65-226.hlrn.qwest.net (bapiya.Home) [75.166.65.226]:43578 X-Source-Auth: tom+tromey.com X-Email-Count: 10 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This removes some more cleanups from location.c by using unique_xmalloc_ptr. 2017-04-07 Tom Tromey * 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 + * location.c (explicit_location_lex_one): Return a + unique_xmalloc_ptr. + (string_to_explicit_location): Update. Remove cleanups. + +2017-04-07 Tom Tromey + * 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 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 (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 (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 (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 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 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