* [python] python-utils.c (python_string_to_unicode): Always return a new reference.
@ 2009-02-26 18:01 Phil Muldoon
2009-02-26 18:41 ` Tom Tromey
0 siblings, 1 reply; 2+ messages in thread
From: Phil Muldoon @ 2009-02-26 18:01 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1004 bytes --]
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 <pmuldoon@redhat.com>
* 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.
[-- Attachment #2: unicode_decref_cvs.patch --]
[-- Type: text/x-patch, Size: 1507 bytes --]
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [python] python-utils.c (python_string_to_unicode): Always return a new reference.
2009-02-26 18:01 [python] python-utils.c (python_string_to_unicode): Always return a new reference Phil Muldoon
@ 2009-02-26 18:41 ` Tom Tromey
0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2009-02-26 18:41 UTC (permalink / raw)
To: Phil Muldoon; +Cc: gdb-patches
>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
Phil> 2009-02-26 Phil Muldoon <pmuldoon@redhat.com>
Phil> * python/python-utils.c (python_string_to_unicode): Always
Phil> return
Phil> a new reference.
[...]
This is ok.
thanks,
Tom
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-02-26 17:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-26 18:01 [python] python-utils.c (python_string_to_unicode): Always return a new reference Phil Muldoon
2009-02-26 18:41 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox