From patchwork Fri Feb 9 12:55:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 25883 Received: (qmail 42035 invoked by alias); 9 Feb 2018 12:56:00 -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 41017 invoked by uid 89); 9 Feb 2018 12:55:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2576 X-HELO: gateway33.websitewelcome.com Received: from gateway33.websitewelcome.com (HELO gateway33.websitewelcome.com) (192.185.145.216) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Feb 2018 12:55:57 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 1B21E1605EC for ; Fri, 9 Feb 2018 06:55:56 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id k8Dcef2o9vkfxk8Dce7j6T; Fri, 09 Feb 2018 06:55:56 -0600 Received: from 174-29-33-254.hlrn.qwest.net ([174.29.33.254]:36716 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1ek8Db-000nMH-Qu; Fri, 09 Feb 2018 06:55:55 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 1/2] Use std::string in execute_script_contents Date: Fri, 9 Feb 2018 05:55:52 -0700 Message-Id: <20180209125553.7392-2-tom@tromey.com> In-Reply-To: <20180209125553.7392-1-tom@tromey.com> References: <20180209125553.7392-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1ek8Db-000nMH-Qu X-Source-Sender: 174-29-33-254.hlrn.qwest.net (pokyo.Home) [174.29.33.254]:36716 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This changes execute_script_contents to use a std::string, allowing the removal of a cleanup. 2018-02-09 Tom Tromey * auto-load.c (execute_script_contents): Use std::string. --- gdb/ChangeLog | 4 ++++ gdb/auto-load.c | 17 +++++------------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 3e5b324472..adc3d19d3b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2018-02-09 Tom Tromey + + * auto-load.c (execute_script_contents): Use std::string. + 2018-02-09 Joel Brobecker * NEWS : Clarify that "rbreak" is a new diff --git a/gdb/auto-load.c b/gdb/auto-load.c index 30c8b89e8e..1f3d366a56 100644 --- a/gdb/auto-load.c +++ b/gdb/auto-load.c @@ -989,23 +989,21 @@ execute_script_contents (struct auto_load_pspace_info *pspace_info, { objfile_script_executor_func *executor; const char *newline, *script_text; - char *name; + const char *name; int is_safe, in_hash_table; - struct cleanup *cleanups; - - cleanups = make_cleanup (null_cleanup, NULL); /* The first line of the script is the name of the script. It must not contain any kind of space character. */ name = NULL; newline = strchr (script, '\n'); + std::string name_holder; if (newline != NULL) { - char *buf, *p; + const char *buf, *p; /* Put the name in a buffer and validate it. */ - buf = xstrndup (script, newline - script); - make_cleanup (xfree, buf); + name_holder = std::string (script, newline - script); + buf = name_holder.c_str (); for (p = buf; *p != '\0'; ++p) { if (isspace (*p)) @@ -1022,7 +1020,6 @@ execute_script_contents (struct auto_load_pspace_info *pspace_info, Missing/bad script name in entry at offset %u in section %s\n\ of file %s."), offset, section_name, objfile_name (objfile)); - do_cleanups (cleanups); return; } script_text = newline + 1; @@ -1035,7 +1032,6 @@ of file %s."), maybe_print_unsupported_script_warning (pspace_info, objfile, language, section_name, offset); maybe_add_script_text (pspace_info, 0, name, language); - do_cleanups (cleanups); return; } @@ -1043,7 +1039,6 @@ of file %s."), if (!ext_lang_auto_load_enabled (language)) { /* No message is printed, just skip it. */ - do_cleanups (cleanups); return; } @@ -1059,8 +1054,6 @@ of file %s."), /* If this file is not currently loaded, load it. */ if (is_safe && !in_hash_table) executor (language, objfile, name, script_text); - - do_cleanups (cleanups); } /* Load scripts specified in OBJFILE.