From patchwork Sat Nov 12 21:28:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 17426 Received: (qmail 57214 invoked by alias); 12 Nov 2016 21:29:06 -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 57196 invoked by uid 89); 12 Nov 2016 21:29:06 -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= X-HELO: gproxy7-pub.mail.unifiedlayer.com Received: from gproxy7-pub.mail.unifiedlayer.com (HELO gproxy7-pub.mail.unifiedlayer.com) (70.40.196.235) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Sat, 12 Nov 2016 21:28:55 +0000 Received: (qmail 27073 invoked by uid 0); 12 Nov 2016 21:28:54 -0000 Received: from unknown (HELO cmgw2) (10.0.90.83) by gproxy7.mail.unifiedlayer.com with SMTP; 12 Nov 2016 21:28:54 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id 79Up1u00S2f2jeq019UsvS; Sat, 12 Nov 2016 14:28:52 -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=9O5oAHKznk_M0cupS8MA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 97-118-168-190.hlrn.qwest.net ([97.118.168.190]:47378 helo=bapiya.localdomain) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1c5fr0-0006jl-QU; Sat, 12 Nov 2016 14:28:50 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 02/11] Use gdbpy_enter in fnpy_call Date: Sat, 12 Nov 2016 14:28:36 -0700 Message-Id: <1478986125-15122-3-git-send-email-tom@tromey.com> In-Reply-To: <1478986125-15122-1-git-send-email-tom@tromey.com> References: <1478986125-15122-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1c5fr0-0006jl-QU X-Source-Sender: 97-118-168-190.hlrn.qwest.net (bapiya.localdomain) [97.118.168.190]:47378 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This changes fnpy_call to use gdbpy_enter and gdbpy_ref. 2016-11-12 Tom Tromey * python/py-function.c (fnpy_call): Use gdbpy_enter, gdbpy_ref. --- gdb/ChangeLog | 4 ++++ gdb/python/py-function.c | 32 +++++++++++--------------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9c0e5d2..1a7e8e2 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,9 @@ 2016-11-12 Tom Tromey + * python/py-function.c (fnpy_call): Use gdbpy_enter, gdbpy_ref. + +2016-11-12 Tom Tromey + * python/py-cmd.c (cmdpy_function): Use gdbpy_enter, gdbpy_ref. 2016-11-10 Tom Tromey diff --git a/gdb/python/py-function.c b/gdb/python/py-function.c index 2bdab7e..00f0848 100644 --- a/gdb/python/py-function.c +++ b/gdb/python/py-function.c @@ -62,34 +62,28 @@ fnpy_call (struct gdbarch *gdbarch, const struct language_defn *language, struct value *value = NULL; /* 'result' must be set to NULL, this initially indicates whether the function was called, or not. */ - PyObject *result = NULL; - PyObject *callable, *args; - struct cleanup *cleanup; + gdbpy_ref result; - cleanup = ensure_python_env (gdbarch, language); + gdbpy_enter enter_py (gdbarch, language); - args = convert_values_to_python (argc, argv); + gdbpy_ref args (convert_values_to_python (argc, argv)); /* convert_values_to_python can return NULL on error. If we encounter this, do not call the function, but allow the Python -> error code conversion below to deal with the Python exception. Note, that this is different if the function simply does not have arguments. */ - if (args) + if (args != NULL) { - callable = PyObject_GetAttrString ((PyObject *) cookie, "invoke"); - if (! callable) - { - Py_DECREF (args); - error (_("No method named 'invoke' in object.")); - } + gdbpy_ref callable (PyObject_GetAttrString ((PyObject *) cookie, + "invoke")); + if (callable == NULL) + error (_("No method named 'invoke' in object.")); - result = PyObject_Call (callable, args, NULL); - Py_DECREF (callable); - Py_DECREF (args); + result.reset (PyObject_Call (callable.get (), args.get (), NULL)); } - if (!result) + if (result == NULL) { PyObject *ptype, *pvalue, *ptraceback; @@ -141,17 +135,13 @@ fnpy_call (struct gdbarch *gdbarch, const struct language_defn *language, } } - value = convert_value_from_python (result); + value = convert_value_from_python (result.get ()); if (value == NULL) { - Py_DECREF (result); gdbpy_print_stack (); error (_("Error while executing Python code.")); } - Py_DECREF (result); - do_cleanups (cleanup); - return value; }