From patchwork Wed May 3 22:46: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: 20263 Received: (qmail 54160 invoked by alias); 3 May 2017 22:46:56 -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 52573 invoked by uid 89); 3 May 2017 22:46:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gproxy4.mail.unifiedlayer.com Received: from gproxy4-pub.mail.unifiedlayer.com (HELO gproxy4.mail.unifiedlayer.com) (69.89.23.142) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 03 May 2017 22:46:40 +0000 Received: from cmgw2 (unknown [10.0.90.83]) by gproxy4.mail.unifiedlayer.com (Postfix) with ESMTP id 80A09175C79 for ; Wed, 3 May 2017 16:46:41 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id Fyme1v00L2f2jeq01ymhCu; Wed, 03 May 2017 16:46:41 -0600 X-Authority-Analysis: v=2.2 cv=Ibz3YSia c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=tJ8p9aeEuA8A:10 a=zstS-IiYAAAA:8 a=NSQXzcjjCJWURcBAK0EA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-63-71.hlrn.qwest.net ([75.166.63.71]:53090 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1d632c-00051x-7M; Wed, 03 May 2017 16:46:38 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 23/23] Use gdb_argv_up in Python Date: Wed, 3 May 2017 16:46:26 -0600 Message-Id: <20170503224626.2818-24-tom@tromey.com> In-Reply-To: <20170503224626.2818-1-tom@tromey.com> References: <20170503224626.2818-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1d632c-00051x-7M X-Source-Sender: 75-166-63-71.hlrn.qwest.net (bapiya.Home) [75.166.63.71]:53090 X-Source-Auth: tom+tromey.com X-Email-Count: 30 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This changes one spot in the Python code to use gdb_argv_up. This removes the last cleanup from the Python layer. 2017-05-02 Tom Tromey * python/py-param.c (compute_enum_values): Use gdb_argv_up. --- gdb/ChangeLog | 4 ++++ gdb/python/py-param.c | 21 +++++---------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4dc3bb4..12b9755 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,9 @@ 2017-05-02 Tom Tromey + * python/py-param.c (compute_enum_values): Use gdb_argv_up. + +2017-05-02 Tom Tromey + * utils.h (struct gdb_argv_deleter): New. (gdb_argv_up): New typedef. (gdb_buildargv): Change return type. diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c index f0d3423..0afed32 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,26 @@ 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_up enumeration (XCNEWVEC (char *, size + 1)); 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 (); + 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]); + return 0; } - discard_cleanups (back_to); + self->enumeration = const_cast (enumeration.release ()); return 1; }