From patchwork Mon Nov 7 05:47:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 17256 Received: (qmail 127866 invoked by alias); 7 Nov 2016 05:57:04 -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 127855 invoked by uid 89); 7 Nov 2016 05:57:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=H*RU:cmgw2, Hx-spam-relays-external:cmgw2, H*r:cmgw2, Hx-spam-relays-external:10.0.90.83 X-HELO: gproxy1.mail.unifiedlayer.com Received: from gproxy1-pub.mail.unifiedlayer.com (HELO gproxy1.mail.unifiedlayer.com) (69.89.25.95) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 07 Nov 2016 05:56:53 +0000 Received: from cmgw2 (cmgw3 [10.0.90.83]) by gproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id 82C7A177AAE for ; Sun, 6 Nov 2016 22:47:45 -0700 (MST) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id 4tng1u00k2f2jeq01tnjv6; Sun, 06 Nov 2016 22:47:43 -0700 X-Authority-Analysis: v=2.1 cv=PIacp5aC c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=L24OOQBejmoA:10 a=zstS-IiYAAAA:8 a=SFB_Q5g4IkfUfC3_VdQA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 174-16-143-211.hlrn.qwest.net ([174.16.143.211]:47918 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1c3cmU-0008A3-7r; Sun, 06 Nov 2016 22:47:42 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 09/14] Use gdbpy_reference in py-linetable.c Date: Sun, 6 Nov 2016 22:47:31 -0700 Message-Id: <1478497656-11832-10-git-send-email-tom@tromey.com> In-Reply-To: <1478497656-11832-1-git-send-email-tom@tromey.com> References: <1478497656-11832-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1c3cmU-0008A3-7r X-Source-Sender: 174-16-143-211.hlrn.qwest.net (bapiya.Home) [174.16.143.211]:47918 X-Source-Auth: tom+tromey.com X-Email-Count: 10 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This changes some code in py-linetable.c to use gdbpy_reference. 2016-11-06 Tom Tromey * python/py-linetable.c (build_line_table_tuple_from_pcs) (ltpy_get_all_source_lines): Use gdbpy_reference. --- gdb/ChangeLog | 5 +++++ gdb/python/py-linetable.c | 51 +++++++++++++---------------------------------- 2 files changed, 19 insertions(+), 37 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4921600..9aa7008 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2016-11-06 Tom Tromey + * python/py-linetable.c (build_line_table_tuple_from_pcs) + (ltpy_get_all_source_lines): Use gdbpy_reference. + +2016-11-06 Tom Tromey + * python/py-framefilter.c (extract_sym, extract_value) (get_py_iter_from_func, bootstrap_python_frame_filters): Use gdbpy_reference. diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c index 662ae88..8be7e0e 100644 --- a/gdb/python/py-linetable.c +++ b/gdb/python/py-linetable.c @@ -19,6 +19,7 @@ #include "defs.h" #include "python-internal.h" +#include "py-ref.h" typedef struct { PyObject_HEAD @@ -124,7 +125,6 @@ static PyObject * build_line_table_tuple_from_pcs (int line, VEC (CORE_ADDR) *vec) { int vec_len = 0; - PyObject *tuple; CORE_ADDR pc; int i; @@ -132,31 +132,22 @@ build_line_table_tuple_from_pcs (int line, VEC (CORE_ADDR) *vec) if (vec_len < 1) Py_RETURN_NONE; - tuple = PyTuple_New (vec_len); + gdbpy_reference tuple (PyTuple_New (vec_len)); if (tuple == NULL) return NULL; for (i = 0; VEC_iterate (CORE_ADDR, vec, i, pc); ++i) { - PyObject *obj = build_linetable_entry (line, pc); + gdbpy_reference obj (build_linetable_entry (line, pc)); if (obj == NULL) - { - Py_DECREF (tuple); - tuple = NULL; - break; - } - else if (PyTuple_SetItem (tuple, i, obj) != 0) - { - Py_DECREF (obj); - Py_DECREF (tuple); - tuple = NULL; - break; - } + return NULL; + else if (PyTuple_SetItem (tuple.get (), i, obj.release ()) != 0) + return NULL; } - return tuple; + return tuple.release (); } /* Implementation of gdb.LineTable.line (self) -> Tuple. Returns a @@ -236,7 +227,6 @@ ltpy_get_all_source_lines (PyObject *self, PyObject *args) { struct symtab *symtab; Py_ssize_t index; - PyObject *source_list, *source_dict, *line; struct linetable_entry *item; LTPY_REQUIRE_VALID (self, symtab); @@ -248,7 +238,7 @@ ltpy_get_all_source_lines (PyObject *self, PyObject *args) return NULL; } - source_dict = PyDict_New (); + gdbpy_reference source_dict (PyDict_New ()); if (source_dict == NULL) return NULL; @@ -260,30 +250,17 @@ ltpy_get_all_source_lines (PyObject *self, PyObject *args) include in the source set. */ if (item->line > 0) { - line = gdb_py_object_from_longest (item->line); + gdbpy_reference line (gdb_py_object_from_longest (item->line)); if (line == NULL) - { - Py_DECREF (source_dict); - return NULL; - } - - if (PyDict_SetItem (source_dict, line, Py_None) == -1) - { - Py_DECREF (line); - Py_DECREF (source_dict); - return NULL; - } - - Py_DECREF (line); + return NULL; + + if (PyDict_SetItem (source_dict.get (), line.get (), Py_None) == -1) + return NULL; } } - - source_list = PyDict_Keys (source_dict); - Py_DECREF (source_dict); - - return source_list; + return PyDict_Keys (source_dict.get ()); } /* Implementation of gdb.LineTable.is_valid (self) -> Boolean.