From patchwork Sun Oct 28 18:13:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 29933 Received: (qmail 92882 invoked by alias); 28 Oct 2018 18:13:46 -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 92829 invoked by uid 89); 28 Oct 2018 18:13:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.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_HELO_PASS autolearn=ham version=3.3.2 spammy=UD:pc X-HELO: gateway32.websitewelcome.com Received: from gateway32.websitewelcome.com (HELO gateway32.websitewelcome.com) (192.185.145.113) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 28 Oct 2018 18:13:42 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 782502AAF32 for ; Sun, 28 Oct 2018 13:13:41 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id GpZFgBNufBcCXGpZFgOoNf; Sun, 28 Oct 2018 13:13:41 -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=qddB1x6pMxsZvaa3yddHixV0ZqMlfMJAiR6RdsCqjPE=; b=ix0rkf2KOZcVwLBR2xkf8zz2b4 58DULati8yv9Sjs04PXaaenAypAHv2og4Eh7/zIA7/lBkaf55bivND/8LXa0GNdpyR/bbFj+VXdbJ NGmhDbMAue8EitTqDwNu3fK93; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:39426 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gGpZE-001XD2-CU; Sun, 28 Oct 2018 13:13:40 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/3] Return gdbpy_ref from gdb_py_object_from_*longest Date: Sun, 28 Oct 2018 12:13:35 -0600 Message-Id: <20181028181337.21681-2-tom@tromey.com> In-Reply-To: <20181028181337.21681-1-tom@tromey.com> References: <20181028181337.21681-1-tom@tromey.com> This changes gdb_py_object_from_longest and gdb_py_object_from_ulongest to return a gdbpy_ref rather than a PyObject*. gdb/ChangeLog 2018-10-28 Tom Tromey * python/python-internal.h (gdb_py_object_from_longest) (gdb_py_object_from_ulongest): Return gdbpy_ref. * python/py-value.c (valpy_int): Update. * python/py-utils.c (gdb_py_object_from_longest): Return gdbpy_ref. (gdb_py_object_from_ulongest): Likewise. * python/py-type.c (typy_get_alignof): Update. * python/py-linetable.c (ltpy_get_all_source_lines) (ltpy_entry_get_line, ltpy_entry_get_pc): Update. * python/py-block.c (blpy_get_start, blpy_get_end): Update. --- gdb/ChangeLog | 13 +++++++++++++ gdb/python/py-block.c | 4 ++-- gdb/python/py-linetable.c | 6 +++--- gdb/python/py-type.c | 2 +- gdb/python/py-utils.c | 22 +++++++++++----------- gdb/python/py-value.c | 4 ++-- gdb/python/python-internal.h | 4 ++-- 7 files changed, 34 insertions(+), 21 deletions(-) diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c index 5fc33f0f0f..f5870c662b 100644 --- a/gdb/python/py-block.c +++ b/gdb/python/py-block.c @@ -110,7 +110,7 @@ blpy_get_start (PyObject *self, void *closure) BLPY_REQUIRE_VALID (self, block); - return gdb_py_object_from_ulongest (BLOCK_START (block)); + return gdb_py_object_from_ulongest (BLOCK_START (block)).release (); } static PyObject * @@ -120,7 +120,7 @@ blpy_get_end (PyObject *self, void *closure) BLPY_REQUIRE_VALID (self, block); - return gdb_py_object_from_ulongest (BLOCK_END (block)); + return gdb_py_object_from_ulongest (BLOCK_END (block)).release (); } static PyObject * diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c index c4e80d02a5..97c81aacf0 100644 --- a/gdb/python/py-linetable.c +++ b/gdb/python/py-linetable.c @@ -244,7 +244,7 @@ ltpy_get_all_source_lines (PyObject *self, PyObject *args) include in the source set. */ if (item->line > 0) { - gdbpy_ref<> line (gdb_py_object_from_longest (item->line)); + gdbpy_ref<> line = gdb_py_object_from_longest (item->line); if (line == NULL) return NULL; @@ -327,7 +327,7 @@ ltpy_entry_get_line (PyObject *self, void *closure) { linetable_entry_object *obj = (linetable_entry_object *) self; - return gdb_py_object_from_longest (obj->line); + return gdb_py_object_from_longest (obj->line).release (); } /* Implementation of gdb.LineTableEntry.pc (self) -> Long. Returns a @@ -338,7 +338,7 @@ ltpy_entry_get_pc (PyObject *self, void *closure) { linetable_entry_object *obj = (linetable_entry_object *) self; - return gdb_py_object_from_longest (obj->pc); + return gdb_py_object_from_longest (obj->pc).release (); } /* LineTable iterator functions. */ diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 897ad9374a..afc7635235 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -755,7 +755,7 @@ typy_get_alignof (PyObject *self, void *closure) /* Ignore exceptions. */ - return gdb_py_object_from_ulongest (align); + return gdb_py_object_from_ulongest (align).release (); } static struct type * diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c index 6ef0d7efd3..4dcac3daaf 100644 --- a/gdb/python/py-utils.c +++ b/gdb/python/py-utils.c @@ -295,47 +295,47 @@ get_addr_from_python (PyObject *obj, CORE_ADDR *addr) /* Convert a LONGEST to the appropriate Python object -- either an integer object or a long object, depending on its value. */ -PyObject * +gdbpy_ref<> gdb_py_object_from_longest (LONGEST l) { #ifdef IS_PY3K if (sizeof (l) > sizeof (long)) - return PyLong_FromLongLong (l); - return PyLong_FromLong (l); + return gdbpy_ref<> (PyLong_FromLongLong (l)); + return gdbpy_ref<> (PyLong_FromLong (l)); #else #ifdef HAVE_LONG_LONG /* Defined by Python. */ /* If we have 'long long', and the value overflows a 'long', use a Python Long; otherwise use a Python Int. */ if (sizeof (l) > sizeof (long) && (l > PyInt_GetMax () || l < (- (LONGEST) PyInt_GetMax ()) - 1)) - return PyLong_FromLongLong (l); + return gdbpy_ref<> (PyLong_FromLongLong (l)); #endif - return PyInt_FromLong (l); + return gdbpy_ref<> (PyInt_FromLong (l)); #endif } /* Convert a ULONGEST to the appropriate Python object -- either an integer object or a long object, depending on its value. */ -PyObject * +gdbpy_ref<> gdb_py_object_from_ulongest (ULONGEST l) { #ifdef IS_PY3K if (sizeof (l) > sizeof (unsigned long)) - return PyLong_FromUnsignedLongLong (l); - return PyLong_FromUnsignedLong (l); + return gdbpy_ref<> (PyLong_FromUnsignedLongLong (l)); + return gdbpy_ref<> (PyLong_FromUnsignedLong (l)); #else #ifdef HAVE_LONG_LONG /* Defined by Python. */ /* If we have 'long long', and the value overflows a 'long', use a Python Long; otherwise use a Python Int. */ if (sizeof (l) > sizeof (unsigned long) && l > PyInt_GetMax ()) - return PyLong_FromUnsignedLongLong (l); + return gdbpy_ref<> (PyLong_FromUnsignedLongLong (l)); #endif if (l > PyInt_GetMax ()) - return PyLong_FromUnsignedLong (l); + return gdbpy_ref<> (PyLong_FromUnsignedLong (l)); - return PyInt_FromLong (l); + return gdbpy_ref<> (PyInt_FromLong (l)); #endif } diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 26e91ff2b2..fe2adcc19c 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -1516,9 +1516,9 @@ valpy_int (PyObject *self) END_CATCH if (TYPE_UNSIGNED (type)) - return gdb_py_object_from_ulongest (l); + return gdb_py_object_from_ulongest (l).release (); else - return gdb_py_object_from_longest (l); + return gdb_py_object_from_longest (l).release (); } #endif diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 1812abb5b7..5f15a33d5e 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -705,8 +705,8 @@ extern void gdbpy_convert_exception (struct gdb_exception) int get_addr_from_python (PyObject *obj, CORE_ADDR *addr) CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION; -PyObject *gdb_py_object_from_longest (LONGEST l); -PyObject *gdb_py_object_from_ulongest (ULONGEST l); +gdbpy_ref<> gdb_py_object_from_longest (LONGEST l); +gdbpy_ref<> gdb_py_object_from_ulongest (ULONGEST l); int gdb_py_int_as_long (PyObject *, long *); PyObject *gdb_py_generic_dict (PyObject *self, void *closure);