From d42153dc690a83446007e8217cf12b7cd94ab70e Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Sat, 27 Oct 2007 19:49:39 +0000 Subject: [PATCH] 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. --- ChangeLog | 18 ++++++++++++++++++ clutter/json/json-node.c | 6 ++++-- clutter/json/json-parser.c | 32 ++++++++++++++++++++++++-------- tests/test-script.json | 2 ++ 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index ef68200..96143f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,23 @@ 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 clutter_script_get_objects() function: now it takes object name/object return location pairs and returns the diff --git a/clutter/json/json-node.c b/clutter/json/json-node.c index 61bb644..74fbf58 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 4e39611..1ced2b2 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 0691545..868b9e9 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, -- 2.7.4