Gitweb links:

...log 
http://git.netsurf-browser.org/libcss.git/shortlog/6cca986e1de413b5caeffd452da929e32ab23bb9
...commit 
http://git.netsurf-browser.org/libcss.git/commit/6cca986e1de413b5caeffd452da929e32ab23bb9
...tree 
http://git.netsurf-browser.org/libcss.git/tree/6cca986e1de413b5caeffd452da929e32ab23bb9

The branch, tlsa/jmb/mq has been updated
       via  6cca986e1de413b5caeffd452da929e32ab23bb9 (commit)
       via  73f9082726ce90eeb7109a95e499163398e98273 (commit)
       via  2ec72552d71e6993dfb43ed6ee956668b5026613 (commit)
       via  843fc213d3f21a8402fcf0358940a8079d8bc927 (commit)
       via  e9c42105dc74a431a36b047852dca4b516d6ca87 (commit)
       via  f3cdd740161f3f401b92e8a849c6e0478dddedb0 (commit)
       via  d5e731f328e14cc8b9898aaa033006df25fc5da5 (commit)
       via  c465688fd50e74a9d2a6a29ffebe52f0a3ac485f (commit)
       via  10dcdc39b751c1a321577f73c077270f16565d6d (commit)
       via  ba291e3f1d245fab22d9bfcf9c3e666cedb47d96 (commit)
      from  2e50ebe6fb3ece6c33d648ca3e222524d79c3999 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/libcss.git/commit/?id=6cca986e1de413b5caeffd452da929e32ab23bb9
commit 6cca986e1de413b5caeffd452da929e32ab23bb9
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    Media queries: Ensure values get destroyed.

diff --git a/src/parse/mq.c b/src/parse/mq.c
index 9d232f9..214b5a2 100644
--- a/src/parse/mq.c
+++ b/src/parse/mq.c
@@ -17,10 +17,21 @@
 #include "parse/properties/utils.h"
 #include "utils/utils.h"
 
-static void css_mq_feature_destroy(css_mq_feature *feature)
+static void css__mq_value_destroy(css_mq_value *value)
+{
+       assert(value != NULL);
+
+       if (value->type == CSS_MQ_VALUE_TYPE_IDENT) {
+               lwc_string_unref(value->data.ident);
+       }
+}
+
+static void css__mq_feature_destroy(css_mq_feature *feature)
 {
        if (feature != NULL) {
                lwc_string_unref(feature->name);
+               css__mq_value_destroy(&feature->value);
+               css__mq_value_destroy(&feature->value2);
                free(feature);
        }
 }
