From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23241 invoked by alias); 26 Feb 2009 08:37:05 -0000 Received: (qmail 23230 invoked by uid 22791); 26 Feb 2009 08:37:04 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 26 Feb 2009 08:36:58 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n1Q8auAH017420 for ; Thu, 26 Feb 2009 03:36:56 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n1Q8aumv023618 for ; Thu, 26 Feb 2009 03:36:56 -0500 Received: from localhost.localdomain (vpn-6-26.fab.redhat.com [10.33.6.26]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n1Q8atYK006368 for ; Thu, 26 Feb 2009 03:36:56 -0500 Message-ID: <49A654A6.8050504@redhat.com> Date: Thu, 26 Feb 2009 18:01:00 -0000 From: Phil Muldoon User-Agent: Thunderbird 2.0.0.19 (X11/20090105) MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: [python] python-utils.c (python_string_to_unicode): Always return a new reference. Content-Type: multipart/mixed; boundary="------------060809000102020502000807" X-IsSubscribed: yes 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 X-SW-Source: 2009-02/txt/msg00485.txt.bz2 This is a multi-part message in MIME format. --------------060809000102020502000807 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1004 Hi, The python_string_to_unicode function previously returned either a borrowed or new reference. This depended on some internal unicode versus encoded string checks. Because of the new versus borrowed reference question, and the inability to determine which was subsequently returned, this brought ambiguity to the clean-up decisions around this function. This patch removes the ambiguity by altering python_string_to_unicode to always return a new reference, and alters the consumers of this function to deal with this new behaviour appropriately. This patch does not increase or decrease the number of regressions with make check. Tested and built on Fedora 10 x86_64. 2009-02-26 Phil Muldoon * python/python-utils.c (python_string_to_unicode): Always return a new reference. (python_string_to_target_string): Decrement transient python instance. (python_string_to_host_string): Likewise. --------------060809000102020502000807 Content-Type: text/x-patch; name="unicode_decref_cvs.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="unicode_decref_cvs.patch" Content-length: 1507 Index: gdb/python/python-utils.c =================================================================== RCS file: /cvs/src/src/gdb/python/python-utils.c,v retrieving revision 1.5 diff -u -r1.5 python-utils.c --- gdb/python/python-utils.c 5 Feb 2009 21:16:09 -0000 1.5 +++ gdb/python/python-utils.c 26 Feb 2009 08:20:17 -0000 @@ -81,7 +81,11 @@ /* If obj is already a unicode string, just return it. I wish life was always that simple... */ if (PyUnicode_Check (obj)) - unicode_str = obj; + { + unicode_str = obj; + Py_INCREF (obj); + } + else if (PyString_Check (obj)) unicode_str = PyUnicode_FromEncodedObject (obj, host_charset (), NULL); else @@ -136,12 +140,15 @@ python_string_to_target_string (PyObject *obj) { PyObject *str; + char *result; str = python_string_to_unicode (obj); if (str == NULL) return NULL; - return unicode_to_target_string (str); + result = unicode_to_target_string (str); + Py_DECREF (str); + return result; } /* Converts a python string (8-bit or unicode) to a target string in @@ -152,12 +159,15 @@ python_string_to_host_string (PyObject *obj) { PyObject *str; + char *result; str = python_string_to_unicode (obj); if (str == NULL) return NULL; - return unicode_to_encoded_string (str, host_charset ()); + result = unicode_to_encoded_string (str, host_charset ()); + Py_DECREF (str); + return result; } /* Converts a target string of LENGTH bytes in the target's charset to a --------------060809000102020502000807--