From patchwork Wed Aug 2 15:02:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 21852 Received: (qmail 26177 invoked by alias); 2 Aug 2017 15:02:53 -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 26080 invoked by uid 89); 2 Aug 2017 15:02:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.5 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=6596, appease, 6526 X-HELO: gproxy9-pub.mail.unifiedlayer.com Received: from gproxy9-pub.mail.unifiedlayer.com (HELO gproxy9-pub.mail.unifiedlayer.com) (69.89.20.122) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 02 Aug 2017 15:02:45 +0000 Received: from cmgw3 (unknown [10.0.90.84]) by gproxy9.mail.unifiedlayer.com (Postfix) with ESMTP id 530471E0A37 for ; Wed, 2 Aug 2017 09:02:44 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id sF2h1v00U2f2jeq01F2kX1; Wed, 02 Aug 2017 09:02:44 -0600 X-Authority-Analysis: v=2.2 cv=epiv9shX c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=KeKAF7QvOSUA:10 a=zstS-IiYAAAA:8 a=9pL6KgRF_zsiHANDrScA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 174-29-39-24.hlrn.qwest.net ([174.29.39.24]:54692 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dcvAX-002dpC-67; Wed, 02 Aug 2017 09:02:41 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v3 20/23] Remove a cleanup in Python Date: Wed, 2 Aug 2017 09:02:24 -0600 Message-Id: <20170802150227.24460-21-tom@tromey.com> In-Reply-To: <20170802150227.24460-1-tom@tromey.com> References: <20170802150227.24460-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dcvAX-002dpC-67 X-Source-Sender: 174-29-39-24.hlrn.qwest.net (bapiya.Home) [174.29.39.24]:54692 X-Source-Auth: tom+tromey.com X-Email-Count: 21 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This removes cleanups from gdbpy_decode_line, in favor of a use of unique_xmalloc_ptr. ChangeLog 2017-08-02 Tom Tromey * python/python.c (gdbpy_decode_line): Use unique_xmalloc_ptr. --- gdb/ChangeLog | 4 ++++ gdb/python/python.c | 30 +++++++----------------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9c4c05a..72d896e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,9 @@ 2017-08-02 Tom Tromey + * python/python.c (gdbpy_decode_line): Use unique_xmalloc_ptr. + +2017-08-02 Tom Tromey + * python/python.c (compute_python_string): Return std::string. (gdbpy_eval_from_control_command): Update. (do_start_initialization): Use std::string. diff --git a/gdb/python/python.c b/gdb/python/python.c index 67f134d..c53e10f 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -652,7 +652,6 @@ gdbpy_decode_line (PyObject *self, PyObject *args) appease gcc. */ struct symtab_and_line sal; char *arg = NULL; - struct cleanup *cleanups; gdbpy_ref<> result; gdbpy_ref<> unparsed; event_location_up location; @@ -660,8 +659,6 @@ gdbpy_decode_line (PyObject *self, PyObject *args) if (! PyArg_ParseTuple (args, "|s", &arg)) return NULL; - cleanups = make_cleanup (null_cleanup, NULL); - sals.sals = NULL; if (arg != NULL) @@ -685,12 +682,13 @@ gdbpy_decode_line (PyObject *self, PyObject *args) } END_CATCH + /* Ensure that the sals data is freed, when needed. */ + gdb::unique_xmalloc_ptr free_sals; if (sals.sals != NULL && sals.sals != &sal) - make_cleanup (xfree, sals.sals); + free_sals.reset (sals.sals); if (except.reason < 0) { - do_cleanups (cleanups); /* We know this will always throw. */ gdbpy_convert_exception (except); return NULL; @@ -702,20 +700,14 @@ gdbpy_decode_line (PyObject *self, PyObject *args) result.reset (PyTuple_New (sals.nelts)); if (result == NULL) - { - do_cleanups (cleanups); - return NULL; - } + return NULL; for (i = 0; i < sals.nelts; ++i) { PyObject *obj; obj = symtab_and_line_to_sal_object (sals.sals[i]); if (! obj) - { - do_cleanups (cleanups); - return NULL; - } + return NULL; PyTuple_SetItem (result.get (), i, obj); } @@ -728,19 +720,13 @@ gdbpy_decode_line (PyObject *self, PyObject *args) gdbpy_ref<> return_result (PyTuple_New (2)); if (return_result == NULL) - { - do_cleanups (cleanups); - return NULL; - } + return NULL; if (arg != NULL && strlen (arg) > 0) { unparsed.reset (PyString_FromString (arg)); if (unparsed == NULL) - { - do_cleanups (cleanups); - return NULL; - } + return NULL; } else { @@ -751,8 +737,6 @@ gdbpy_decode_line (PyObject *self, PyObject *args) PyTuple_SetItem (return_result.get (), 0, unparsed.release ()); PyTuple_SetItem (return_result.get (), 1, result.release ()); - do_cleanups (cleanups); - return return_result.release (); }