diff options
author | Tom Tromey <tom@tromey.com> | 2018-10-24 16:40:00 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-11-04 08:01:01 -0700 |
commit | 833d985d1c7f69f953a5c7ddcf2af1d001504961 (patch) | |
tree | ccb8011da9e64e6b6201dd079c1e57723215f505 /gdb/python/py-utils.c | |
parent | 12dfa12a3cfd4552c0cc4d7b271ab3e9c439589a (diff) | |
download | gdb-833d985d1c7f69f953a5c7ddcf2af1d001504961.zip gdb-833d985d1c7f69f953a5c7ddcf2af1d001504961.tar.gz gdb-833d985d1c7f69f953a5c7ddcf2af1d001504961.tar.bz2 |
Return gdbpy_ref from some Python string functions
This changes python_string_to_unicode,
python_string_to_target_python_string, and
host_string_to_python_string to return gdbpy_ref.
gdb/ChangeLog
2018-11-04 Tom Tromey <tom@tromey.com>
* python/python.c (gdbpy_parameter_value): Update.
* python/python-internal.h (python_string_to_unicode)
(python_string_to_target_python_string)
(host_string_to_python_string): Return gdbpy_ref.
* python/py-utils.c (python_string_to_unicode)
(unicode_to_encoded_python_string)
(unicode_to_target_python_string)
(python_string_to_target_string)
(python_string_to_target_python_string): Return gdbpy_ref.
(python_string_to_host_string): Update.
(host_string_to_python_string): Return gdbpy_ref.
* python/py-symtab.c (stpy_get_filename, stpy_get_producer)
(stpy_fullname): Update.
* python/py-progspace.c (pspy_get_filename, pspy_solib_name):
Update.
* python/py-prettyprint.c (print_string_repr): Update.
* python/py-objfile.c (objfpy_get_filename, objfpy_get_username)
(objfpy_get_build_id): Update.
* python/py-breakpoint.c (bppy_get_location)
(bppy_get_expression, bppy_get_condition, bppy_get_commands):
Update.
Diffstat (limited to 'gdb/python/py-utils.c')
-rw-r--r-- | gdb/python/py-utils.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c index 4dcac3d..2b47790 100644 --- a/gdb/python/py-utils.c +++ b/gdb/python/py-utils.c @@ -34,7 +34,7 @@ If the given object is not one of the mentioned string types, NULL is returned, with the TypeError python exception set. */ -PyObject * +gdbpy_ref<> python_string_to_unicode (PyObject *obj) { PyObject *unicode_str; @@ -57,7 +57,7 @@ python_string_to_unicode (PyObject *obj) unicode_str = NULL; } - return unicode_str; + return gdbpy_ref<> (unicode_str); } /* Returns a newly allocated string with the contents of the given unicode @@ -88,11 +88,11 @@ unicode_to_encoded_string (PyObject *unicode_str, const char *charset) object converted to a named charset. If an error occurs during the conversion, NULL will be returned and a python exception will be set. */ -static PyObject * +static gdbpy_ref<> unicode_to_encoded_python_string (PyObject *unicode_str, const char *charset) { /* Translate string to named charset. */ - return PyUnicode_AsEncodedString (unicode_str, charset, NULL); + return gdbpy_ref<> (PyUnicode_AsEncodedString (unicode_str, charset, NULL)); } /* Returns a newly allocated string with the contents of the given @@ -110,7 +110,7 @@ unicode_to_target_string (PyObject *unicode_str) object converted to the target's charset. If an error occurs during the conversion, NULL will be returned and a python exception will be set. */ -static PyObject * +static gdbpy_ref<> unicode_to_target_python_string (PyObject *unicode_str) { return unicode_to_encoded_python_string (unicode_str, @@ -123,7 +123,7 @@ unicode_to_target_python_string (PyObject *unicode_str) gdb::unique_xmalloc_ptr<char> python_string_to_target_string (PyObject *obj) { - gdbpy_ref<> str (python_string_to_unicode (obj)); + gdbpy_ref<> str = python_string_to_unicode (obj); if (str == NULL) return NULL; @@ -135,12 +135,12 @@ python_string_to_target_string (PyObject *obj) set. In Python 3, the returned object is a "bytes" object (not a string). */ -PyObject * +gdbpy_ref<> python_string_to_target_python_string (PyObject *obj) { - gdbpy_ref<> str (python_string_to_unicode (obj)); + gdbpy_ref<> str = python_string_to_unicode (obj); if (str == NULL) - return NULL; + return str; return unicode_to_target_python_string (str.get ()); } @@ -151,7 +151,7 @@ python_string_to_target_python_string (PyObject *obj) gdb::unique_xmalloc_ptr<char> python_string_to_host_string (PyObject *obj) { - gdbpy_ref<> str (python_string_to_unicode (obj)); + gdbpy_ref<> str = python_string_to_unicode (obj); if (str == NULL) return NULL; @@ -160,10 +160,11 @@ python_string_to_host_string (PyObject *obj) /* Convert a host string to a python string. */ -PyObject * +gdbpy_ref<> host_string_to_python_string (const char *str) { - return PyString_Decode (str, strlen (str), host_charset (), NULL); + return gdbpy_ref<> (PyString_Decode (str, strlen (str), host_charset (), + NULL)); } /* Return true if OBJ is a Python string or unicode object, false |