diff options
author | Phil Muldoon <pmuldoon@redhat.com> | 2009-02-26 20:45:21 +0000 |
---|---|---|
committer | Phil Muldoon <pmuldoon@redhat.com> | 2009-02-26 20:45:21 +0000 |
commit | 83390453c399fd336223ba1cfbcd77d5bef4c2cb (patch) | |
tree | de219623bbdfc3f3c73e4014331bcce22c13b67d | |
parent | a0740d21fab1a24e058a517d17bfb80f166ff9e1 (diff) | |
download | gdb-83390453c399fd336223ba1cfbcd77d5bef4c2cb.zip gdb-83390453c399fd336223ba1cfbcd77d5bef4c2cb.tar.gz gdb-83390453c399fd336223ba1cfbcd77d5bef4c2cb.tar.bz2 |
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.
-rw-r--r-- | gdb/ChangeLog | 10 | ||||
-rw-r--r-- | gdb/python/python-utils.c | 16 |
2 files changed, 22 insertions, 4 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 02d0fc6..c7045cd 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,4 +1,12 @@ -2009-02-26 Pedro Alves <pedro@codesourcery.com> +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. + +2007-02-26 Pedro Alves <pedro@codesourcery.com> * mips-linux-nat.c (mips64_linux_fetch_registers): Pass `ops' to call to super_fetch_registers. diff --git a/gdb/python/python-utils.c b/gdb/python/python-utils.c index b0ec7b3..ddac2f5 100644 --- a/gdb/python/python-utils.c +++ b/gdb/python/python-utils.c @@ -81,7 +81,11 @@ python_string_to_unicode (PyObject *obj) /* 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 @@ char * 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 @@ char * 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 |