From: Arran Cudbard-Bell Date: Sat, 7 Sep 2019 05:19:55 +0000 (-0500) Subject: I guess we just can't use an enum for flag fields anymore... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66df975598a396a4d2fc513ae73068da06d8a97b;p=thirdparty%2Ffreeradius-server.git I guess we just can't use an enum for flag fields anymore... --- diff --git a/src/lib/unlang/foreach.c b/src/lib/unlang/foreach.c index 8dd0891deca..c2ca43a0d24 100644 --- a/src/lib/unlang/foreach.c +++ b/src/lib/unlang/foreach.c @@ -185,15 +185,14 @@ static unlang_action_t unlang_break(REQUEST *request, rlm_rcode_t *presult, int RDEBUG2("%s", unlang_ops[instruction->type].name); + *presult = frame->result; + *priority = frame->priority; + /* * Stop at the next break point, or if we hit * the a top frame. */ - stack->unwind = UNWIND_FLAG_BREAK_POINT | UNWIND_FLAG_TOP_FRAME; - - *presult = frame->result; - *priority = frame->priority; - + UNWIND_TO_BREAK(stack); return UNLANG_ACTION_UNWIND; } diff --git a/src/lib/unlang/interpret.c b/src/lib/unlang/interpret.c index a367bafe858..f0808d52f0a 100644 --- a/src/lib/unlang/interpret.c +++ b/src/lib/unlang/interpret.c @@ -484,7 +484,7 @@ static inline unlang_frame_action_t frame_eval(REQUEST *request, unlang_stack_fr do_stop: frame->result = RLM_MODULE_FAIL; frame->priority = 9999; - stack->unwind = UNWIND_FLAG_TOP_FRAME | UNWIND_FLAG_NO_CLEAR; + UNWIND_ALL(stack); break; } diff --git a/src/lib/unlang/return.c b/src/lib/unlang/return.c index 5454af820a5..4f0feea6c37 100644 --- a/src/lib/unlang/return.c +++ b/src/lib/unlang/return.c @@ -35,15 +35,14 @@ unlang_action_t unlang_return(REQUEST *request, rlm_rcode_t *presult, int *prior RDEBUG2("%s", unlang_ops[instruction->type].name); + *presult = frame->result; + *priority = frame->priority; + /* * Stop at the next return point, or if we hit * the a top frame. */ - stack->unwind = UNWIND_FLAG_RETURN_POINT | UNWIND_FLAG_TOP_FRAME; - - *presult = frame->result; - *priority = frame->priority; - + UNWIND_TO_RETURN(stack); return UNLANG_ACTION_UNWIND; } diff --git a/src/lib/unlang/unlang_priv.h b/src/lib/unlang/unlang_priv.h index 2d88568630a..4c6229c2faa 100644 --- a/src/lib/unlang/unlang_priv.h +++ b/src/lib/unlang/unlang_priv.h @@ -234,39 +234,36 @@ typedef struct { unlang_t *found; } unlang_frame_state_redundant_t; -typedef enum { - UNWIND_FLAG_NONE = 0x00, //!< No flags. - UNWIND_FLAG_REPEAT = 0x01, //!< Repeat the frame on the way up the stack. - UNWIND_FLAG_TOP_FRAME = 0x02, //!< are we the top frame of the stack? +#define UNWIND_FLAG_NONE 0x00 //!< No flags. +#define UNWIND_FLAG_REPEAT 0x01 //!< Repeat the frame on the way up the stack. +#define UNWIND_FLAG_TOP_FRAME 0x02 //!< are we the top frame of the stack? ///< If true, causes the interpreter to stop ///< interpreting and return, control then passes ///< to whatever called the interpreter. - UNWIND_FLAG_BREAK_POINT = 0x04, //!< 'break' stops here. - UNWIND_FLAG_RETURN_POINT = 0x08, //!< 'return' stops here. - UNWIND_FLAG_NO_CLEAR = 0x10, //!< Keep unwinding, don't clear the unwind flag. - UNWIND_FLAG_MAX = 0xff -} unlang_unwind_flags_t; +#define UNWIND_FLAG_BREAK_POINT 0x04 //!< 'break' stops here. +#define UNWIND_FLAG_RETURN_POINT 0x08 //!< 'return' stops here. +#define UNWIND_FLAG_NO_CLEAR 0x10 //!< Keep unwinding, don't clear the unwind flag. + #define repeatable_set(_frame) ((_frame)->uflags |= UNWIND_FLAG_REPEAT) #define top_frame_set(_frame) ((_frame)->uflags |= UNWIND_FLAG_TOP_FRAME) #define break_point_set(_frame) ((_frame)->uflags |= UNWIND_FLAG_BREAK_POINT) #define return_point_set(_frame) ((_frame)->uflags |= UNWIND_FLAG_RETURN_POINT) -/* - * clang doesn't like the fact that the masks - * are outside the range of values the enum - * can represent *sigh* - */ -#define repeatable_clear(_frame) ((_frame)->uflags) -= (((_frame)->uflags) & UNWIND_FLAG_REPEAT) -#define top_frame_clear(_frame) ((_frame)->uflags) -= (((_frame)->uflags) & UNWIND_FLAG_TOP_FRAME) -#define break_point_clear(_frame) ((_frame)->uflags) -= (((_frame)->uflags) & UNWIND_FLAG_BREAK_POINT) -#define return_point_clear(_frame) ((_frame)->uflags) -= (((_frame)->uflags) & UNWIND_FLAG_RETURN_POINT) +#define repeatable_clear(_frame) ((_frame)->uflags) &= ~UNWIND_FLAG_REPEAT +#define top_frame_clear(_frame) ((_frame)->uflags) &= ~UNWIND_FLAG_TOP_FRAME +#define break_point_clear(_frame) ((_frame)->uflags) &= ~UNWIND_FLAG_BREAK_POINT +#define return_point_clear(_frame) ((_frame)->uflags) &= ~UNWIND_FLAG_RETURN_POINT #define is_repeatable(_frame) ((_frame)->uflags & UNWIND_FLAG_REPEAT) #define is_top_frame(_frame) ((_frame)->uflags & UNWIND_FLAG_TOP_FRAME) #define is_break_point(_frame) ((_frame)->uflags & UNWIND_FLAG_BREAK_POINT) #define is_return_point(_frame) ((_frame)->uflags & UNWIND_FLAG_RETURN_POINT) +#define UNWIND_TO_BREAK(_stack) ((_stack)->unwind = (UNWIND_FLAG_BREAK_POINT | UNWIND_FLAG_TOP_FRAME)) +#define UNWIND_TO_RETURN(_stack) ((_stack)->unwind = (UNWIND_FLAG_RETURN_POINT | UNWIND_FLAG_TOP_FRAME)) +#define UNWIND_ALL(_stack) ((_stack)->unwind = (UNWIND_FLAG_TOP_FRAME | UNWIND_FLAG_NO_CLEAR)) + /** Our interpreter stack, as distinct from the C stack * * We don't call the modules recursively. Instead we iterate over a list of #unlang_t and @@ -300,7 +297,7 @@ typedef struct { ///< frame lower in the stack to determine if the ///< result stored in the lower stack frame should ///< be replaced. - unlang_unwind_flags_t uflags; //!< Unwind markers + uint8_t uflags; //!< Unwind markers } unlang_stack_frame_t; /** An unlang stack associated with a request @@ -309,7 +306,7 @@ typedef struct { typedef struct { rlm_rcode_t result; //!< The current stack rcode. int depth; //!< Current depth we're executing at. - unlang_unwind_flags_t unwind; //!< Unwind to this frame if it exists. + uint8_t unwind; //!< Unwind to this frame if it exists. ///< This is used for break and return. unlang_stack_frame_t frame[UNLANG_STACK_MAX]; //!< The stack... } unlang_stack_t;