From b4be9fadea469e2c937c81a8f1d3243206f9bcfc Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 21 May 2018 12:35:59 -0600 Subject: Use unique_xmalloc_ptr for read_string This changes read_string's "buffer" out-parameter to be a unique_xmalloc_ptr, then updates the users. This allows for the removal of some cleanups. I chose unique_xmalloc_ptr rather than byte_vector here due to the way Guile unwinding seems to work. Tested by the buildbot. gdb/ChangeLog 2018-06-18 Tom Tromey * valprint.h (read_string): Update. * valprint.c (read_string): Change type of "buffer". (val_print_string): Update. * python/py-value.c (valpy_string): Update. * language.h (struct language_defn) : Change type of "buffer". (default_get_string, c_get_string): Update. * language.c (default_get_string): Change type of "buffer". * guile/scm-value.c (gdbscm_value_to_string): Update. * c-lang.c (c_get_string): Change type of "buffer". --- gdb/python/py-value.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'gdb/python') diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 30a0082..1b880fa 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -517,9 +517,8 @@ static PyObject * valpy_string (PyObject *self, PyObject *args, PyObject *kw) { int length = -1; - gdb_byte *buffer; + gdb::unique_xmalloc_ptr buffer; struct value *value = ((value_object *) self)->value; - PyObject *unicode; const char *encoding = NULL; const char *errors = NULL; const char *user_encoding = NULL; @@ -542,12 +541,9 @@ valpy_string (PyObject *self, PyObject *args, PyObject *kw) END_CATCH encoding = (user_encoding && *user_encoding) ? user_encoding : la_encoding; - unicode = PyUnicode_Decode ((const char *) buffer, - length * TYPE_LENGTH (char_type), - encoding, errors); - xfree (buffer); - - return unicode; + return PyUnicode_Decode ((const char *) buffer.get (), + length * TYPE_LENGTH (char_type), + encoding, errors); } /* A helper function that implements the various cast operators. */ -- cgit v1.1