2007-10-27 Emmanuele Bassi <ebassi@openedhand.com>

* clutter/json/json-parser.c:
	(json_scanner_msg_handler): Set the GError to be returned by
	the parsing functions into the GScanner error message handler.

	(json_parser_object): Return the symbol token in case we have
	a parse error after the member name.

	(json_parser_load_from_data): Propagate the error set in the
	message handler, if any.

	* clutter/json/json-node.c (json_node_free): Unref the objects
	only if are set, to avoid a couple of needless criticals we
	get on error.

	* tests/test-script.json: More properties.
This commit is contained in:
Emmanuele Bassi 2007-10-27 19:49:39 +00:00
parent 35132fb5de
commit d42153dc69
4 changed files with 48 additions and 10 deletions

View File

@ -1,3 +1,21 @@
2007-10-27 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/json/json-parser.c:
(json_scanner_msg_handler): Set the GError to be returned by
the parsing functions into the GScanner error message handler.
(json_parser_object): Return the symbol token in case we have
a parse error after the member name.
(json_parser_load_from_data): Propagate the error set in the
message handler, if any.
* clutter/json/json-node.c (json_node_free): Unref the objects
only if are set, to avoid a couple of needless criticals we
get on error.
* tests/test-script.json: More properties.
2007-10-27 Emmanuele Bassi <ebassi@openedhand.com> 2007-10-27 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/clutter-script.[ch]: Slight API change in the * clutter/clutter-script.[ch]: Slight API change in the

View File

@ -332,11 +332,13 @@ json_node_free (JsonNode *node)
switch (node->type) switch (node->type)
{ {
case JSON_NODE_OBJECT: case JSON_NODE_OBJECT:
json_object_unref (node->data.object); if (node->data.object)
json_object_unref (node->data.object);
break; break;
case JSON_NODE_ARRAY: case JSON_NODE_ARRAY:
json_array_unref (node->data.array); if (node->data.array)
json_array_unref (node->data.array);
break; break;
case JSON_NODE_VALUE: case JSON_NODE_VALUE:

View File

@ -49,6 +49,8 @@ struct _JsonParserPrivate
JsonNode *current_node; JsonNode *current_node;
GScanner *scanner; GScanner *scanner;
GError *last_error;
}; };
static const GScannerConfig json_scanner_config = static const GScannerConfig json_scanner_config =
@ -144,6 +146,12 @@ json_parser_dispose (GObject *gobject)
priv->root = NULL; priv->root = NULL;
} }
if (priv->last_error)
{
g_error_free (priv->last_error);
priv->last_error = NULL;
}
G_OBJECT_CLASS (json_parser_parent_class)->dispose (gobject); G_OBJECT_CLASS (json_parser_parent_class)->dispose (gobject);
} }
@ -543,7 +551,10 @@ json_parse_object (JsonParser *parser,
if (token != G_TOKEN_NONE) if (token != G_TOKEN_NONE)
{ {
g_free (name); g_free (name);
json_node_free (node);
if (node)
json_node_free (node);
json_object_unref (object); json_object_unref (object);
return token; return token;
} }
@ -628,7 +639,7 @@ json_parse_object (JsonParser *parser,
break; break;
default: default:
return G_TOKEN_RIGHT_BRACE; return G_TOKEN_SYMBOL;
} }
if (node) if (node)
@ -717,9 +728,8 @@ json_scanner_msg_handler (GScanner *scanner,
scanner->line, scanner->line,
message); message);
parser->priv->last_error = error;
g_signal_emit (parser, parser_signals[ERROR], 0, error); g_signal_emit (parser, parser_signals[ERROR], 0, error);
g_error_free (error);
} }
else else
g_warning ("Line %d: %s", scanner->line, message); g_warning ("Line %d: %s", scanner->line, message);
@ -871,10 +881,10 @@ json_parser_load_from_data (JsonParser *parser,
{ {
for (i = 0; i < n_symbols; i++) for (i = 0; i < n_symbols; i++)
if (symbols[i].token == expected_token) if (symbols[i].token == expected_token)
msg = (gchar *) symbol_names + symbols[i].name_offset; symbol_name = symbol_names + symbols[i].name_offset;
if (msg) if (msg)
msg = g_strconcat ("e.g. `", msg, "'", NULL); msg = g_strconcat ("e.g. `", symbol_name, "'", NULL);
} }
if (scanner->token > JSON_TOKEN_INVALID && if (scanner->token > JSON_TOKEN_INVALID &&
@ -896,6 +906,12 @@ json_parser_load_from_data (JsonParser *parser,
symbol_name, msg, symbol_name, msg,
TRUE); TRUE);
if (parser->priv->last_error)
{
g_propagate_error (error, parser->priv->last_error);
parser->priv->last_error = NULL;
}
#if 0
/* we set a generic error here; the message from /* we set a generic error here; the message from
* GScanner is relayed in the ::error signal * GScanner is relayed in the ::error signal
*/ */
@ -904,7 +920,7 @@ json_parser_load_from_data (JsonParser *parser,
"Invalid token `%s' found: expecting %s", "Invalid token `%s' found: expecting %s",
symbol_name ? symbol_name : "???", symbol_name ? symbol_name : "???",
msg ? msg : "unknown"); msg ? msg : "unknown");
#endif
retval = FALSE; retval = FALSE;
g_free (msg); g_free (msg);

View File

@ -22,6 +22,8 @@
"id" : "green-button", "id" : "green-button",
"type" : "ClutterRectangle", "type" : "ClutterRectangle",
"color" : "#00ff00ff", "color" : "#00ff00ff",
"border-width" : 5,
"border-color" : "#00cc00ff",
"x" : 200, "x" : 200,
"y" : 50, "y" : 50,
"width" : 100, "width" : 100,