From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4542 invoked by alias); 20 Nov 2016 20:42:09 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 3526 invoked by uid 89); 20 Nov 2016 20:42: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=UD:value.h, UD:py-utils.c, charseth, pyunwindc X-HELO: gproxy9-pub.mail.unifiedlayer.com Received: from gproxy9-pub.mail.unifiedlayer.com (HELO gproxy9-pub.mail.unifiedlayer.com) (69.89.20.122) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Sun, 20 Nov 2016 20:41:48 +0000 Received: (qmail 26586 invoked by uid 0); 20 Nov 2016 20:41:47 -0000 Received: from unknown (HELO CMOut01) (10.0.90.82) by gproxy9.mail.unifiedlayer.com with SMTP; 20 Nov 2016 20:41:47 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id ALhi1u00G2f2jeq01LhlMA; Sun, 20 Nov 2016 13:41:45 -0700 X-Authority-Analysis: v=2.1 cv=QtDNgzCd 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=BLkp6aD9sp_7OuuIXSQA:9 a=c2P-bsKbGAAMsEbT:21 a=lVRaNR0KcTFjt57k:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 174-16-143-211.hlrn.qwest.net ([174.16.143.211]:40590 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1c8Yvn-0005f5-R6; Sun, 20 Nov 2016 13:41:43 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 10/13] Use gdbpy_ref in py-utils.c Date: Sun, 20 Nov 2016 20:42:00 -0000 Message-Id: <1479674496-14000-11-git-send-email-tom@tromey.com> In-Reply-To: <1479674496-14000-1-git-send-email-tom@tromey.com> References: <1479674496-14000-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1c8Yvn-0005f5-R6 X-Source-Sender: 174-16-143-211.hlrn.qwest.net (bapiya.Home) [174.16.143.211]:40590 X-Source-Auth: tom+tromey.com X-Email-Count: 12 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-SW-Source: 2016-11/txt/msg00590.txt.bz2 This changes more places in py-utils.c to use gdbpy_ref. 2016-11-20 Tom Tromey * python/py-utils.c (unicode_to_encoded_string) (python_string_to_target_string) (python_string_to_target_python_string) (python_string_to_host_string, gdbpy_obj_to_string) (get_addr_from_python): Use gdbpy_ref. --- gdb/ChangeLog | 8 ++++++++ gdb/python/py-utils.c | 49 +++++++++++++++---------------------------------- 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 3016d3a..4f8447c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,13 @@ 2016-11-20 Tom Tromey + * python/py-utils.c (unicode_to_encoded_string) + (python_string_to_target_string) + (python_string_to_target_python_string) + (python_string_to_host_string, gdbpy_obj_to_string) + (get_addr_from_python): Use gdbpy_ref. + +2016-11-20 Tom Tromey + * python/py-unwind.c (pyuw_object_attribute_to_pointer): Use gdbpy_ref. diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c index 9f99e29..6b7540c 100644 --- a/gdb/python/py-utils.c +++ b/gdb/python/py-utils.c @@ -21,7 +21,7 @@ #include "charset.h" #include "value.h" #include "python-internal.h" - +#include "py-ref.h" /* This is a cleanup function which decrements the refcount on a Python object. */ @@ -111,21 +111,18 @@ static gdb::unique_xmalloc_ptr unicode_to_encoded_string (PyObject *unicode_str, const char *charset) { gdb::unique_xmalloc_ptr result; - PyObject *string; /* Translate string to named charset. */ - string = PyUnicode_AsEncodedString (unicode_str, charset, NULL); + gdbpy_ref string (PyUnicode_AsEncodedString (unicode_str, charset, NULL)); if (string == NULL) return NULL; #ifdef IS_PY3K - result.reset (xstrdup (PyBytes_AsString (string))); + result.reset (xstrdup (PyBytes_AsString (string.get ()))); #else - result.reset (xstrdup (PyString_AsString (string))); + result.reset (xstrdup (PyString_AsString (string.get ()))); #endif - Py_DECREF (string); - return result; } @@ -168,15 +165,11 @@ unicode_to_target_python_string (PyObject *unicode_str) gdb::unique_xmalloc_ptr python_string_to_target_string (PyObject *obj) { - PyObject *str; - - str = python_string_to_unicode (obj); + gdbpy_ref str (python_string_to_unicode (obj)); if (str == NULL) return NULL; - gdb::unique_xmalloc_ptr result (unicode_to_target_string (str)); - Py_DECREF (str); - return result; + return unicode_to_target_string (str.get ()); } /* Converts a python string (8-bit or unicode) to a target string in the @@ -187,16 +180,11 @@ python_string_to_target_string (PyObject *obj) PyObject * python_string_to_target_python_string (PyObject *obj) { - PyObject *str; - PyObject *result; - - str = python_string_to_unicode (obj); + gdbpy_ref str (python_string_to_unicode (obj)); if (str == NULL) return NULL; - result = unicode_to_target_python_string (str); - Py_DECREF (str); - return result; + return unicode_to_target_python_string (str.get ()); } /* Converts a python string (8-bit or unicode) to a target string in @@ -205,16 +193,11 @@ python_string_to_target_python_string (PyObject *obj) gdb::unique_xmalloc_ptr python_string_to_host_string (PyObject *obj) { - PyObject *str; - - str = python_string_to_unicode (obj); + gdbpy_ref str (python_string_to_unicode (obj)); if (str == NULL) return NULL; - gdb::unique_xmalloc_ptr - result (unicode_to_encoded_string (str, host_charset ())); - Py_DECREF (str); - return result; + return unicode_to_encoded_string (str.get (), host_charset ()); } /* Convert a host string to a python string. */ @@ -244,19 +227,18 @@ gdbpy_is_string (PyObject *obj) gdb::unique_xmalloc_ptr gdbpy_obj_to_string (PyObject *obj) { - PyObject *str_obj = PyObject_Str (obj); + gdbpy_ref str_obj (PyObject_Str (obj)); if (str_obj != NULL) { gdb::unique_xmalloc_ptr msg; #ifdef IS_PY3K - msg = python_string_to_host_string (str_obj); + msg = python_string_to_host_string (str_obj.get ()); #else - msg.reset (xstrdup (PyString_AsString (str_obj))); + msg.reset (xstrdup (PyString_AsString (str_obj.get ()))); #endif - Py_DECREF (str_obj); return msg; } @@ -329,14 +311,13 @@ get_addr_from_python (PyObject *obj, CORE_ADDR *addr) } else { - PyObject *num = PyNumber_Long (obj); + gdbpy_ref num (PyNumber_Long (obj)); gdb_py_ulongest val; if (num == NULL) return -1; - val = gdb_py_long_as_ulongest (num); - Py_XDECREF (num); + val = gdb_py_long_as_ulongest (num.get ()); if (PyErr_Occurred ()) return -1; -- 2.7.4