]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG/MINOR: lua: convert boolean "int" to bitfield
authorThierry FOURNIER <tfournier@arpalert.org>
Sun, 20 Dec 2015 17:42:25 +0000 (18:42 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 20 Dec 2015 22:13:00 +0000 (23:13 +0100)
This patch converts a boolean "int" to a bitfiled. The main
reason is to save space in the struct if another flag may will
be require.

Note that this patch is required for next fix and will need to be
backported to 1.6.

include/types/hlua.h
src/hlua.c

index a9b6498f383ffe376d2e5a013377761ba219d320..fd7b7d3c52b350fba699cc18b6d78972a066b997 100644 (file)
@@ -29,6 +29,8 @@ struct stream;
 #define HLUA_EXIT      0x00000010
 #define HLUA_MUST_GC   0x00000020
 
+#define HLUA_F_AS_STRING    0x01
+
 enum hlua_exec {
        HLUA_E_OK = 0,
        HLUA_E_AGAIN,  /* LUA yield, must resume the stack execution later, when
@@ -114,7 +116,7 @@ struct hlua_appctx {
 struct hlua_smp {
        struct stream *s;
        struct proxy *p;
-       int stringsafe;
+       unsigned int flags;     /* LUA_F_OPT_* */
        int dir;                /* SMP_OPT_DIR_{REQ,RES} */
 };
 
index a03b9ddd96175424e1a15491abdf725b585989fc..43c73f6e28a0fc14fb81ff868b901c287cedacfb 100644 (file)
@@ -2961,7 +2961,7 @@ __LJMP static struct hlua_smp *hlua_checkfetches(lua_State *L, int ud)
 /* This function creates and push in the stack a fetch object according
  * with a current TXN.
  */
-static int hlua_fetches_new(lua_State *L, struct hlua_txn *txn, int stringsafe)
+static int hlua_fetches_new(lua_State *L, struct hlua_txn *txn, unsigned int flags)
 {
        struct hlua_smp *hsmp;
 
@@ -2980,7 +2980,7 @@ static int hlua_fetches_new(lua_State *L, struct hlua_txn *txn, int stringsafe)
        hsmp->s = txn->s;
        hsmp->p = txn->p;
        hsmp->dir = txn->dir;
-       hsmp->stringsafe = stringsafe;
+       hsmp->flags = flags;
 
        /* Pop a class sesison metatable and affect it to the userdata. */
        lua_rawgeti(L, LUA_REGISTRYINDEX, class_fetches_ref);
@@ -3035,7 +3035,7 @@ __LJMP static int hlua_run_sample_fetch(lua_State *L)
        smp.strm = hsmp->s;
        smp.opt = hsmp->dir & SMP_OPT_DIR;
        if (!f->process(args, &smp, f->kw, f->private)) {
-               if (hsmp->stringsafe)
+               if (hsmp->flags & HLUA_F_AS_STRING)
                        lua_pushstring(L, "");
                else
                        lua_pushnil(L);
@@ -3043,7 +3043,7 @@ __LJMP static int hlua_run_sample_fetch(lua_State *L)
        }
 
        /* Convert the returned sample in lua value. */
-       if (hsmp->stringsafe)
+       if (hsmp->flags & HLUA_F_AS_STRING)
                hlua_smp2lua_str(L, &smp);
        else
                hlua_smp2lua(L, &smp);
@@ -3069,7 +3069,7 @@ __LJMP static struct hlua_smp *hlua_checkconverters(lua_State *L, int ud)
 /* This function creates and push in the stack a Converters object
  * according with a current TXN.
  */
-static int hlua_converters_new(lua_State *L, struct hlua_txn *txn, int stringsafe)
+static int hlua_converters_new(lua_State *L, struct hlua_txn *txn, unsigned int flags)
 {
        struct hlua_smp *hsmp;
 
@@ -3088,7 +3088,7 @@ static int hlua_converters_new(lua_State *L, struct hlua_txn *txn, int stringsaf
        hsmp->s = txn->s;
        hsmp->p = txn->p;
        hsmp->dir = txn->dir;
-       hsmp->stringsafe = stringsafe;
+       hsmp->flags = flags;
 
        /* Pop a class stream metatable and affect it to the table. */
        lua_rawgeti(L, LUA_REGISTRYINDEX, class_converters_ref);
@@ -3158,7 +3158,7 @@ __LJMP static int hlua_run_sample_conv(lua_State *L)
        smp.strm = hsmp->s;
        smp.opt = hsmp->dir & SMP_OPT_DIR;
        if (!conv->process(args, &smp, conv->private)) {
-               if (hsmp->stringsafe)
+               if (hsmp->flags & HLUA_F_AS_STRING)
                        lua_pushstring(L, "");
                else
                        lua_pushnil(L);
@@ -3166,7 +3166,7 @@ __LJMP static int hlua_run_sample_conv(lua_State *L)
        }
 
        /* Convert the returned sample in lua value. */
-       if (hsmp->stringsafe)
+       if (hsmp->flags & HLUA_F_AS_STRING)
                hlua_smp2lua_str(L, &smp);
        else
                hlua_smp2lua(L, &smp);
@@ -3222,7 +3222,7 @@ static int hlua_applet_tcp_new(lua_State *L, struct appctx *ctx)
 
        /* Create the "sf" field that contains a list of stringsafe fetches. */
        lua_pushstring(L, "sf");
-       if (!hlua_fetches_new(L, &appctx->htxn, 1))
+       if (!hlua_fetches_new(L, &appctx->htxn, HLUA_F_AS_STRING))
                return 0;
        lua_settable(L, -3);
 
@@ -3234,7 +3234,7 @@ static int hlua_applet_tcp_new(lua_State *L, struct appctx *ctx)
 
        /* Create the "sc" field that contains a list of stringsafe converters. */
        lua_pushstring(L, "sc");
-       if (!hlua_converters_new(L, &appctx->htxn, 1))
+       if (!hlua_converters_new(L, &appctx->htxn, HLUA_F_AS_STRING))
                return 0;
        lua_settable(L, -3);
 
@@ -3509,7 +3509,7 @@ static int hlua_applet_http_new(lua_State *L, struct appctx *ctx)
 
        /* Create the "sf" field that contains a list of stringsafe fetches. */
        lua_pushstring(L, "sf");
-       if (!hlua_fetches_new(L, &appctx->htxn, 1))
+       if (!hlua_fetches_new(L, &appctx->htxn, HLUA_F_AS_STRING))
                return 0;
        lua_settable(L, -3);
 
@@ -3521,7 +3521,7 @@ static int hlua_applet_http_new(lua_State *L, struct appctx *ctx)
 
        /* Create the "sc" field that contains a list of stringsafe converters. */
        lua_pushstring(L, "sc");
-       if (!hlua_converters_new(L, &appctx->htxn, 1))
+       if (!hlua_converters_new(L, &appctx->htxn, HLUA_F_AS_STRING))
                return 0;
        lua_settable(L, -3);
 
@@ -4634,7 +4634,7 @@ static int hlua_txn_new(lua_State *L, struct stream *s, struct proxy *p, int dir
 
        /* Create the "sf" field that contains a list of stringsafe fetches. */
        lua_pushstring(L, "sf");
-       if (!hlua_fetches_new(L, htxn, 1))
+       if (!hlua_fetches_new(L, htxn, HLUA_F_AS_STRING))
                return 0;
        lua_rawset(L, -3);
 
@@ -4646,7 +4646,7 @@ static int hlua_txn_new(lua_State *L, struct stream *s, struct proxy *p, int dir
 
        /* Create the "sc" field that contains a list of stringsafe converters. */
        lua_pushstring(L, "sc");
-       if (!hlua_converters_new(L, htxn, 1))
+       if (!hlua_converters_new(L, htxn, HLUA_F_AS_STRING))
                return 0;
        lua_rawset(L, -3);