From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 18/31] Use ui_file_as_string in gdb/python/
Date: Wed, 19 Oct 2016 01:21:00 -0000 [thread overview]
Message-ID: <1476839539-8374-19-git-send-email-palves@redhat.com> (raw)
In-Reply-To: <1476839539-8374-1-git-send-email-palves@redhat.com>
gdb/ChangeLog:
yyyy-mm-yy Pedro Alves <palves@redhat.com>
* python/py-arch.c (archpy_disassemble): Use ui_file_as_string and
std::string.
* python/py-breakpoint.c (bppy_get_commands): Use
ui_file_as_string and std::string.
* python/py-frame.c (frapy_str): Likewise.
* python/py-type.c (typy_str): Likewise.
* python/py-unwind.c (unwind_infopy_str): Likewise.
* python/py-value.c (valpy_str): Likewise.
---
gdb/python/py-arch.c | 10 +++++-----
gdb/python/py-breakpoint.c | 8 +++-----
gdb/python/py-frame.c | 8 ++------
gdb/python/py-type.c | 10 ++++------
gdb/python/py-unwind.c | 7 ++-----
gdb/python/py-value.c | 7 +++----
6 files changed, 19 insertions(+), 31 deletions(-)
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index 4a2dcbf..60cc5a9 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -198,7 +198,6 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
|| (end_obj == NULL && count_obj == NULL && pc == start);)
{
int insn_len = 0;
- char *as = NULL;
struct ui_file *memfile = mem_fileopen ();
PyObject *insn_dict = PyDict_New ();
@@ -232,18 +231,20 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
}
END_CATCH
- as = ui_file_xstrdup (memfile, NULL);
+ std::string as = ui_file_as_string (memfile);
+
if (PyDict_SetItemString (insn_dict, "addr",
gdb_py_long_from_ulongest (pc))
|| PyDict_SetItemString (insn_dict, "asm",
- PyString_FromString (*as ? as : "<unknown>"))
+ PyString_FromString (!as.empty ()
+ ? as.c_str ()
+ : "<unknown>"))
|| PyDict_SetItemString (insn_dict, "length",
PyInt_FromLong (insn_len)))
{
Py_DECREF (result_list);
ui_file_delete (memfile);
- xfree (as);
return NULL;
}
@@ -251,7 +252,6 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
pc += insn_len;
i++;
ui_file_delete (memfile);
- xfree (as);
}
return result_list;
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 80f5d1f..e61cbcd 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -487,9 +487,8 @@ bppy_get_commands (PyObject *self, void *closure)
struct breakpoint *bp = self_bp->bp;
long length;
struct ui_file *string_file;
- struct cleanup *chain;
PyObject *result;
- char *cmdstr;
+ struct cleanup *chain;
BPPY_REQUIRE_VALID (self_bp);
@@ -514,9 +513,8 @@ bppy_get_commands (PyObject *self, void *closure)
END_CATCH
ui_out_redirect (current_uiout, NULL);
- cmdstr = ui_file_xstrdup (string_file, &length);
- make_cleanup (xfree, cmdstr);
- result = host_string_to_python_string (cmdstr);
+ std::string cmdstr = ui_file_as_string (string_file);
+ result = host_string_to_python_string (cmdstr.c_str ());
do_cleanups (chain);
return result;
}
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 6bdac08..a66f885 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -80,17 +80,13 @@ frame_object_to_frame_info (PyObject *obj)
static PyObject *
frapy_str (PyObject *self)
{
- char *s;
PyObject *result;
struct ui_file *strfile;
strfile = mem_fileopen ();
fprint_frame_id (strfile, ((frame_object *) self)->frame_id);
- s = ui_file_xstrdup (strfile, NULL);
- result = PyString_FromString (s);
- xfree (s);
-
- return result;
+ std::string s = ui_file_as_string (strfile);
+ return PyString_FromString (s.c_str ());
}
/* Implementation of gdb.Frame.is_valid (self) -> Boolean.
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 03cc8d9..da9dadd 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1010,8 +1010,7 @@ typy_template_argument (PyObject *self, PyObject *args)
static PyObject *
typy_str (PyObject *self)
{
- char *thetype = NULL;
- long length = 0;
+ std::string thetype;
PyObject *result;
TRY
@@ -1025,18 +1024,17 @@ typy_str (PyObject *self)
LA_PRINT_TYPE (type_object_to_type (self), "", stb, -1, 0,
&type_print_raw_options);
- thetype = ui_file_xstrdup (stb, &length);
+ thetype = ui_file_as_string (stb);
do_cleanups (old_chain);
}
CATCH (except, RETURN_MASK_ALL)
{
- xfree (thetype);
GDB_PY_HANDLE_EXCEPTION (except);
}
END_CATCH
- result = PyUnicode_Decode (thetype, length, host_charset (), NULL);
- xfree (thetype);
+ result = PyUnicode_Decode (thetype.c_str (), thetype.length (),
+ host_charset (), NULL);
return result;
}
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index cc685ae..3963cd0 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -238,12 +238,9 @@ unwind_infopy_str (PyObject *self)
}
fprintf_unfiltered (strfile, ")");
}
- {
- char *s = ui_file_xstrdup (strfile, NULL);
- result = PyString_FromString (s);
- xfree (s);
- }
+ std::string s = ui_file_as_string (strfile);
+ result = PyString_FromString (s.c_str ());
ui_file_delete (strfile);
return result;
}
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 46683b8..e326005 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -895,7 +895,7 @@ valpy_call (PyObject *self, PyObject *args, PyObject *keywords)
static PyObject *
valpy_str (PyObject *self)
{
- char *s = NULL;
+ std::string s;
PyObject *result;
struct value_print_options opts;
@@ -909,7 +909,7 @@ valpy_str (PyObject *self)
common_val_print (((value_object *) self)->value, stb, 0,
&opts, python_language);
- s = ui_file_xstrdup (stb, NULL);
+ s = ui_file_as_string (stb);
do_cleanups (old_chain);
}
@@ -919,8 +919,7 @@ valpy_str (PyObject *self)
}
END_CATCH
- result = PyUnicode_Decode (s, strlen (s), host_charset (), NULL);
- xfree (s);
+ result = PyUnicode_Decode (s.c_str (), s.length (), host_charset (), NULL);
return result;
}
--
2.5.5
next prev parent reply other threads:[~2016-10-19 1:21 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-19 1:13 [PATCH v2 00/31] More cleanup elimination & unlimited args to user-defined funcs Pedro Alves
2016-10-19 1:12 ` [PATCH v2 12/31] Use ui_file_as_string in gdb/utils.c Pedro Alves
2016-10-19 1:12 ` [PATCH v2 19/31] Use ui_file_as_string in gdb/remote.c Pedro Alves
2016-10-19 1:12 ` [PATCH v2 01/31] Introduce string_printf Pedro Alves
2016-10-19 13:43 ` Trevor Saunders
2016-10-19 14:41 ` Pedro Alves
2016-10-19 17:18 ` Simon Marchi
2016-10-19 21:02 ` Pedro Alves
2016-11-08 15:35 ` Pedro Alves
2016-10-19 1:12 ` [PATCH v2 20/31] Use ui_file_as_string in gdb/cli/cli-setshow.c Pedro Alves
2016-10-19 1:12 ` [PATCH v2 07/31] Clean up tracepoint.h/c:collection_list Pedro Alves
2016-10-19 1:12 ` [PATCH v2 24/31] Use ui_file_as_string in gdb/ada-lang.c Pedro Alves
2016-10-19 1:12 ` [PATCH v2 06/31] Introduce ui_file_as_string Pedro Alves
2016-10-19 1:12 ` [PATCH v2 21/31] Use ui_file_as_string in gdb/compile/ Pedro Alves
2016-10-19 23:08 ` Simon Marchi
2016-10-19 23:48 ` Pedro Alves
2016-10-20 3:17 ` Simon Marchi
2016-10-20 12:13 ` Pedro Alves
2016-10-19 1:12 ` [PATCH v2 22/31] Use ui_file_as_string in gdb/c-exp.y Pedro Alves
2016-10-19 1:13 ` [PATCH v2 02/31] cli/cli-script.c: Remove some dead NULL checks Pedro Alves
2016-10-19 17:24 ` Simon Marchi
2016-10-19 21:18 ` Pedro Alves
2016-10-19 1:13 ` [PATCH v2 31/31] Support an "unlimited" number of user-defined arguments Pedro Alves
2016-10-19 6:29 ` Eli Zaretskii
2016-10-19 11:33 ` Philipp Rudo
2016-10-19 12:47 ` Pedro Alves
2016-10-19 17:40 ` Philipp Rudo
2016-10-19 17:45 ` Pedro Alves
2016-11-08 15:41 ` Pedro Alves
2016-10-19 1:13 ` [PATCH v2 08/31] Use ui_file_as_string in dwarf2_compute_name Pedro Alves
2016-10-19 1:13 ` [PATCH v2 15/31] Use ui_file_as_string in execute_command_to_string Pedro Alves
2016-10-19 1:13 ` [PATCH v2 14/31] Use ui_file_as_string in gdb/guile/ Pedro Alves
2016-10-19 1:13 ` [PATCH v2 03/31] breakpoint.c:commands_command_1 constification and cleanup Pedro Alves
2016-10-19 1:13 ` [PATCH v2 29/31] 'struct agent_expr *' -> unique_ptr<agent_expr> Pedro Alves
2016-10-19 23:19 ` Simon Marchi
2016-10-19 23:58 ` Pedro Alves
2016-10-19 1:13 ` [PATCH v2 27/31] Use ui_file_as_string in gdb/language.c Pedro Alves
2016-10-19 1:13 ` [PATCH v2 23/31] Use ui_file_as_string in gdbarch.sh/gdbarch.c Pedro Alves
2016-10-19 1:13 ` [PATCH v2 26/31] Use ui_file_as_string in gdb/rust-lang.c Pedro Alves
2016-10-19 1:17 ` [PATCH v2 09/31] Use ui_file_as_string in gdb/xtensa-tdep.c Pedro Alves
2016-10-19 1:17 ` [PATCH v2 10/31] Use ui_file_as_string in gdb/ada-valprint.c Pedro Alves
2016-10-19 1:17 ` [PATCH v2 11/31] Use ui_file_as_string in gdb/ui-out.c Pedro Alves
2016-10-19 1:17 ` [PATCH v2 25/31] Use ui_file_as_string in gdb/infrun.c Pedro Alves
2016-10-19 1:18 ` [PATCH v2 05/31] 'struct expression *' -> gdb::unique_xmalloc_ptr<expression> Pedro Alves
2016-10-19 18:45 ` Simon Marchi
2016-10-19 21:50 ` Pedro Alves
2016-10-19 22:25 ` Simon Marchi
2016-10-19 22:36 ` Pedro Alves
2016-10-19 1:18 ` [PATCH v2 30/31] Eliminate agent_expr_p; VEC -> std::vector in struct bp_target_info Pedro Alves
2016-10-19 1:19 ` [PATCH v2 04/31] cli-script.c: Simplify using std::string, eliminate cleanups Pedro Alves
2016-10-19 18:25 ` Simon Marchi
2016-10-19 21:45 ` Pedro Alves
2016-10-19 1:21 ` [PATCH v2 17/31] Use ui_file_as_string in gdb/printcmd.c Pedro Alves
2016-10-19 1:21 ` Pedro Alves [this message]
2016-10-19 1:21 ` [PATCH v2 16/31] Use ui_file_as_string in gdb/top.c Pedro Alves
2016-10-19 1:21 ` [PATCH v2 13/31] Use ui_file_as_string in gdb/arm-tdep.c Pedro Alves
2016-10-19 22:54 ` Simon Marchi
2016-10-20 13:08 ` [PATCH v2 28/31] Use ui_file_as_string throughout more Pedro Alves
2017-02-23 10:23 ` Yao Qi
2017-02-23 10:53 ` Pedro Alves
2017-02-23 10:35 ` Yao Qi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1476839539-8374-19-git-send-email-palves@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).