From: Josef 'Jeff' Sipek Date: Wed, 25 Nov 2020 16:03:57 +0000 (-0500) Subject: lib-lua: Rewrite arg checking macros to use STMT_{START,END} X-Git-Tag: 2.3.14.rc1~285 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dd8f5d776e9576b668aee16a88e9f1393f22622d;p=thirdparty%2Fdovecot%2Fcore.git lib-lua: Rewrite arg checking macros to use STMT_{START,END} This makes it safer to use. Additionally, this commit adds some newlines to the macro definition to make it more readable. --- diff --git a/src/lib-lua/dlua-script-private.h b/src/lib-lua/dlua-script-private.h index bbacc2fcf9..e4c0243e6b 100644 --- a/src/lib-lua/dlua-script-private.h +++ b/src/lib-lua/dlua-script-private.h @@ -35,8 +35,20 @@ void luaL_setmetatable (lua_State *L, const char *tname); #define DLUA_TABLE_NULL(n, s) { .name = (n), .type = DLUA_TABLE_VALUE_NULL } #define DLUA_TABLE_END { .name = NULL } -#define DLUA_REQUIRE_ARGS_IN(s,x,y) if (lua_gettop((s)->L) < (x) || lua_gettop((s)->L) > (y)) { return luaL_error((s)->L, "expected %d to %d arguments, got %d", x, y, lua_gettop((s)->L)); } -#define DLUA_REQUIRE_ARGS(s,x) if (lua_gettop((s)->L) != (x)) { return luaL_error((s)->L, "expected %d arguments, got %d", (x), lua_gettop((s)->L)); } +#define DLUA_REQUIRE_ARGS_IN(s, x, y) \ + STMT_START { \ + if (lua_gettop((s)->L) < (x) || lua_gettop((s)->L) > (y)) { \ + return luaL_error((s)->L, "expected %d to %d arguments, got %d", \ + (x), (y), lua_gettop((s)->L)); \ + } \ + } STMT_END +#define DLUA_REQUIRE_ARGS(s, x) \ + STMT_START { \ + if (lua_gettop((s)->L) != (x)) { \ + return luaL_error((s)->L, "expected %d arguments, got %d", \ + (x), lua_gettop((s)->L)); \ + } \ + } STMT_END struct dlua_script { struct dlua_script *prev,*next;