From patchwork Wed Aug 2 15:02:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 21862 Received: (qmail 35736 invoked by alias); 2 Aug 2017 15:03:33 -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 35590 invoked by uid 89); 2 Aug 2017 15:03:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.6 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= X-HELO: gproxy5-pub.mail.unifiedlayer.com Received: from gproxy5-pub.mail.unifiedlayer.com (HELO gproxy5-pub.mail.unifiedlayer.com) (67.222.38.55) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 02 Aug 2017 15:03:30 +0000 Received: from cmgw3 (unknown [10.0.90.84]) by gproxy5.mail.unifiedlayer.com (Postfix) with ESMTP id 31EA5140DCD for ; Wed, 2 Aug 2017 09:02:46 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id sF2i1v02a2f2jeq01F2lb2; Wed, 02 Aug 2017 09:02:45 -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=6dvVH2yvaC8BwGTLQeAA: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 1dcvAY-002dpC-LO; Wed, 02 Aug 2017 09:02:42 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v3 22/23] Use gdb_argv in Python Date: Wed, 2 Aug 2017 09:02:26 -0600 Message-Id: <20170802150227.24460-23-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: 1dcvAY-002dpC-LO 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: 23 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This changes one spot in the Python code to use gdb_argv. This removes the last cleanup from the Python layer. ChangeLog 2017-08-02 Tom Tromey * python/py-param.c (compute_enum_values): Use gdb_argv. --- gdb/ChangeLog | 4 ++++ gdb/python/py-param.c | 24 +++++++----------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index ccce44c..259c37c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,9 @@ 2017-08-02 Tom Tromey + * python/py-param.c (compute_enum_values): Use gdb_argv. + +2017-08-02 Tom Tromey + * utils.h (struct gdb_argv_deleter): New. (gdb_argv): New class. * utils.c (gdb_argv::reset): New method. diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c index f0d3423..455c99e 100644 --- a/gdb/python/py-param.c +++ b/gdb/python/py-param.c @@ -555,7 +555,6 @@ static int compute_enum_values (parmpy_object *self, PyObject *enum_values) { Py_ssize_t size, i; - struct cleanup *back_to; if (! enum_values) { @@ -581,36 +580,27 @@ compute_enum_values (parmpy_object *self, PyObject *enum_values) return 0; } - self->enumeration = XCNEWVEC (const char *, size + 1); - back_to = make_cleanup (free_current_contents, &self->enumeration); + gdb_argv holder (XCNEWVEC (char *, size + 1)); + char **enumeration = holder.get (); for (i = 0; i < size; ++i) { gdbpy_ref<> item (PySequence_GetItem (enum_values, i)); if (item == NULL) - { - do_cleanups (back_to); - return 0; - } + return 0; if (! gdbpy_is_string (item.get ())) { - do_cleanups (back_to); PyErr_SetString (PyExc_RuntimeError, _("The enumeration item not a string.")); return 0; } - self->enumeration[i] - = python_string_to_host_string (item.get ()).release (); - if (self->enumeration[i] == NULL) - { - do_cleanups (back_to); - return 0; - } - make_cleanup (xfree, (char *) self->enumeration[i]); + enumeration[i] = python_string_to_host_string (item.get ()).release (); + if (enumeration[i] == NULL) + return 0; } - discard_cleanups (back_to); + self->enumeration = const_cast (holder.release ()); return 1; }