diff options
author | Pedro Alves <palves@redhat.com> | 2016-10-28 23:08:08 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2016-11-17 03:10:00 +0000 |
commit | 3d4ed53ca597f71c72ff0db995468578482a0ee0 (patch) | |
tree | 23c91cebc43c07ae98f0a494642734aa8abc83f5 /gdb/python/py-type.c | |
parent | 05c10af4c15d9501046f6740cdf1173fbd9c3a2e (diff) | |
download | binutils-gdb-3d4ed53ca597f71c72ff0db995468578482a0ee0.tar.gz |
Eliminate make_cleanup_ui_file_deleteusers/palves/cxx-eliminate-cleanups
And now that ui_file_as_string is in, let's eliminate it. :-)
Makes ui_file a real C++ hierarchy. mem_fileopen is replaced with a
new string_file class that is treated as a value class created on the
stack. This alone eliminates most make_cleanup_ui_file_delete calls,
and, simplifies code a whole lot (diffstat shows almost 1k loc
dropped.)
string_file has a string() method that gives you a direct reference to
the internal std::string. This is what replaces old (well, new)
ui_file_as_string, which used to alway return a new copy of the same
data the stream had inside.. With direct access via a writable
reference, we can instead move the string out of the string_stream.
Note I needed a tweak on scoped_restore. That one should probably be
split out to a separate patch.
This exposed the need to make use of gnulib namespace support.
Otherwise, making use of read/write/printf/puts/etc symbol names will
clash on systems where gnulib replaces those functions, due to
'#define foo rpl_foo'.
Diffstat (limited to 'gdb/python/py-type.c')
-rw-r--r-- | gdb/python/py-type.c | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 17fa297960b..94112f06d2c 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -1010,22 +1010,13 @@ typy_template_argument (PyObject *self, PyObject *args) static PyObject * typy_str (PyObject *self) { - std::string thetype; + string_file thetype; PyObject *result; TRY { - struct cleanup *old_chain; - struct ui_file *stb; - - stb = mem_fileopen (); - old_chain = make_cleanup_ui_file_delete (stb); - - LA_PRINT_TYPE (type_object_to_type (self), "", stb, -1, 0, + LA_PRINT_TYPE (type_object_to_type (self), "", &thetype, -1, 0, &type_print_raw_options); - - thetype = ui_file_as_string (stb); - do_cleanups (old_chain); } CATCH (except, RETURN_MASK_ALL) { @@ -1033,10 +1024,8 @@ typy_str (PyObject *self) } END_CATCH - result = PyUnicode_Decode (thetype.c_str (), thetype.length (), - host_charset (), NULL); - - return result; + return PyUnicode_Decode (thetype.c_str (), thetype.size (), + host_charset (), NULL); } /* Implement the richcompare method. */ |