From f058052e94cf11b94299983d6ab1eb163278c875 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 13 Feb 2015 15:54:39 +0100 Subject: [PATCH] XML: Uninlined --- maint/libucw.abi | 5 +++ ucw-xml/dtd.c | 6 ++-- ucw-xml/internals.h | 77 ++++++----------------------------------- ucw-xml/parse.c | 84 ++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 97 insertions(+), 75 deletions(-) diff --git a/maint/libucw.abi b/maint/libucw.abi index ca9287eb..299c06d4 100644 --- a/maint/libucw.abi +++ b/maint/libucw.abi @@ -813,6 +813,10 @@ xml_dtd_finish xml_dtd_find_attr # ucw-xml/internals.h xml_throw +xml_do_push +xml_do_pop +xml_push_dom +xml_pop_dom xml_hash_new xml_spout_chars xml_fatal_nested @@ -823,6 +827,7 @@ xml_sources_cleanup xml_fatal_expected xml_fatal_expected_white xml_fatal_expected_quot +xml_parse_white xml_parse_eq xml_parse_name xml_skip_name diff --git a/ucw-xml/dtd.c b/ucw-xml/dtd.c index 7c06af84..62badba2 100644 --- a/ucw-xml/dtd.c +++ b/ucw-xml/dtd.c @@ -218,7 +218,7 @@ xml_dtd_attrs_eq(struct xml_dtd_attrs_table *tab UNUSED, struct xml_dtd_elem *el return (elem1 == elem2) && !strcmp(name1, name2); } -static inline void +static void xml_dtd_attrs_init_key(struct xml_dtd_attrs_table *tab UNUSED, struct xml_dtd_attr *attr, struct xml_dtd_elem *elem, char *name) { attr->elem = elem; @@ -302,7 +302,7 @@ xml_dtd_enotns_eq(struct xml_dtd_enotns_table *tab UNUSED, struct xml_dtd_attr * return (attr1 == attr2) && (notn1 == notn2); } -static inline void +static void xml_dtd_enotns_init_key(struct xml_dtd_enotns_table *tab UNUSED, struct xml_dtd_enotn *enotn, struct xml_dtd_attr *attr, struct xml_dtd_notn *notn) { enotn->attr = attr; @@ -411,7 +411,7 @@ xml_parse_dtd_pe(struct xml_context *ctx, uint entity_decl) return 1; } -static inline uint +static uint xml_parse_dtd_white(struct xml_context *ctx, uint mandatory) { /* Whitespace or parameter entity, diff --git a/ucw-xml/internals.h b/ucw-xml/internals.h index 8752cc2d..0e9dc2de 100644 --- a/ucw-xml/internals.h +++ b/ucw-xml/internals.h @@ -14,6 +14,8 @@ #include #ifdef CONFIG_UCW_CLEAN_ABI +#define xml_do_pop ucw_xml_do_pop +#define xml_do_push ucw_xml_do_push #define xml_fatal_expected ucw_xml_fatal_expected #define xml_fatal_expected_quot ucw_xml_fatal_expected_quot #define xml_fatal_expected_white ucw_xml_fatal_expected_white @@ -35,9 +37,12 @@ #define xml_parse_pe_ref ucw_xml_parse_pe_ref #define xml_parse_pubid_literal ucw_xml_parse_pubid_literal #define xml_parse_system_literal ucw_xml_parse_system_literal +#define xml_parse_white ucw_xml_parse_white #define xml_pop_comment ucw_xml_pop_comment +#define xml_pop_dom ucw_xml_pop_dom #define xml_pop_pi ucw_xml_pop_pi #define xml_push_comment ucw_xml_push_comment +#define xml_push_dom ucw_xml_push_dom #define xml_push_entity ucw_xml_push_entity #define xml_push_pi ucw_xml_push_pi #define xml_push_source ucw_xml_push_source @@ -72,26 +77,8 @@ struct xml_stack { uint flags; }; -static inline void *xml_do_push(struct xml_context *ctx, uint size) -{ - /* Saves ctx->stack and ctx->flags state */ - struct mempool_state state; - mp_save(ctx->stack, &state); - struct xml_stack *s = mp_alloc(ctx->stack, size); - s->state = state; - s->flags = ctx->flags; - s->next = ctx->stack_list; - ctx->stack_list = s; - return s; -} - -static inline void xml_do_pop(struct xml_context *ctx, struct xml_stack *s) -{ - /* Restore ctx->stack and ctx->flags state */ - ctx->stack_list = s->next; - ctx->flags = s->flags; - mp_restore(ctx->stack, &s->state); -} +void *xml_do_push(struct xml_context *ctx, uint size); +void xml_do_pop(struct xml_context *ctx, struct xml_stack *s); static inline void xml_push(struct xml_context *ctx) { @@ -111,39 +98,8 @@ struct xml_dom_stack { struct mempool_state state; }; -static inline struct xml_node *xml_push_dom(struct xml_context *ctx, struct mempool_state *state) -{ - /* Create a new DOM node */ - TRACE(ctx, "push_dom"); - struct xml_dom_stack *s = xml_do_push(ctx, sizeof(*s)); - if (state) - s->state = *state; - else - mp_save(ctx->pool, &s->state); - struct xml_node *n = mp_alloc(ctx->pool, sizeof(*n)); - n->user = NULL; - if (n->parent = ctx->node) - clist_add_tail(&n->parent->sons, &n->n); - return ctx->node = n; -} - -static inline void xml_pop_dom(struct xml_context *ctx, uint free) -{ - /* Leave DOM subtree */ - TRACE(ctx, "pop_dom"); - ASSERT(ctx->node); - struct xml_node *p = ctx->node->parent; - struct xml_dom_stack *s = (void *)ctx->stack_list; - if (free) - { - /* See xml_pop_element() for cleanup of attribute hash table */ - if (p) - clist_remove(&ctx->node->n); - mp_restore(ctx->pool, &s->state); - } - ctx->node = p; - xml_do_pop(ctx, &s->stack); -} +struct xml_node *xml_push_dom(struct xml_context *ctx, struct mempool_state *state); +void xml_pop_dom(struct xml_context *ctx, uint free); #define XML_HASH_HDR_SIZE ALIGN_TO(sizeof(void *), CPU_STRUCT_ALIGN) #define XML_HASH_GIVE_ALLOC struct HASH_PREFIX(table); \ @@ -254,20 +210,7 @@ void NONRET xml_fatal_expected(struct xml_context *ctx, uint c); void NONRET xml_fatal_expected_white(struct xml_context *ctx); void NONRET xml_fatal_expected_quot(struct xml_context *ctx); -static inline uint xml_parse_white(struct xml_context *ctx, uint mandatory) -{ - /* mandatory=1 -> S ::= (#x20 | #x9 | #xD | #xA)+ - * mandatory=0 -> S? */ - uint cnt = 0; - while (xml_peek_cat(ctx) & XML_CHAR_WHITE) - { - xml_skip_char(ctx); - cnt++; - } - if (unlikely(mandatory && !cnt)) - xml_fatal_expected_white(ctx); - return cnt; -} +uint xml_parse_white(struct xml_context *ctx, uint mandatory); static inline void xml_parse_char(struct xml_context *ctx, uint c) { diff --git a/ucw-xml/parse.c b/ucw-xml/parse.c index b1790d0b..65e556b6 100644 --- a/ucw-xml/parse.c +++ b/ucw-xml/parse.c @@ -54,6 +54,80 @@ xml_parse_eq(struct xml_context *ctx) xml_parse_white(ctx, 0); } +/*** Memory management ***/ + +void *xml_do_push(struct xml_context *ctx, uint size) +{ + /* Saves ctx->stack and ctx->flags state */ + struct mempool_state state; + mp_save(ctx->stack, &state); + struct xml_stack *s = mp_alloc(ctx->stack, size); + s->state = state; + s->flags = ctx->flags; + s->next = ctx->stack_list; + ctx->stack_list = s; + return s; +} + +void xml_do_pop(struct xml_context *ctx, struct xml_stack *s) +{ + /* Restore ctx->stack and ctx->flags state */ + ctx->stack_list = s->next; + ctx->flags = s->flags; + mp_restore(ctx->stack, &s->state); +} + +struct xml_node *xml_push_dom(struct xml_context *ctx, struct mempool_state *state) +{ + /* Create a new DOM node */ + TRACE(ctx, "push_dom"); + struct xml_dom_stack *s = xml_do_push(ctx, sizeof(*s)); + if (state) + s->state = *state; + else + mp_save(ctx->pool, &s->state); + struct xml_node *n = mp_alloc(ctx->pool, sizeof(*n)); + n->user = NULL; + if (n->parent = ctx->node) + clist_add_tail(&n->parent->sons, &n->n); + return ctx->node = n; +} + +void xml_pop_dom(struct xml_context *ctx, uint free) +{ + /* Leave DOM subtree */ + TRACE(ctx, "pop_dom"); + ASSERT(ctx->node); + struct xml_node *p = ctx->node->parent; + struct xml_dom_stack *s = (void *)ctx->stack_list; + if (free) + { + /* See xml_pop_element() for cleanup of attribute hash table */ + if (p) + clist_remove(&ctx->node->n); + mp_restore(ctx->pool, &s->state); + } + ctx->node = p; + xml_do_pop(ctx, &s->stack); +} + +/*** Basics ***/ + +uint xml_parse_white(struct xml_context *ctx, uint mandatory) +{ + /* mandatory=1 -> S ::= (#x20 | #x9 | #xD | #xA)+ + * mandatory=0 -> S? */ + uint cnt = 0; + while (xml_peek_cat(ctx) & XML_CHAR_WHITE) + { + xml_skip_char(ctx); + cnt++; + } + if (unlikely(mandatory && !cnt)) + xml_fatal_expected_white(ctx); + return cnt; +} + /*** Names and nmtokens ***/ static char * @@ -387,7 +461,7 @@ xml_spout_chars(struct fastbuf *fb) } } -static inline uint +static uint xml_end_chars(struct xml_context *ctx, char **out) { struct fastbuf *fb = &ctx->chars; @@ -402,7 +476,7 @@ xml_end_chars(struct xml_context *ctx, char **out) return len; } -static inline uint +static uint xml_report_chars(struct xml_context *ctx, char **out) { struct fastbuf *fb = &ctx->chars; @@ -416,7 +490,7 @@ xml_report_chars(struct xml_context *ctx, char **out) return len; } -static inline uint +static uint xml_flush_chars(struct xml_context *ctx) { char *text, *rtext; @@ -447,14 +521,14 @@ xml_flush_chars(struct xml_context *ctx) return len; } -static inline void +static void xml_pop_chars(struct xml_context *ctx) { xml_pop_dom(ctx, !(ctx->flags & XML_ALLOC_CHARS)); TRACE(ctx, "pop_chars"); } -static inline void +static void xml_append_chars(struct xml_context *ctx) { TRACE(ctx, "append_chars"); -- 2.39.2