summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-10-12 14:45:23 +0200
committerTor Andersson <tor.andersson@artifex.com>2016-10-12 14:45:42 +0200
commit69c379990d83d83682b23eac3ddf390c0d85e976 (patch)
treec6d2fd66d472784924e524c95552aa41d6c87ce6 /include
parentcf94c2a1e8cac52074183b31f75b71480dbdcea1 (diff)
downloadmupdf-69c379990d83d83682b23eac3ddf390c0d85e976.tar.xz
Use pool allocator when parsing CSS.
Fixes memory leaks when parsing throws exceptions and saves a lot of tiny mallocs for objects that have common life times.
Diffstat (limited to 'include')
-rw-r--r--include/mupdf/fitz/pool.h1
-rw-r--r--include/mupdf/html.h21
2 files changed, 15 insertions, 7 deletions
diff --git a/include/mupdf/fitz/pool.h b/include/mupdf/fitz/pool.h
index 924fb804..919b08d0 100644
--- a/include/mupdf/fitz/pool.h
+++ b/include/mupdf/fitz/pool.h
@@ -21,6 +21,7 @@ struct fz_pool_node_s
fz_pool *fz_new_pool(fz_context *ctx);
void *fz_pool_alloc(fz_context *ctx, fz_pool *pool, size_t size);
+char *fz_pool_strdup(fz_context *ctx, fz_pool *pool, const char *s);
void fz_drop_pool(fz_context *ctx, fz_pool *pool);
#endif
diff --git a/include/mupdf/html.h b/include/mupdf/html.h
index 7c3eadac..f9bd4d98 100644
--- a/include/mupdf/html.h
+++ b/include/mupdf/html.h
@@ -9,6 +9,7 @@ typedef struct fz_html_s fz_html;
typedef struct fz_html_box_s fz_html_box;
typedef struct fz_html_flow_s fz_html_flow;
+typedef struct fz_css_s fz_css;
typedef struct fz_css_rule_s fz_css_rule;
typedef struct fz_css_match_prop_s fz_css_match_prop;
typedef struct fz_css_match_s fz_css_match;
@@ -48,11 +49,16 @@ enum
CSS_URI,
};
+struct fz_css_s
+{
+ fz_pool *pool;
+ fz_css_rule *rule;
+};
+
struct fz_css_rule_s
{
fz_css_selector *selector;
fz_css_property *declaration;
- fz_css_property *garbage; /* for freeing inline style attributes at the end */
fz_css_rule *next;
};
@@ -244,12 +250,13 @@ struct fz_html_flow_s
fz_html_flow *next;
};
-fz_css_rule *fz_parse_css(fz_context *ctx, fz_css_rule *chain, const char *source, const char *file);
-fz_css_property *fz_parse_css_properties(fz_context *ctx, const char *source);
-void fz_drop_css(fz_context *ctx, fz_css_rule *rule);
+fz_css *fz_new_css(fz_context *ctx);
+void fz_parse_css(fz_context *ctx, fz_css *css, const char *source, const char *file);
+fz_css_property *fz_parse_css_properties(fz_context *ctx, fz_pool *pool, const char *source);
+void fz_drop_css(fz_context *ctx, fz_css *css);
-void fz_match_css(fz_context *ctx, fz_css_match *match, fz_css_rule *rule, fz_xml *node);
-void fz_match_css_at_page(fz_context *ctx, fz_css_match *match, fz_css_rule *css);
+void fz_match_css(fz_context *ctx, fz_css_match *match, fz_css *css, fz_xml *node);
+void fz_match_css_at_page(fz_context *ctx, fz_css_match *match, fz_css *css);
int fz_get_css_match_display(fz_css_match *node);
void fz_default_css_style(fz_context *ctx, fz_css_style *style);
@@ -264,7 +271,7 @@ void fz_add_html_font_face(fz_context *ctx, fz_html_font_set *set,
fz_font *fz_load_html_font(fz_context *ctx, fz_html_font_set *set, const char *family, int is_bold, int is_italic);
void fz_drop_html_font_set(fz_context *ctx, fz_html_font_set *htx);
-void fz_add_css_font_faces(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const char *base_uri, fz_css_rule *css);
+void fz_add_css_font_faces(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const char *base_uri, fz_css *css);
fz_html *fz_parse_html(fz_context *ctx, fz_html_font_set *htx, fz_archive *zip, const char *base_uri, fz_buffer *buf, const char *user_css);
void fz_layout_html(fz_context *ctx, fz_html *html, float w, float h, float em);