From 2963d5f3929f6a1c646a9fc613641339bcd16013 Mon Sep 17 00:00:00 2001 From: Arran Cudbard-Bell Date: Thu, 28 May 2020 18:00:41 -0500 Subject: [PATCH] interpreter: Allow frame states to be allocated without allocating memory for a frame state structure It's useful for scratch space where we don't need to store state between calls --- src/lib/unlang/interpret.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/lib/unlang/interpret.c b/src/lib/unlang/interpret.c index 90e0392234..60766f8ae8 100644 --- a/src/lib/unlang/interpret.c +++ b/src/lib/unlang/interpret.c @@ -119,29 +119,38 @@ static inline void frame_state_init(unlang_stack_t *stack, unlang_stack_frame_t { unlang_t const *instruction = frame->instruction; unlang_op_t *op; + char const *name; op = &unlang_ops[instruction->type]; + name = op->frame_state_name ? op->frame_state_name : __location__; frame->interpret = op->interpret; frame->signal = op->signal; +#ifdef HAVE_TALLOC_ZERO_POOLED_OBJECT /* - * The frame needs to track state. Do so here. + * Pooled object */ - if (op->frame_state_size) { - char const *name = op->frame_state_name ? op->frame_state_name : __location__; - -#ifdef HAVE_TALLOC_ZERO_POOLED_OBJECT - if (op->frame_state_pool_size) { - MEM(frame->state = _talloc_zero_pooled_object(stack, - op->frame_state_size, name, - op->frame_state_pool_objects, - op->frame_state_pool_size)); - } + if (op->frame_state_pool_size && op->frame_state_size) { + MEM(frame->state = _talloc_zero_pooled_object(stack, + op->frame_state_size, name, + op->frame_state_pool_objects, + op->frame_state_pool_size)); + } else #endif - else { - MEM(frame->state = _talloc_zero(stack, op->frame_state_size, name)); - } + /* + * Pool + */ + if (op->frame_state_pool_size && !op->frame_state_size) { + MEM(frame->state = talloc_pool(stack, + op->frame_state_pool_size + + ((20 + 68 + 15) * op->frame_state_pool_objects))); /* from samba talloc.c */ + talloc_set_name_const(frame->state, name); + /* + * Object + */ + } else if (op->frame_state_size) { + MEM(frame->state = _talloc_zero(stack, op->frame_state_size, name)); } } -- 2.47.3