old-cross-binutils/gdb/varobj-iter.h
Yao Qi 827f100cee Iterate over 'struct varobj_item' instead of PyObject
In previous patch, "saved_item" is still a PyOjbect and iteration is
still performed over PyObject.  This patch continues to decouple
iteration from python code, so it changes its type to "struct
varobj_item *", so that the iterator itself is independent of python.

 V2:
 - Call varobj_delete_iter in free_variable.
 - Fix changelog entries.
 - Use XNEW.

 V3:
 - Return NULL early in py_varobj_iter_next if gdb_python_initialized
   is false.

gdb:

2014-06-12  Pedro Alves  <pedro@codesourcery.com>
	    Yao Qi  <yao@codesourcery.com>

	* python/py-varobj.c (py_varobj_iter_next): Return NULL if
	gdb_python_initialized is false.  Move some code from varobj.c.
	* varobj-iter.h (struct varobj_item): Moved from varobj.c.
	* varobj.c: Move "varobj-iter.h" inclusion earlier.
	(struct varobj_item): Moved to varobj-iter.h".
	(varobj_clear_saved_item): New function.
	(update_dynamic_varobj_children): Move python-related code to
	py-varobj.c.
	(free_variable): Call varobj_clear_saved_item and
	varobj_iter_delete.
2014-06-12 15:27:19 +08:00

72 lines
2 KiB
C

/* Iterator of varobj.
Copyright (C) 2013-2014 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* A node or item of varobj, composed of the name and the value. */
typedef struct varobj_item
{
/* Name of this item. */
char *name;
/* Value of this item. */
struct value *value;
} varobj_item;
struct varobj_iter_ops;
/* A dynamic varobj iterator "class". */
struct varobj_iter
{
/* The 'vtable'. */
const struct varobj_iter_ops *ops;
/* The varobj this iterator is listing children for. */
struct varobj *var;
/* The next raw index we will try to check is available. If it is
equal to number_of_children, then we've already iterated the
whole set. */
int next_raw_index;
};
/* The vtable of the varobj iterator class. */
struct varobj_iter_ops
{
/* Destructor. Releases everything from SELF (but not SELF
itself). */
void (*dtor) (struct varobj_iter *self);
/* Returns the next object or NULL if it has reached the end. */
varobj_item *(*next) (struct varobj_iter *self);
};
/* Returns the next varobj or NULL if it has reached the end. */
#define varobj_iter_next(ITER) (ITER)->ops->next (ITER)
/* Delete a varobj_iter object. */
#define varobj_iter_delete(ITER) \
do \
{ \
if ((ITER) != NULL) \
{ \
(ITER)->ops->dtor (ITER); \
xfree (ITER); \
} \
} while (0)