@@ -52,7 +63,7 @@ static void css__mq_cond_or_feature_destroy(
        if (cond_or_feature != NULL) {
                switch (cond_or_feature->type) {
                case CSS_MQ_FEATURE:
-                       css_mq_feature_destroy(cond_or_feature->data.feat);
+                       css__mq_feature_destroy(cond_or_feature->data.feat);
                        break;
                case CSS_MQ_COND:
                        css__mq_cond_destroy(cond_or_feature->data.cond);
@@ -369,7 +380,7 @@ static css_error mq_parse_range(lwc_string **strings,
                        /* num/dim/ident */
                        error = mq_populate_value(&result->value2, token);
                        if (error != CSS_OK) {
-                               css_mq_feature_destroy(result);
+                               css__mq_feature_destroy(result);
                                return error;
                        }
                }
@@ -482,7 +493,7 @@ static css_error mq_parse_media_feature(lwc_string 
**strings,
 
        token = parserutils_vector_iterate(vector, ctx);
        if (tokenIsChar(token, ')') == false) {
-               css_mq_feature_destroy(result);
+               css__mq_feature_destroy(result);
                return CSS_INVALID;
        }
 
@@ -664,7 +675,7 @@ static css_error mq_parse_media_in_parens(lwc_string 
**strings,
                if (error == CSS_OK) {
                        result = malloc(sizeof(*result));
                        if (result == NULL) {
-                               css_mq_feature_destroy(feature);
+                               css__mq_feature_destroy(feature);
                                return CSS_NOMEM;
                        }
                        memset(result, 0, sizeof(*result));


-----------------------------------------------------------------------

Summary of changes:
 src/parse/mq.c                      |   32 ++++++++-----
 src/parse/parse.c                   |   85 ++++++++++++++++++++++-------------
 src/stylesheet.c                    |    8 ----
 test/data/parse2/illegal-values.dat |    2 +-
 4 files changed, 78 insertions(+), 49 deletions(-)

diff --git a/src/parse/mq.c b/src/parse/mq.c
index 2b2164f..214b5a2 100644
--- a/src/parse/mq.c
+++ b/src/parse/mq.c
@@ -17,10 +17,21 @@
 #include "parse/properties/utils.h"
 #include "utils/utils.h"
 
-static void css_mq_feature_destroy(css_mq_feature *feature)
+static void css__mq_value_destroy(css_mq_value *value)
+{
+       assert(value != NULL);
+
+       if (value->type == CSS_MQ_VALUE_TYPE_IDENT) {
+               lwc_string_unref(value->data.ident);
+       }
+}
+
+static void css__mq_feature_destroy(css_mq_feature *feature)
 {
        if (feature != NULL) {
                lwc_string_unref(feature->name);
+               css__mq_value_destroy(&feature->value);
+               css__mq_value_destroy(&feature->value2);
                free(feature);
        }
 }
@@ -52,7 +63,7 @@ static void css__mq_cond_or_feature_destroy(
        if (cond_or_feature != NULL) {
                switch (cond_or_feature->type) {
                case CSS_MQ_FEATURE:
-                       css_mq_feature_destroy(cond_or_feature->data.feat);
+                       css__mq_feature_destroy(cond_or_feature->data.feat);
                        break;
                case CSS_MQ_COND:
                        css__mq_cond_destroy(cond_or_feature->data.cond);
@@ -369,7 +380,7 @@ static css_error mq_parse_range(lwc_string **strings,
                        /* num/dim/ident */
                        error = mq_populate_value(&result->value2, token);
                        if (error != CSS_OK) {
-                               css_mq_feature_destroy(result);
+                               css__mq_feature_destroy(result);
                                return error;
                        }
                }
@@ -482,7 +493,7 @@ static css_error mq_parse_media_feature(lwc_string 
**strings,
 
        token = parserutils_vector_iterate(vector, ctx);
        if (tokenIsChar(token, ')') == false) {
-               css_mq_feature_destroy(result);
+               css__mq_feature_destroy(result);
                return CSS_INVALID;
        }
 
@@ -664,7 +675,7 @@ static css_error mq_parse_media_in_parens(lwc_string 
**strings,
                if (error == CSS_OK) {
                        result = malloc(sizeof(*result));
                        if (result == NULL) {
-                               css_mq_feature_destroy(feature);
+                               css__mq_feature_destroy(feature);
                                return CSS_NOMEM;
                        }
                        memset(result, 0, sizeof(*result));
@@ -686,7 +697,7 @@ static css_error mq_parse_condition(lwc_string **strings,
                bool permit_or, css_mq_cond **cond)
 {
        const css_token *token;
-       bool match;
+       bool match = false;
        int op = 0; /* Will be AND | OR once we've had one */
        css_mq_cond_or_feature *cond_or_feature, **parts;
        css_mq_cond *result;
@@ -700,11 +711,12 @@ static css_error mq_parse_condition(lwc_string **strings,
         */
 
        token = parserutils_vector_peek(vector, *ctx);
-       if (token == NULL || tokenIsChar(token, '(') == false ||
-                       token->type != CSS_TOKEN_IDENT ||
+       if (token == NULL ||
+                       (tokenIsChar(token, '(') == false &&
+                       token->type != CSS_TOKEN_IDENT &&
                        lwc_string_caseless_isequal(token->idata,
-                               strings[NOT], &match) != lwc_error_ok ||
-                       match == false) {
+                               strings[NOT], &match) != lwc_error_ok &&
+                       match == false)) {
                return CSS_INVALID;
        }
 
diff --git a/src/parse/parse.c b/src/parse/parse.c
index f02526b..670b88d 100644
--- a/src/parse/parse.c
+++ b/src/parse/parse.c
@@ -99,8 +99,6 @@ struct css_parser
        bool parseError;                /**< A parse error has occurred */
        parserutils_stack *open_items;  /**< Stack of open brackets */
 
-       uint8_t match_char;             /**< Close bracket type for parseAny */
-
        bool last_was_ws;               /**< Last token was whitespace */
 
        css_parser_event_handler event; /**< Client's event handler */
@@ -478,7 +476,6 @@ css_error css__parser_create_internal(const char *charset,
        p->quirks = false;
        p->pushback = NULL;
        p->parseError = false;
-       p->match_char = 0;
        p->event = NULL;
        p->last_was_ws = false;
        p->event_pw = NULL;
@@ -909,17 +906,6 @@ css_error parseRuleset(css_parser *parser)
                }
                break;
        case Brace:
-#if !defined(NDEBUG) && defined(DEBUG_EVENTS)
-               printf("Begin ruleset\n");
-               parserutils_vector_dump(parser->tokens, __func__, tprinter);
-#endif
-               if (parser->parseError == false && parser->event != NULL) {
-                       if (parser->event(CSS_PARSER_START_RULESET,
-                                       parser->tokens, parser->event_pw) ==
-                                       CSS_INVALID)
-                               parser->parseError = true;
-               }
-
                if (parser->parseError == true) {
                        parser_state to = { sMalformedSelector, Initial };
 
@@ -930,22 +916,40 @@ css_error parseRuleset(css_parser *parser)
                if (error != CSS_OK)
                        return error;
 
-               if (token->type == CSS_TOKEN_EOF) {
+               if (token->type != CSS_TOKEN_CHAR ||
+                               lwc_string_length(token->idata) != 1 ||
+                               lwc_string_data(token->idata)[0] != '{') {
+                       /* FOLLOW(selector) contains only '{', but we may
+                        * also have seen EOF, which is a parse error. */
                        error = pushBack(parser, token);
                        if (error != CSS_OK)
                                return error;
 
+                       parser->parseError = true;
                        return done(parser);
                }
 
-               if (token->type != CSS_TOKEN_CHAR ||
-                               lwc_string_length(token->idata) != 1 ||
-                               lwc_string_data(token->idata)[0] != '{') {
-                       /* This should never happen, as FOLLOW(selector)
-                        * contains only '{' */
-                       assert(0 && "Expected {");
+               /* We don't want to emit the brace, so push it back */
+               error = pushBack(parser, token);
+               if (error != CSS_OK)
+                       return error;
+
+#if !defined(NDEBUG) && defined(DEBUG_EVENTS)
+               printf("Begin ruleset\n");
+               parserutils_vector_dump(parser->tokens, __func__, tprinter);
+#endif
+               if (parser->parseError == false && parser->event != NULL) {
+                       if (parser->event(CSS_PARSER_START_RULESET,
+                                       parser->tokens, parser->event_pw) ==
+                                       CSS_INVALID)
+                               parser->parseError = true;
                }
 
+               /* Re-read the brace */
+               error = getToken(parser, &token);
+               if (error != CSS_OK)
+                       return error;
+
                state->substate = WS;
                /* Fall through */
        case WS:
@@ -1080,7 +1084,7 @@ css_error parseAtRule(css_parser *parser)
                /* Fall through */
        case Any:
        {
-               parser_state to = { sAny, Initial };
+               parser_state to = { sAny0, Initial };
                parser_state subsequent = { sAtRule, AfterAny };
 
                return transition(parser, to, subsequent);
@@ -1103,7 +1107,7 @@ css_error parseAtRule(css_parser *parser)
                        if (lwc_string_data(token->idata)[0] == ')' ||
                                        lwc_string_data(
                                                token->idata)[0] == ']') {
-                               parser_state to = { sAny, Initial };
+                               parser_state to = { sAny0, Initial };
                                parser_state subsequent = { sAtRule, AfterAny };
 
                                return transition(parser, to, subsequent);
@@ -1964,6 +1968,9 @@ css_error parseAny1(css_parser *parser)
                if (error != CSS_OK)
                        return error;
 
+               if (token->type == CSS_TOKEN_EOF)
+                       return done(parser);
+
                /* Grammar ambiguity: any0 can be followed by
                 * '{', ';', ')', ']'. any1 can only be followed by '{'. */
                if (token->type == CSS_TOKEN_CHAR &&
@@ -2044,18 +2051,19 @@ css_error parseAny(css_parser *parser)
                }
 
                if (token->type == CSS_TOKEN_FUNCTION) {
-                       parser->match_char = ')';
+                       parserutils_stack_push(parser->open_items, &")"[0]);
                        state->substate = WS;
                } else if (token->type == CSS_TOKEN_CHAR &&
                                lwc_string_length(token->idata) == 1 &&
                                (lwc_string_data(token->idata)[0] == '(' ||
                                lwc_string_data(token->idata)[0] == '[')) {
-                       parser->match_char = lwc_string_data(
-                                       token->idata)[0] == '(' ? ')' : ']';
+                       parserutils_stack_push(parser->open_items,
+                                       &(lwc_string_data(
+                                       token->idata)[0] == '(' ? ")" : 
"]")[0]);
                        state->substate = WS;
+               } else {
+                       state->substate = WS2;
                }
-
-               state->substate = WS2;
                /* Fall through */
        case WS:
        case WS2:
@@ -2082,11 +2090,24 @@ css_error parseAny(css_parser *parser)
                if (error != CSS_OK)
                        return error;
 
+               if (token->type == CSS_TOKEN_EOF) {
+                       error = pushBack(parser, token);
+                       if (error != CSS_OK)
+                               return error;
+
+                       /* parse error */
+                       parser->parseError = true;
+
+                       return done(parser);
+               }
+
                /* Match correct close bracket (grammar ambiguity) */
                if (token->type == CSS_TOKEN_CHAR &&
                                lwc_string_length(token->idata) == 1 &&
                                lwc_string_data(token->idata)[0] ==
-                               parser->match_char) {
+                               ((uint8_t *) parserutils_stack_get_current(
+                                               parser->open_items))[0]) {
+                       parserutils_stack_pop(parser->open_items, NULL);
                        state->substate = WS2;
                        goto ws2;
                }
@@ -2623,7 +2644,11 @@ static void tprinter(void *token)
 {
        css_token *t = token;
 
-       if (t->data.data)
+       if (t->idata) {
+               printf("%d: %.*s", t->type,
+                               (int) lwc_string_length(t->idata),
+                               lwc_string_data(t->idata));
+       } else if (t->data.data)
                printf("%d: %.*s", t->type, (int) t->data.len, t->data.data);
        else
                printf("%d", t->type);
diff --git a/src/stylesheet.c b/src/stylesheet.c
index 1ee9eed..934954c 100644
--- a/src/stylesheet.c
+++ b/src/stylesheet.c
@@ -208,14 +208,6 @@ static css_error css_parse_media_query(lwc_string 
**strings,
                return err;
        }
 
-       err = css__parser_parse_chunk(parser,
-                       (const uint8_t *)" {",
-                                 strlen(" {"));
-       if (err != CSS_OK && err != CSS_NEEDDATA) {
-               css__parser_destroy(parser);
-               return err;
-       }
-
        err = css__parser_completed(parser);
        if (err != CSS_OK) {
                css__parser_destroy(parser);
diff --git a/test/data/parse2/illegal-values.dat 
b/test/data/parse2/illegal-values.dat
index 3187e18..2d58b54 100644
--- a/test/data/parse2/illegal-values.dat
+++ b/test/data/parse2/illegal-values.dat
@@ -864,7 +864,7 @@
 #reset
 
 #data
-* { display: 

Reply via email to