1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-01-03 14:57:44 -05:00

ADD DOM_STACK_CODE_FREE_NODE so callbacks can remove nodes when popping

This commit is contained in:
Jonas Fonseca 2006-01-16 05:09:45 +01:00 committed by Jonas Fonseca
parent eecc22751d
commit 4e6b05394d
2 changed files with 15 additions and 5 deletions

View File

@ -129,10 +129,12 @@ enum dom_stack_action {
DOM_STACK_POP, 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, call_dom_stack_callbacks(struct dom_stack *stack, struct dom_stack_state *state,
enum dom_stack_action action) enum dom_stack_action action)
{ {
int free_node = 0;
int i; int i;
for (i = 0; i < stack->contexts_size; 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); void *data = get_dom_stack_state_data(context, state);
stack->current = context; 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; stack->current = NULL;
} }
} }
return free_node;
} }
enum dom_stack_code enum dom_stack_code
@ -211,9 +221,8 @@ pop_dom_node(struct dom_stack *stack)
if (state->immutable) if (state->immutable)
return; return;
call_dom_stack_callbacks(stack, state, DOM_STACK_POP); if (call_dom_stack_callbacks(stack, state, DOM_STACK_POP)
|| (stack->flags & DOM_STACK_FLAG_FREE_NODES))
if (stack->flags & DOM_STACK_FLAG_FREE_NODES)
done_dom_node(state->node); done_dom_node(state->node);
stack->depth--; stack->depth--;

View File

@ -15,6 +15,7 @@ struct dom_stack;
*/ */
enum dom_stack_code { enum dom_stack_code {
DOM_STACK_CODE_OK, /*: All is well */ 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_MEM_ALLOC, /*: Memory allocation failure */
DOM_STACK_CODE_ERROR_MAX_DEPTH, /*: Stack max depth reached */ DOM_STACK_CODE_ERROR_MAX_DEPTH, /*: Stack max depth reached */
}; };