From 051db70dd4eb678728052f6f3dba15fbe8c6e6ea Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Mon, 19 Dec 2005 02:34:26 +0100 Subject: [PATCH] Add boolean immutable flag to the DOM stack state Can be used to ensure the document root node never leaves the stack while parsing. --- src/document/dom/stack.c | 3 +++ src/document/dom/stack.h | 3 +++ src/document/sgml/parser.c | 2 ++ 3 files changed, 8 insertions(+) diff --git a/src/document/dom/stack.c b/src/document/dom/stack.c index 824891bf3..8ee990581 100644 --- a/src/document/dom/stack.c +++ b/src/document/dom/stack.c @@ -140,6 +140,9 @@ do_pop_dom_node(struct dom_stack *stack, struct dom_stack_state *parent) assert(stack && !dom_stack_is_empty(stack)); state = get_dom_stack_top(stack); + if (state->immutable) + return 1; + callback = stack->pop_callbacks[state->node->type]; if (callback) { void *state_data = get_dom_stack_state_data(stack, state); diff --git a/src/document/dom/stack.h b/src/document/dom/stack.h index 234114268..5501ea0f8 100644 --- a/src/document/dom/stack.h +++ b/src/document/dom/stack.h @@ -27,6 +27,9 @@ struct dom_stack_state { /* The depth of the state in the stack. This is amongst other things * used to get the state object data. */ unsigned int depth; + + /* Wether this stack state can be popped with pop_dom_*() family. */ + unsigned int immutable:1; }; /* The DOM stack is a convenient way to traverse DOM trees. Also it diff --git a/src/document/sgml/parser.c b/src/document/sgml/parser.c index 34bfdfb9e..b63556b60 100644 --- a/src/document/sgml/parser.c +++ b/src/document/sgml/parser.c @@ -330,6 +330,8 @@ init_sgml_parser(enum sgml_parser_type type, void *data, struct uri *uri, return NULL; } + get_dom_stack_top(&parser->stack)->immutable = 1; + return parser; }