From patchwork Thu Sep 19 21:28:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 34604 Received: (qmail 68993 invoked by alias); 19 Sep 2019 21:28:31 -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 68985 invoked by uid 89); 19 Sep 2019 21:28:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=HX-Languages-Length:1590 X-HELO: gateway21.websitewelcome.com Received: from gateway21.websitewelcome.com (HELO gateway21.websitewelcome.com) (192.185.46.113) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 19 Sep 2019 21:28:29 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway21.websitewelcome.com (Postfix) with ESMTP id 63E6D400DA113 for ; Thu, 19 Sep 2019 16:28:28 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id B3yWigHmw2qH7B3yWiYmKq; Thu, 19 Sep 2019 16:28:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=EdImDkVroE8oUBx+536i/Y56X72zU3JIqRH0WUpNcfY=; b=dzc1Tx2FWiHyBw0GKR9y33lrlC TaxzkxOqa47Qy/o/xe9CbwWlNu8EMVT9YHK71iyx/BJoor/swkv+D8Zdt4o1W9T+qPHQOtUzFEcxY BrJECCosx8M54oTiAx1IcbCiw; Received: from 71-218-73-27.hlrn.qwest.net ([71.218.73.27]:35244 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1iB3yW-001n6D-2u; Thu, 19 Sep 2019 16:28:28 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/4] Use foreach in gdbpy_inferiors Date: Thu, 19 Sep 2019 15:28:22 -0600 Message-Id: <20190919212825.7586-2-tom@tromey.com> In-Reply-To: <20190919212825.7586-1-tom@tromey.com> References: <20190919212825.7586-1-tom@tromey.com> This changes gdbpy_inferiors to use foreach rather than a callback function. gdb/ChangeLog 2019-09-19 Tom Tromey * python/py-inferior.c (build_inferior_list): Remove. (gdbpy_inferiors): Use foreach. --- gdb/ChangeLog | 5 +++++ gdb/python/py-inferior.c | 24 ++++++++++-------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 28882221a90..ecb95444a36 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -462,18 +462,6 @@ infpy_get_progspace (PyObject *self, void *closure) return pspace_to_pspace_object (pspace).release (); } -static int -build_inferior_list (struct inferior *inf, void *arg) -{ - PyObject *list = (PyObject *) arg; - gdbpy_ref inferior = inferior_to_inferior_object (inf); - - if (inferior == NULL) - return 0; - - return PyList_Append (list, (PyObject *) inferior.get ()) ? 1 : 0; -} - /* Implementation of gdb.inferiors () -> (gdb.Inferior, ...). Returns a tuple of all inferiors. */ PyObject * @@ -483,8 +471,16 @@ gdbpy_inferiors (PyObject *unused, PyObject *unused2) if (list == NULL) return NULL; - if (iterate_over_inferiors (build_inferior_list, list.get ())) - return NULL; + for (inferior *inf : all_inferiors_safe ()) + { + gdbpy_ref inferior = inferior_to_inferior_object (inf); + + if (inferior == NULL) + continue; + + if (PyList_Append (list.get (), (PyObject *) inferior.get ()) == -1) + return NULL; + } return PyList_AsTuple (list.get ()); }