From patchwork Tue Nov 29 05:05:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 18026 Received: (qmail 14930 invoked by alias); 29 Nov 2016 05:06:12 -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 14798 invoked by uid 89); 29 Nov 2016 05:06:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=xfree, TRY, from_tty, H*F:U*tom 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; Tue, 29 Nov 2016 05:06:01 +0000 Received: (qmail 27615 invoked by uid 0); 29 Nov 2016 05:05:59 -0000 Received: from unknown (HELO cmgw4) (10.0.90.85) by gproxy7.mail.unifiedlayer.com with SMTP; 29 Nov 2016 05:05:59 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw4 with id Dh5w1u00z2f2jeq01h5zcC; Mon, 28 Nov 2016 22:05:59 -0700 X-Authority-Analysis: v=2.1 cv=Zpp+dbLG c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=L24OOQBejmoA:10 a=zstS-IiYAAAA:8 a=vlaFufVZGtBZlUVKypQA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 71-218-195-233.hlrn.qwest.net ([71.218.195.233]:46172 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1cBac8-0000aB-Pa; Mon, 28 Nov 2016 22:05:56 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 7/8] Use unique_xmalloc_ptr in execute_gdb_command Date: Mon, 28 Nov 2016 22:05:45 -0700 Message-Id: <1480395946-10924-8-git-send-email-tom@tromey.com> In-Reply-To: <1480395946-10924-1-git-send-email-tom@tromey.com> References: <1480395946-10924-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1cBac8-0000aB-Pa X-Source-Sender: 71-218-195-233.hlrn.qwest.net (bapiya.Home) [71.218.195.233]:46172 X-Source-Auth: tom+tromey.com X-Email-Count: 8 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This replaces a cleanup in execute_gdb_command with an instance of unique_xmalloc_ptr. std::string was not used because execute_command and execute_command_to_string don't accept a "const char *" (in fact the reason for copying the string at all). 2016-11-28 Tom Tromey * python/python.c (execute_gdb_command): Use unique_xmalloc_ptr. --- gdb/ChangeLog | 4 ++++ gdb/python/python.c | 8 +++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index cf61306..d0d2ef6 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,9 @@ 2016-11-28 Tom Tromey + * python/python.c (execute_gdb_command): Use unique_xmalloc_ptr. + +2016-11-28 Tom Tromey + * value.h (value_freer::~value_freer): Call release. (value_freer::release): New method. * dwarf2loc.c (dwarf2_evaluate_loc_desc_full): Use value_freer. diff --git a/gdb/python/python.c b/gdb/python/python.c index 83b9805..83894a1 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -601,8 +601,7 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) TRY { /* Copy the argument text in case the command modifies it. */ - char *copy = xstrdup (arg); - struct cleanup *cleanup = make_cleanup (xfree, copy); + gdb::unique_xmalloc_ptr copy (xstrdup (arg)); struct interp *interp; scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0); @@ -616,10 +615,9 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) prevent_dont_repeat (); if (to_string) - to_string_res = execute_command_to_string (copy, from_tty); + to_string_res = execute_command_to_string (copy.get (), from_tty); else - execute_command (copy, from_tty); - do_cleanups (cleanup); + execute_command (copy.get (), from_tty); } CATCH (except, RETURN_MASK_ALL) {