From patchwork Thu Nov 10 22:19:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 17395 Received: (qmail 62307 invoked by alias); 10 Nov 2016 22:20:20 -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 62169 invoked by uid 89); 10 Nov 2016 22:20:19 -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=vec_safe_push, matchers, gdb_assert, VEC_safe_push 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; Thu, 10 Nov 2016 22:20:04 +0000 Received: from cmgw2 (cmgw3 [10.0.90.83]) by gproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id 85680176511 for ; Thu, 10 Nov 2016 15:20:03 -0700 (MST) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id 6NKy1u0192f2jeq01NL1Cr; Thu, 10 Nov 2016 15:20:01 -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=0cArjbrH7-ntj3OxBLUA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 174-16-143-211.hlrn.qwest.net ([174.16.143.211]:60120 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1c4xhQ-0002sd-22; Thu, 10 Nov 2016 15:20:00 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 16/20] Use gdbpy_enter in gdbpy_get_matching_xmethod_workers Date: Thu, 10 Nov 2016 15:19:43 -0700 Message-Id: <1478816387-27064-17-git-send-email-tom@tromey.com> In-Reply-To: <1478816387-27064-1-git-send-email-tom@tromey.com> References: <1478816387-27064-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1c4xhQ-0002sd-22 X-Source-Sender: 174-16-143-211.hlrn.qwest.net (bapiya.Home) [174.16.143.211]:60120 X-Source-Auth: tom+tromey.com X-Email-Count: 17 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== Change gdbpy_get_matching_xmethod_workers to use gdbpy_enter and gdbpy_reference. 2016-11-10 Tom Tromey * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): use gdbpy_enter, gdbpy_reference. --- gdb/ChangeLog | 5 ++ gdb/python/py-xmethods.c | 153 ++++++++++++++++++----------------------------- 2 files changed, 63 insertions(+), 95 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1a415fb..fef6a71 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2016-11-10 Tom Tromey + * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): use + gdbpy_enter, gdbpy_reference. + +2016-11-10 Tom Tromey + * python/python.c (python_interactive_command): Use gdbpy_enter. 2016-11-10 Tom Tromey diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c index 2c86478..ca83b0b 100644 --- a/gdb/python/py-xmethods.c +++ b/gdb/python/py-xmethods.c @@ -26,6 +26,7 @@ #include "python.h" #include "python-internal.h" +#include "py-ref.h" static const char enabled_field_name[] = "enabled"; static const char match_method_name[] = "match"; @@ -156,33 +157,26 @@ gdbpy_get_matching_xmethod_workers struct type *obj_type, const char *method_name, xmethod_worker_vec **dm_vec) { - struct cleanup *cleanups; struct objfile *objfile; VEC (xmethod_worker_ptr) *worker_vec = NULL; - PyObject *py_type, *py_progspace; - PyObject *py_xmethod_matcher_list = NULL, *list_iter, *matcher; + PyObject *py_progspace; gdb_assert (obj_type != NULL && method_name != NULL); - cleanups = ensure_python_env (get_current_arch (), current_language); + gdbpy_enter enter_py (get_current_arch (), current_language); - py_type = type_to_type_object (obj_type); + gdbpy_reference py_type (type_to_type_object (obj_type)); if (py_type == NULL) { gdbpy_print_stack (); - do_cleanups (cleanups); - return EXT_LANG_RC_ERROR; } - make_cleanup_py_decref (py_type); /* Create an empty list of debug methods. */ - py_xmethod_matcher_list = PyList_New (0); + gdbpy_reference py_xmethod_matcher_list (PyList_New (0)); if (py_xmethod_matcher_list == NULL) { gdbpy_print_stack (); - do_cleanups (cleanups); - return EXT_LANG_RC_ERROR; } @@ -192,28 +186,23 @@ gdbpy_get_matching_xmethod_workers ALL_OBJFILES (objfile) { PyObject *py_objfile = objfile_to_objfile_object (objfile); - PyObject *objfile_matchers, *temp = py_xmethod_matcher_list; if (py_objfile == NULL) { gdbpy_print_stack (); - Py_DECREF (py_xmethod_matcher_list); - do_cleanups (cleanups); - return EXT_LANG_RC_ERROR; } - objfile_matchers = objfpy_get_xmethods (py_objfile, NULL); - py_xmethod_matcher_list = PySequence_Concat (temp, objfile_matchers); - Py_DECREF (temp); - Py_DECREF (objfile_matchers); - if (py_xmethod_matcher_list == NULL) + gdbpy_reference objfile_matchers (objfpy_get_xmethods (py_objfile, NULL)); + gdbpy_reference temp (PySequence_Concat (py_xmethod_matcher_list.get (), + objfile_matchers.get ())); + if (temp == NULL) { gdbpy_print_stack (); - do_cleanups (cleanups); - return EXT_LANG_RC_ERROR; } + + py_xmethod_matcher_list = temp; } /* Gather debug methods matchers registered with the current program @@ -221,26 +210,21 @@ gdbpy_get_matching_xmethod_workers py_progspace = pspace_to_pspace_object (current_program_space); if (py_progspace != NULL) { - PyObject *temp = py_xmethod_matcher_list; - PyObject *pspace_matchers = pspy_get_xmethods (py_progspace, NULL); + gdbpy_reference pspace_matchers (pspy_get_xmethods (py_progspace, NULL)); - py_xmethod_matcher_list = PySequence_Concat (temp, pspace_matchers); - Py_DECREF (temp); - Py_DECREF (pspace_matchers); - if (py_xmethod_matcher_list == NULL) + gdbpy_reference temp (PySequence_Concat (py_xmethod_matcher_list.get (), + pspace_matchers.get ())); + if (temp == NULL) { gdbpy_print_stack (); - do_cleanups (cleanups); - return EXT_LANG_RC_ERROR; } + + py_xmethod_matcher_list = temp; } else { gdbpy_print_stack (); - Py_DECREF (py_xmethod_matcher_list); - do_cleanups (cleanups); - return EXT_LANG_RC_ERROR; } @@ -248,117 +232,96 @@ gdbpy_get_matching_xmethod_workers if (gdb_python_module != NULL && PyObject_HasAttrString (gdb_python_module, matchers_attr_str)) { - PyObject *gdb_matchers; - PyObject *temp = py_xmethod_matcher_list; - - gdb_matchers = PyObject_GetAttrString (gdb_python_module, - matchers_attr_str); + gdbpy_reference gdb_matchers (PyObject_GetAttrString (gdb_python_module, + matchers_attr_str)); if (gdb_matchers != NULL) { - py_xmethod_matcher_list = PySequence_Concat (temp, gdb_matchers); - Py_DECREF (temp); - Py_DECREF (gdb_matchers); - if (py_xmethod_matcher_list == NULL) + gdbpy_reference temp + (PySequence_Concat (py_xmethod_matcher_list.get (), + gdb_matchers.get ())); + if (temp == NULL) { gdbpy_print_stack (); - do_cleanups (cleanups); - return EXT_LANG_RC_ERROR; } + + py_xmethod_matcher_list = temp; } else { gdbpy_print_stack (); - Py_DECREF (py_xmethod_matcher_list); - do_cleanups (cleanups); - return EXT_LANG_RC_ERROR; } } - /* Safe to make a cleanup for py_xmethod_matcher_list now as it - will not change any more. */ - make_cleanup_py_decref (py_xmethod_matcher_list); - - list_iter = PyObject_GetIter (py_xmethod_matcher_list); + gdbpy_reference list_iter (PyObject_GetIter (py_xmethod_matcher_list.get ())); if (list_iter == NULL) { gdbpy_print_stack (); - do_cleanups (cleanups); - return EXT_LANG_RC_ERROR; } - while ((matcher = PyIter_Next (list_iter)) != NULL) + while (true) { - PyObject *match_result = invoke_match_method (matcher, py_type, - method_name); + gdbpy_reference matcher (PyIter_Next (list_iter.get ())); + if (matcher == NULL) + { + if (PyErr_Occurred ()) + { + gdbpy_print_stack (); + return EXT_LANG_RC_ERROR; + } + break; + } + + gdbpy_reference match_result + (invoke_match_method (matcher.get (), py_type.get (), method_name)); if (match_result == NULL) { gdbpy_print_stack (); - Py_DECREF (matcher); - do_cleanups (cleanups); - return EXT_LANG_RC_ERROR; } if (match_result == Py_None) ; /* This means there was no match. */ - else if (PySequence_Check (match_result)) + else if (PySequence_Check (match_result.get ())) { - PyObject *iter = PyObject_GetIter (match_result); - PyObject *py_worker; + gdbpy_reference iter (PyObject_GetIter (match_result.get ())); if (iter == NULL) { gdbpy_print_stack (); - Py_DECREF (matcher); - Py_DECREF (match_result); - do_cleanups (cleanups); - return EXT_LANG_RC_ERROR; } - while ((py_worker = PyIter_Next (iter)) != NULL) + while (true) { struct xmethod_worker *worker; - worker = new_python_xmethod_worker (py_worker, py_type); + gdbpy_reference py_worker (PyIter_Next (iter.get ())); + if (py_worker == NULL) + { + if (PyErr_Occurred ()) + { + gdbpy_print_stack (); + return EXT_LANG_RC_ERROR; + } + break; + } + + worker = new_python_xmethod_worker (py_worker.get (), + py_type.get ()); VEC_safe_push (xmethod_worker_ptr, worker_vec, worker); - Py_DECREF (py_worker); - } - Py_DECREF (iter); - /* Report any error that could have occurred while iterating. */ - if (PyErr_Occurred ()) - { - gdbpy_print_stack (); - Py_DECREF (matcher); - Py_DECREF (match_result); - do_cleanups (cleanups); - - return EXT_LANG_RC_ERROR; } } else { struct xmethod_worker *worker; - worker = new_python_xmethod_worker (match_result, py_type); + worker = new_python_xmethod_worker (match_result.get (), + py_type.get ()); VEC_safe_push (xmethod_worker_ptr, worker_vec, worker); } - - Py_DECREF (match_result); - Py_DECREF (matcher); - } - Py_DECREF (list_iter); - /* Report any error that could have occurred while iterating. */ - if (PyErr_Occurred ()) - { - gdbpy_print_stack (); - do_cleanups (cleanups); - - return EXT_LANG_RC_ERROR; } - do_cleanups (cleanups); *dm_vec = worker_vec; return EXT_LANG_RC_OK;