diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2009-01-25 14:07:29 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2009-01-25 14:07:29 +0000 |
commit | bcc22fab44fee60e8a96f69a229db1e3956e5801 (patch) | |
tree | f323f16c6245326e4ebe4b1a926419e875489ef0 /src/stylesheet.c | |
parent | 1c23bae15b2bb019c39af68b1c0cfc5bb40ba2a7 (diff) | |
download | libcss-bcc22fab44fee60e8a96f69a229db1e3956e5801.tar.gz libcss-bcc22fab44fee60e8a96f69a229db1e3956e5801.tar.bz2 |
Destroy parser on completion of parse, rather than keeping it around until we destroy the sheet.
svn path=/trunk/libcss/; revision=6264
Diffstat (limited to 'src/stylesheet.c')
-rw-r--r-- | src/stylesheet.c | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/src/stylesheet.c b/src/stylesheet.c index 80f2a1b..955c887 100644 --- a/src/stylesheet.c +++ b/src/stylesheet.c @@ -138,8 +138,6 @@ css_error css_stylesheet_destroy(css_stylesheet *sheet) if (sheet == NULL) return CSS_BADPARM; - parserutils_hash_destroy(sheet->dictionary); - if (sheet->title != NULL) sheet->alloc(sheet->title, 0, sheet->pw); @@ -149,9 +147,14 @@ css_error css_stylesheet_destroy(css_stylesheet *sheet) css_selector_hash_destroy(sheet->selectors); - css_language_destroy(sheet->parser_frontend); + /* These two may have been destroyed when parsing completed */ + if (sheet->parser_frontend != NULL) + css_language_destroy(sheet->parser_frontend); - css_parser_destroy(sheet->parser); + if (sheet->parser != NULL) + css_parser_destroy(sheet->parser); + + parserutils_hash_destroy(sheet->dictionary); sheet->alloc(sheet, 0, sheet->pw); @@ -172,6 +175,9 @@ css_error css_stylesheet_append_data(css_stylesheet *sheet, if (sheet == NULL || data == NULL) return CSS_BADPARM; + if (sheet->parser == NULL) + return CSS_INVALID; + return css_parser_parse_chunk(sheet->parser, data, len); } @@ -183,17 +189,26 @@ css_error css_stylesheet_append_data(css_stylesheet *sheet, */ css_error css_stylesheet_data_done(css_stylesheet *sheet) { + css_error error; + if (sheet == NULL) return CSS_BADPARM; - return css_parser_completed(sheet->parser); + if (sheet->parser == NULL) + return CSS_INVALID; + + error = css_parser_completed(sheet->parser); + if (error != CSS_OK) + return error; + + /* Destroy the parser, as it's no longer needed */ + css_language_destroy(sheet->parser_frontend); + css_parser_destroy(sheet->parser); - /** \todo We can destroy the parser here as it won't be needed - * Note, however, that, if we do so, then the dictionary of - * strings created by the parser *must* be preserved (and, ideally, - * created by us in the first place) because our stylesheet - * datastructures contain pointers to strings stored in this - * dictionary. */ + sheet->parser_frontend = NULL; + sheet->parser = NULL; + + return CSS_OK; } /** |