diff --git a/ChangeLog b/ChangeLog index ef68200eb..96143f37e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2007-10-27 Emmanuele Bassi + + * 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 * clutter/clutter-script.[ch]: Slight API change in the diff --git a/clutter/json/json-node.c b/clutter/json/json-node.c index 61bb64470..74fbf58ec 100644 --- a/clutter/json/json-node.c +++ b/clutter/json/json-node.c @@ -332,11 +332,13 @@ json_node_free (JsonNode *node) switch (node->type) { case JSON_NODE_OBJECT: - json_object_unref (node->data.object); + if (node->data.object) + json_object_unref (node->data.object); break; case JSON_NODE_ARRAY: - json_array_unref (node->data.array); + if (node->data.array) + json_array_unref (node->data.array); break; case JSON_NODE_VALUE: diff --git a/clutter/json/json-parser.c b/clutter/json/json-parser.c index 4e3961100..1ced2b224 100644 --- a/clutter/json/json-parser.c +++ b/clutter/json/json-parser.c @@ -49,6 +49,8 @@ struct _JsonParserPrivate JsonNode *current_node; GScanner *scanner; + + GError *last_error; }; static const GScannerConfig json_scanner_config = @@ -144,6 +146,12 @@ json_parser_dispose (GObject *gobject) 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); } @@ -543,7 +551,10 @@ json_parse_object (JsonParser *parser, if (token != G_TOKEN_NONE) { g_free (name); - json_node_free (node); + + if (node) + json_node_free (node); + json_object_unref (object); return token; } @@ -628,7 +639,7 @@ json_parse_object (JsonParser *parser, break; default: - return G_TOKEN_RIGHT_BRACE; + return G_TOKEN_SYMBOL; } if (node) @@ -717,9 +728,8 @@ json_scanner_msg_handler (GScanner *scanner, scanner->line, message); + parser->priv->last_error = error; g_signal_emit (parser, parser_signals[ERROR], 0, error); - - g_error_free (error); } else 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++) if (symbols[i].token == expected_token) - msg = (gchar *) symbol_names + symbols[i].name_offset; + symbol_name = symbol_names + symbols[i].name_offset; if (msg) - msg = g_strconcat ("e.g. `", msg, "'", NULL); + msg = g_strconcat ("e.g. `", symbol_name, "'", NULL); } if (scanner->token > JSON_TOKEN_INVALID && @@ -895,7 +905,13 @@ json_parser_load_from_data (JsonParser *parser, NULL, "keyword", symbol_name, msg, 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 * GScanner is relayed in the ::error signal */ @@ -904,7 +920,7 @@ json_parser_load_from_data (JsonParser *parser, "Invalid token `%s' found: expecting %s", symbol_name ? symbol_name : "???", msg ? msg : "unknown"); - +#endif retval = FALSE; g_free (msg); diff --git a/tests/test-script.json b/tests/test-script.json index 069154582..868b9e9a1 100644 --- a/tests/test-script.json +++ b/tests/test-script.json @@ -22,6 +22,8 @@ "id" : "green-button", "type" : "ClutterRectangle", "color" : "#00ff00ff", + "border-width" : 5, + "border-color" : "#00cc00ff", "x" : 200, "y" : 50, "width" : 100,