From 4e6b05394d0ee148c87ba98c2e2acb850ea30171 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Mon, 16 Jan 2006 05:09:45 +0100 Subject: [PATCH] ADD DOM_STACK_CODE_FREE_NODE so callbacks can remove nodes when popping --- src/dom/stack.c | 19 ++++++++++++++----- src/dom/stack.h | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/dom/stack.c b/src/dom/stack.c index 2197482f4..3597593ce 100644 --- a/src/dom/stack.c +++ b/src/dom/stack.c @@ -129,10 +129,12 @@ enum dom_stack_action { DOM_STACK_POP, }; -static void +/* Returns whether the node should be freed with done_dom_node(). */ +static int call_dom_stack_callbacks(struct dom_stack *stack, struct dom_stack_state *state, enum dom_stack_action action) { + int free_node = 0; int i; for (i = 0; i < stack->contexts_size; i++) { @@ -148,10 +150,18 @@ call_dom_stack_callbacks(struct dom_stack *stack, struct dom_stack_state *state, void *data = get_dom_stack_state_data(context, state); stack->current = context; - callback(stack, state->node, data); + switch (callback(stack, state->node, data)) { + case DOM_STACK_CODE_FREE_NODE: + free_node = 1; + break; + default: + break; + } stack->current = NULL; } } + + return free_node; } enum dom_stack_code @@ -211,9 +221,8 @@ pop_dom_node(struct dom_stack *stack) if (state->immutable) return; - call_dom_stack_callbacks(stack, state, DOM_STACK_POP); - - if (stack->flags & DOM_STACK_FLAG_FREE_NODES) + if (call_dom_stack_callbacks(stack, state, DOM_STACK_POP) + || (stack->flags & DOM_STACK_FLAG_FREE_NODES)) done_dom_node(state->node); stack->depth--; diff --git a/src/dom/stack.h b/src/dom/stack.h index 211c52b6c..996b2a00b 100644 --- a/src/dom/stack.h +++ b/src/dom/stack.h @@ -15,6 +15,7 @@ struct dom_stack; */ enum dom_stack_code { DOM_STACK_CODE_OK, /*: All is well */ + DOM_STACK_CODE_FREE_NODE, /*: Free the (popped) node */ DOM_STACK_CODE_ERROR_MEM_ALLOC, /*: Memory allocation failure */ DOM_STACK_CODE_ERROR_MAX_DEPTH, /*: Stack max depth reached */ };