summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn-Mark Bell <jmb@netsurf-browser.org>2017-02-04 11:51:30 (GMT)
committer John-Mark Bell <jmb@netsurf-browser.org>2017-02-04 11:51:30 (GMT)
commit7c57ceadc3a6076914242783582581095283b63b (patch)
tree13f3404b4199e18fc5072fc7e902db0cd8e12aa4
parent3634123921fdff383e1ed62f62f1aaf1e71134f5 (diff)
downloadlibcss-7c57ceadc3a6076914242783582581095283b63b.tar.gz
libcss-7c57ceadc3a6076914242783582581095283b63b.tar.bz2
Media Queries: sort out object lifetimes
-rw-r--r--src/parse/language.c20
-rw-r--r--src/parse/mq.h4
-rw-r--r--src/stylesheet.c14
3 files changed, 19 insertions, 19 deletions
diff --git a/src/parse/language.c b/src/parse/language.c
index 68055e1..d03c878 100644
--- a/src/parse/language.c
+++ b/src/parse/language.c
@@ -416,8 +416,7 @@ css_error handleStartAtRule(css_language *c, const parserutils_vector *vector)
lwc_string *url;
css_mq_query *media = NULL;
- /* any0 = (STRING | URI) ws
- * (media query)? */
+ /* any0 = (STRING | URI) ws (media query)? */
const css_token *uri =
parserutils_vector_iterate(vector, &ctx);
if (uri == NULL || (uri->type != CSS_TOKEN_STRING &&
@@ -435,7 +434,7 @@ css_error handleStartAtRule(css_language *c, const parserutils_vector *vector)
error = css__stylesheet_rule_create(c->sheet,
CSS_RULE_IMPORT, &rule);
if (error != CSS_OK) {
- css__mq_query_unref(media);
+ css__mq_query_destroy(media);
return error;
}
@@ -444,8 +443,8 @@ css_error handleStartAtRule(css_language *c, const parserutils_vector *vector)
c->sheet->url,
uri->idata, &url);
if (error != CSS_OK) {
- css__mq_query_unref(media);
css__stylesheet_rule_destroy(c->sheet, rule);
+ css__mq_query_destroy(media);
return error;
}
@@ -454,8 +453,8 @@ css_error handleStartAtRule(css_language *c, const parserutils_vector *vector)
rule, url, media);
if (error != CSS_OK) {
lwc_string_unref(url);
- css__mq_query_unref(media);
css__stylesheet_rule_destroy(c->sheet, rule);
+ css__mq_query_destroy(media);
return error;
}
@@ -465,16 +464,14 @@ css_error handleStartAtRule(css_language *c, const parserutils_vector *vector)
c->sheet, url);
if (error != CSS_OK) {
lwc_string_unref(url);
- css__mq_query_unref(media);
css__stylesheet_rule_destroy(c->sheet,
rule);
return error;
}
}
- /* No longer care about url or media */
+ /* No longer care about url */
lwc_string_unref(url);
- css__mq_query_unref(media);
/* Add rule to sheet */
error = css__stylesheet_add_rule(c->sheet, rule, NULL);
@@ -542,26 +539,23 @@ css_error handleStartAtRule(css_language *c, const parserutils_vector *vector)
error = css__stylesheet_rule_create(c->sheet,
CSS_RULE_MEDIA, &rule);
if (error != CSS_OK) {
- css__mq_query_unref(media);
+ css__mq_query_destroy(media);
return error;
}
error = css__stylesheet_rule_set_media(c->sheet, rule, media);
if (error != CSS_OK) {
css__stylesheet_rule_destroy(c->sheet, rule);
- css__mq_query_unref(media);
+ css__mq_query_destroy(media);
return error;
}
error = css__stylesheet_add_rule(c->sheet, rule, NULL);
if (error != CSS_OK) {
css__stylesheet_rule_destroy(c->sheet, rule);
- css__mq_query_unref(media);
return error;
}
- css__mq_query_unref(media);
-
/* Rule is now owned by the sheet,
* so no need to destroy it */
diff --git a/src/parse/mq.h b/src/parse/mq.h
index eeb55da..7d62e8c 100644
--- a/src/parse/mq.h
+++ b/src/parse/mq.h
@@ -93,8 +93,6 @@ css_error css__mq_parse_media_list(css_language *c,
const parserutils_vector *vector, int *ctx,
css_mq_query **media);
-/** \todo is this necessary? */
-css_mq_query *css__mq_query_ref(css_mq_query *media);
-css_mq_query *css__mq_query_unref(css_mq_query *media);
+css_mq_query *css__mq_query_destroy(css_mq_query *media);
#endif
diff --git a/src/stylesheet.c b/src/stylesheet.c
index 63f958b..a8d2175 100644
--- a/src/stylesheet.c
+++ b/src/stylesheet.c
@@ -12,6 +12,7 @@
#include "stylesheet.h"
#include "bytecode/bytecode.h"
#include "parse/language.h"
+#include "parse/mq.h"
#include "utils/parserutilserror.h"
#include "utils/utils.h"
#include "select/dispatch.h"
@@ -1151,7 +1152,10 @@ css_error css__stylesheet_rule_destroy(css_stylesheet *sheet, css_rule *rule)
css_rule_import *import = (css_rule_import *) rule;
lwc_string_unref(import->url);
-
+ if (import->media != NULL) {
+ css__mq_query_destroy(import->media);
+ }
+
/* Do not destroy imported sheet: it is owned by the client */
}
break;
@@ -1160,6 +1164,10 @@ css_error css__stylesheet_rule_destroy(css_stylesheet *sheet, css_rule *rule)
css_rule_media *media = (css_rule_media *) rule;
css_rule *c, *d;
+ if (media->media != NULL) {
+ css__mq_query_destroy(media->media);
+ }
+
for (c = media->first_child; c != NULL; c = d) {
d = c->next;
@@ -1335,7 +1343,7 @@ css_error css__stylesheet_rule_set_nascent_import(css_stylesheet *sheet,
/* Set the rule's sheet field */
r->url = lwc_string_ref(url);
- r->media = css__mq_query_ref(media);
+ r->media = media;
return CSS_OK;
}
@@ -1360,7 +1368,7 @@ css_error css__stylesheet_rule_set_media(css_stylesheet *sheet,
assert(rule->type == CSS_RULE_MEDIA);
/* Set the rule's media */
- r->media = css__mq_query_ref(media);
+ r->media = media;
return CSS_OK;
}