]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-lua: Rewrite arg checking macros to use STMT_{START,END}
authorJosef 'Jeff' Sipek <jeff.sipek@open-xchange.com>
Wed, 25 Nov 2020 16:03:57 +0000 (11:03 -0500)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Thu, 3 Dec 2020 13:06:30 +0000 (13:06 +0000)
This makes it safer to use.  Additionally, this commit adds some newlines to
the macro definition to make it more readable.

src/lib-lua/dlua-script-private.h

index bbacc2fcf96296e028ea768fdab01603a385c475..e4c0243e6b3deb06af7f91aef2c98c4a2e113ab2 100644 (file)
@@ -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;