aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-lazy-string.c9
-rw-r--r--gdb/python/py-prettyprint.c10
-rw-r--r--gdb/python/python-internal.h3
3 files changed, 10 insertions, 12 deletions
diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index 14575bf..4af4566 100644
--- a/gdb/python/py-lazy-string.c
+++ b/gdb/python/py-lazy-string.c
@@ -180,14 +180,13 @@ gdbpy_is_lazy_string (PyObject *result)
}
/* Extract the parameters from the lazy string object STRING.
- ENCODING will either be set to NULL, or will be allocated with
- xmalloc, in which case the callers is responsible for freeing
- it. */
+ ENCODING may be set to NULL, if no encoding is found. */
void
gdbpy_extract_lazy_string (PyObject *string, CORE_ADDR *addr,
struct type **str_type,
- long *length, char **encoding)
+ long *length,
+ gdb::unique_xmalloc_ptr<char> *encoding)
{
lazy_string_object *lazy;
@@ -198,7 +197,7 @@ gdbpy_extract_lazy_string (PyObject *string, CORE_ADDR *addr,
*addr = lazy->address;
*str_type = lazy->type;
*length = lazy->length;
- *encoding = lazy->encoding ? xstrdup (lazy->encoding) : NULL;
+ encoding->reset (lazy->encoding ? xstrdup (lazy->encoding) : NULL);
}
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index a4bdf87..fb3d9b1 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -301,15 +301,14 @@ print_string_repr (PyObject *printer, const char *hint,
CORE_ADDR addr;
long length;
struct type *type;
- char *encoding = NULL;
+ gdb::unique_xmalloc_ptr<char> encoding;
struct value_print_options local_opts = *options;
- make_cleanup (free_current_contents, &encoding);
gdbpy_extract_lazy_string (py_str, &addr, &type,
&length, &encoding);
local_opts.addressprint = 0;
- val_print_string (type, encoding, addr, (int) length,
+ val_print_string (type, encoding.get (), addr, (int) length,
stream, &local_opts);
}
else
@@ -610,14 +609,13 @@ print_children (PyObject *printer, const char *hint,
CORE_ADDR addr;
struct type *type;
long length;
- char *encoding = NULL;
+ gdb::unique_xmalloc_ptr<char> encoding;
struct value_print_options local_opts = *options;
- make_cleanup (free_current_contents, &encoding);
gdbpy_extract_lazy_string (py_v, &addr, &type, &length, &encoding);
local_opts.addressprint = 0;
- val_print_string (type, encoding, addr, (int) length, stream,
+ val_print_string (type, encoding.get (), addr, (int) length, stream,
&local_opts);
}
else if (gdbpy_is_string (py_v))
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 41275bb..f231486 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -583,7 +583,8 @@ gdb::unique_xmalloc_ptr<char> gdbpy_exception_to_string (PyObject *ptype,
int gdbpy_is_lazy_string (PyObject *result);
void gdbpy_extract_lazy_string (PyObject *string, CORE_ADDR *addr,
struct type **str_type,
- long *length, char **encoding);
+ long *length,
+ gdb::unique_xmalloc_ptr<char> *encoding);
int gdbpy_is_value_object (PyObject *obj);