From patchwork Sat Sep 8 23:21:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 29269 Received: (qmail 26886 invoked by alias); 8 Sep 2018 23:22:01 -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 26865 invoked by uid 89); 8 Sep 2018 23:22:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.2 spammy=gap X-HELO: sesbmg22.ericsson.net Received: from sesbmg22.ericsson.net (HELO sesbmg22.ericsson.net) (193.180.251.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 08 Sep 2018 23:21:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/simple; q=dns/txt; i=@ericsson.com; t=1536448915; h=From:Sender:Reply-To:Subject:Date:Message-Id:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=QIsYWkyAr7/NLQbxTdn5laNxpt8TaNkUfGPylE2MLCI=; b=gg7zBZ4ILgLCgBYEeD2YhuEd0Wv+t3YPTWR4fwy1QUJPglA3QBG/AxlFKxzyzld4 A6NKfHXW/rqXfIF/fylcOYiU9Q0zCB2fY9xrGGmgm+0P7X5yFndsHOJ4cKbsiA2q 2EnR8XFsK4P86xq44CzH/CcKZrzfmnj0UMLj9TJP+GI=; Received: from ESESBMB503.ericsson.se (Unknown_Domain [153.88.183.116]) by sesbmg22.ericsson.net (Symantec Mail Security) with SMTP id 9D.8E.21978.399549B5; Sun, 9 Sep 2018 01:21:55 +0200 (CEST) Received: from ESESBMB503.ericsson.se (153.88.183.170) by ESESBMB503.ericsson.se (153.88.183.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Sun, 9 Sep 2018 01:21:55 +0200 Received: from NAM01-BY2-obe.outbound.protection.outlook.com (153.88.183.157) by ESESBMB503.ericsson.se (153.88.183.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3 via Frontend Transport; Sun, 9 Sep 2018 01:21:55 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NjfomD04YBOYGJYwX9umlHERLxSq2FC6SUZcx/mYzqk=; b=LIyZXfOzTb7deqQm5T9xrQMIOZ5FgFKEPxhSiob3PmhYuw1O+iPOXSRgwQetnnrq/yIOYEjqfSUXD+K/k/kt/SLqz73IFR0ZJ1yacjvAcAOjfLJboqxbSp2fhpsCQZZG40k80i4Ekayhv2BkMta9tqnaaXRQli5NzF+Z7jM3W58= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=simon.marchi@ericsson.com; Received: from elxacz23q12.ericsson.se (192.176.1.81) by SN6PR15MB2398.namprd15.prod.outlook.com (2603:10b6:805:24::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1101.17; Sat, 8 Sep 2018 23:21:50 +0000 From: Simon Marchi To: CC: Simon Marchi Subject: [PATCH] python: Make two functions return gdbpy_ref<> Date: Sun, 9 Sep 2018 00:21:25 +0100 Message-Id: <1536448885-6222-1-git-send-email-simon.marchi@ericsson.com> MIME-Version: 1.0 Return-Path: simon.marchi@ericsson.com Received-SPF: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) X-IsSubscribed: yes I noticed that we release a gdbpy_ref in pretty_print_one_value only to create it again later. This patch fills the gap by returning a gdbpy_ref all the way. gdb/ChangeLog: * python/py-prettyprint.c (pretty_print_one_value): Return gdbpy_ref<>. (print_string_repr): Adjust. (apply_varobj_pretty_printer): Return gdbpy_ref<>. * python/python-internal.h (apply_varobj_pretty_printer): Return gdbpy_ref<>. * varobj.c (varobj_value_get_print_value): Adjust. --- gdb/python/py-prettyprint.c | 12 +++++------- gdb/python/python-internal.h | 7 ++++--- gdb/varobj.c | 6 +++--- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c index a8a8489..3c4c8cf 100644 --- a/gdb/python/py-prettyprint.c +++ b/gdb/python/py-prettyprint.c @@ -187,7 +187,7 @@ find_pretty_printer (PyObject *value) is returned. On error, *OUT_VALUE is set to NULL, NULL is returned, with a python exception set. */ -static PyObject * +static gdbpy_ref<> pretty_print_one_value (PyObject *printer, struct value **out_value) { gdbpy_ref<> result; @@ -215,7 +215,7 @@ pretty_print_one_value (PyObject *printer, struct value **out_value) } END_CATCH - return result.release (); + return result; } /* Return the display hint for the object printer, PRINTER. Return @@ -288,7 +288,7 @@ print_string_repr (PyObject *printer, const char *hint, struct value *replacement = NULL; enum string_repr_result result = string_repr_ok; - gdbpy_ref<> py_str (pretty_print_one_value (printer, &replacement)); + gdbpy_ref<> py_str = pretty_print_one_value (printer, &replacement); if (py_str != NULL) { if (py_str == Py_None) @@ -721,15 +721,13 @@ gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang, set to the replacement value and this function returns NULL. On error, *REPLACEMENT is set to NULL and this function also returns NULL. */ -PyObject * +gdbpy_ref<> apply_varobj_pretty_printer (PyObject *printer_obj, struct value **replacement, struct ui_file *stream) { - PyObject *py_str = NULL; - *replacement = NULL; - py_str = pretty_print_one_value (printer_obj, replacement); + gdbpy_ref<> py_str = pretty_print_one_value (printer_obj, replacement); if (*replacement == NULL && py_str == NULL) print_stack_unless_memory_error (stream); diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index c4f0e21..3874fdc 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -99,6 +99,7 @@ from including our python/python.h header file. */ #include #include +#include "py-ref.h" #if PY_MAJOR_VERSION >= 3 #define IS_PY3K 1 @@ -691,9 +692,9 @@ int gdbpy_is_value_object (PyObject *obj); /* Note that these are declared here, and not in python.h with the other pretty-printer functions, because they refer to PyObject. */ -PyObject *apply_varobj_pretty_printer (PyObject *print_obj, - struct value **replacement, - struct ui_file *stream); +gdbpy_ref<> apply_varobj_pretty_printer (PyObject *print_obj, + struct value **replacement, + struct ui_file *stream); PyObject *gdbpy_get_varobj_pretty_printer (struct value *value); gdb::unique_xmalloc_ptr gdbpy_get_display_hint (PyObject *printer); PyObject *gdbpy_default_visualizer (PyObject *self, PyObject *args); diff --git a/gdb/varobj.c b/gdb/varobj.c index af60796..e109926 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -2318,9 +2318,9 @@ varobj_value_get_print_value (struct value *value, { struct value *replacement; - gdbpy_ref<> output (apply_varobj_pretty_printer (value_formatter, - &replacement, - &stb)); + gdbpy_ref<> output = apply_varobj_pretty_printer (value_formatter, + &replacement, + &stb); /* If we have string like output ... */ if (output != NULL)