This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Fix FIXME: xstrdup should not be here
- From: Yao Qi <yao at codesourcery dot com>
- To: Mark Kettenis <mark dot kettenis at xs4all dot nl>
- Cc: <gdb-patches at sourceware dot org>
- Date: Mon, 16 Sep 2013 21:13:22 +0800
- Subject: Re: [PATCH] Fix FIXME: xstrdup should not be here
- Authentication-results: sourceware.org; auth=none
- References: <1377826046-21218-1-git-send-email-yao at codesourcery dot com> <522E84B9 dot 10502 at codesourcery dot com> <5232B567 dot 9020202 at codesourcery dot com> <201309130752 dot r8D7q1EX023001 at glazunov dot sibelius dot xs4all dot nl>
On 09/13/2013 03:52 PM, Mark Kettenis wrote:
> If you do this, you should drop the const from the
> install_dynamic_child() prototype instead of adding the (char *) cast.
Looks I've been confused by the usage of const, :). Here is an updated
one.
--
Yao (éå)
gdb:
2013-09-16 Yao Qi <yao@codesourcery.com>
* varobj.c (create_child_with_value): Remove 'const' from the
type of parameter 'name'.
(varobj_add_child): Likewise.
(install_dynamic_child): Remove 'const' from the type of
parameter 'name'.
(varobj_add_child): Likewise.
(create_child_with_value): Likewise. Update comments. Don't
duplicate 'name'.
(update_dynamic_varobj_children): Duplicate 'name'
and pass it to install_dynamic_child.
---
gdb/varobj.c | 18 +++++++++---------
1 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/gdb/varobj.c b/gdb/varobj.c
index ced3e2d..cd75a32 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -245,7 +245,7 @@ static void uninstall_variable (struct varobj *);
static struct varobj *create_child (struct varobj *, int, char *);
static struct varobj *
-create_child_with_value (struct varobj *parent, int index, const char *name,
+create_child_with_value (struct varobj *parent, int index, char *name,
struct value *value);
/* Utility routines */
@@ -304,7 +304,7 @@ static int is_root_p (struct varobj *var);
#if HAVE_PYTHON
static struct varobj *varobj_add_child (struct varobj *var,
- const char *name,
+ char *name,
struct value *value);
#endif /* HAVE_PYTHON */
@@ -1031,7 +1031,7 @@ install_dynamic_child (struct varobj *var,
VEC (varobj_p) **unchanged,
int *cchanged,
int index,
- const char *name,
+ char *name,
struct value *value)
{
if (VEC_length (varobj_p, var->children) < index + 1)
@@ -1225,7 +1225,8 @@ update_dynamic_varobj_children (struct varobj *var,
can_mention ? type_changed : NULL,
can_mention ? new : NULL,
can_mention ? unchanged : NULL,
- can_mention ? cchanged : NULL, i, name, v);
+ can_mention ? cchanged : NULL, i,
+ xstrdup (name), v);
do_cleanups (inner);
}
else
@@ -1344,7 +1345,7 @@ varobj_list_children (struct varobj *var, int *from, int *to)
#if HAVE_PYTHON
static struct varobj *
-varobj_add_child (struct varobj *var, const char *name, struct value *value)
+varobj_add_child (struct varobj *var, char *name, struct value *value)
{
varobj_p v = create_child_with_value (var,
VEC_length (varobj_p, var->children),
@@ -2431,7 +2432,7 @@ is_anonymous_child (struct varobj *child)
}
static struct varobj *
-create_child_with_value (struct varobj *parent, int index, const char *name,
+create_child_with_value (struct varobj *parent, int index, char *name,
struct value *value)
{
struct varobj *child;
@@ -2439,9 +2440,8 @@ create_child_with_value (struct varobj *parent, int index, const char *name,
child = new_variable ();
- /* Name is allocated by name_of_child. */
- /* FIXME: xstrdup should not be here. */
- child->name = xstrdup (name);
+ /* NAME is allocated by caller. */
+ child->name = name;
child->index = index;
child->parent = parent;
child->root = parent->root;
--
1.7.7.6