From: Tom Tromey Date: Sat, 12 Nov 2016 18:48:48 +0000 (-0700) Subject: Change type of encoding argument to gdbpy_extract_lazy_string X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1eba63835ea23cbae6059c076db985a47e39ce24;p=binutils-gdb.git Change type of encoding argument to gdbpy_extract_lazy_string This changes gdbpy_extract_lazy_string's "encoding" argument to be a unique_xmalloc_ptr. I chose this rather than std::string because it can sometimes be NULL. 2017-01-10 Tom Tromey * python/py-prettyprint.c (print_string_repr, print_children): Update. * python/py-lazy-string.c (gdbpy_extract_lazy_string): Change type of "encoding". * varobj.c (varobj_value_get_print_value): Update. * python/python-internal.h (gdbpy_extract_lazy_string): Update. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4cb6ac6e6be..8eb4390e6ca 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2017-01-10 Tom Tromey + + * python/py-prettyprint.c (print_string_repr, print_children): + Update. + * python/py-lazy-string.c (gdbpy_extract_lazy_string): Change type + of "encoding". + * varobj.c (varobj_value_get_print_value): Update. + * python/python-internal.h (gdbpy_extract_lazy_string): Update. + 2017-01-10 Tom Tromey * varobj.c (varobj_get_display_hint) diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c index 14575bff85a..4af4566ef64 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 *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 a4bdf87a41a..fb3d9b1f14a 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 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 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 41275bb7d3e..f2314861907 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -583,7 +583,8 @@ gdb::unique_xmalloc_ptr 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 *encoding); int gdbpy_is_value_object (PyObject *obj); diff --git a/gdb/varobj.c b/gdb/varobj.c index 43acc31bfaf..d75c9b84934 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -2413,7 +2413,7 @@ varobj_value_get_print_value (struct value *value, struct value_print_options opts; struct type *type = NULL; long len = 0; - char *encoding = NULL; + gdb::unique_xmalloc_ptr encoding; /* Initialize it just to avoid a GCC false warning. */ CORE_ADDR str_addr = 0; int string_print = 0; @@ -2464,7 +2464,6 @@ varobj_value_get_print_value (struct value *value, { gdbpy_extract_lazy_string (output, &str_addr, &type, &len, &encoding); - make_cleanup (free_current_contents, &encoding); string_print = 1; } else @@ -2520,11 +2519,11 @@ varobj_value_get_print_value (struct value *value, /* If the THEVALUE has contents, it is a regular string. */ if (!thevalue.empty ()) LA_PRINT_STRING (stb, type, (gdb_byte *) thevalue.c_str (), - len, encoding, 0, &opts); + len, encoding.get (), 0, &opts); else if (string_print) /* Otherwise, if string_print is set, and it is not a regular string, it is a lazy string. */ - val_print_string (type, encoding, str_addr, len, stb, &opts); + val_print_string (type, encoding.get (), str_addr, len, stb, &opts); else /* All other cases. */ common_val_print (value, stb, 0, &opts, current_language);