Beispiel #1
0
void gdb_mi_result_free(struct gdb_mi_result *res, gboolean next)
{
	if (! res)
		return;
	g_free(res->var);
	gdb_mi_value_free(res->val);
	if (next)
		gdb_mi_result_free(res->next, next);
	g_free(res);
}
Beispiel #2
0
/* parses: cstring | list | tuple
 * Actually, this is more permissive and allows mixed tuples/lists */
static struct gdb_mi_value *parse_value(const gchar **p)
{
	struct gdb_mi_value *val = g_malloc0(sizeof *val);
	if (**p == '"')
	{
		val->type = GDB_MI_VAL_STRING;
		val->string = parse_cstring(p);
	}
	else if (**p == '{' || **p == '[')
	{
		struct gdb_mi_result *prev = NULL;
		val->type = GDB_MI_VAL_LIST;
		gchar end = **p == '{' ? '}' : ']';
		(*p)++;
		while (**p && **p != end)
		{
			struct gdb_mi_result *item = g_malloc0(sizeof *item);
			while (g_ascii_isspace(**p)) (*p)++;
			if ((item->val = parse_value(p)) ||
				parse_result(item, p))
			{
				if (prev)
					prev->next = item;
				else
					val->list = item;
				prev = item;
			}
			else
			{
				gdb_mi_result_free(item, TRUE);
				break;
			}
			while (g_ascii_isspace(**p)) (*p)++;
			if (**p != ',') break;
			(*p)++;
		}
		if (**p == end)
			(*p)++;
	}
	else
	{
		gdb_mi_value_free(val);
		val = NULL;
	}
	return val;
}