]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: Do not use time_t as a special Lua encoder/decoder 14128/head
authorDonatas Abraitis <donatas@opensourcerouting.org>
Tue, 1 Aug 2023 11:08:25 +0000 (14:08 +0300)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Wed, 2 Aug 2023 04:53:38 +0000 (04:53 +0000)
This is purely an integer (long long/long), and causes issues for 32-bit systems.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
(cherry picked from commit 27dbf81a7375ccb352a35261c6c9ee3aa3fcb98f)

bgpd/bgp_script.c
lib/frrlua.c
lib/frrlua.h
lib/frrscript.c
lib/frrscript.h
tests/lib/test_frrlua.c

index f4ab23352434f624c082365f0354f2aaf3d7c489..68df175c186bb371007e176e3aca790eeb0bf7b4 100644 (file)
@@ -30,11 +30,11 @@ void lua_pushpeer(lua_State *L, const struct peer *peer)
        lua_setfield(L, -2, "state");
        lua_pushstring(L, peer->desc ? peer->desc : "");
        lua_setfield(L, -2, "description");
-       lua_pushtimet(L, &peer->uptime);
+       lua_pushinteger(L, peer->uptime);
        lua_setfield(L, -2, "uptime");
-       lua_pushtimet(L, &peer->readtime);
+       lua_pushinteger(L, peer->readtime);
        lua_setfield(L, -2, "last_readtime");
-       lua_pushtimet(L, &peer->resettime);
+       lua_pushinteger(L, peer->resettime);
        lua_setfield(L, -2, "last_resettime");
        lua_pushsockunion(L, peer->su_local);
        lua_setfield(L, -2, "local_address");
index 5b49d32a9cf47b70d7dbe6bdafb75380b671ab95..e626efe20b65fc605db71a32da820fd90a48329a 100644 (file)
@@ -259,25 +259,6 @@ void *lua_tosockunion(lua_State *L, int idx)
        return su;
 }
 
-void lua_pushtimet(lua_State *L, const time_t *time)
-{
-       lua_pushinteger(L, *time);
-}
-
-void lua_decode_timet(lua_State *L, int idx, time_t *t)
-{
-       *t = lua_tointeger(L, idx);
-       lua_pop(L, 1);
-}
-
-void *lua_totimet(lua_State *L, int idx)
-{
-       time_t *t = XCALLOC(MTYPE_SCRIPT_RES, sizeof(time_t));
-
-       lua_decode_timet(L, idx, t);
-       return t;
-}
-
 void lua_pushintegerp(lua_State *L, const long long *num)
 {
        lua_pushinteger(L, *num);
index bf6eb5fd913bb926f1334a90bc272d459d4be9c9..d248312d625f46f3dcfbfac786016dd275cc7f1a 100644 (file)
@@ -99,21 +99,6 @@ void lua_pushethaddr(lua_State *L, const struct ethaddr *addr);
  */
 void *lua_toin6addr(lua_State *L, int idx);
 
-/*
- * Converts a time_t to a Lua value and pushes it on the stack.
- */
-void lua_pushtimet(lua_State *L, const time_t *time);
-
-void lua_decode_timet(lua_State *L, int idx, time_t *time);
-
-/*
- * Converts the Lua value at idx to a time_t.
- *
- * Returns:
- *    time_t allocated with MTYPE_TMP.
- */
-void *lua_totimet(lua_State *L, int idx);
-
 /*
  * Converts a sockunion to a Lua value and pushes it on the stack.
  */
index 1b99c7e2c6df5efcb333367d2b6c601335733ea8..50410fb58bd66310c2a6d44a455fcd601c4716c8 100644 (file)
@@ -133,9 +133,6 @@ struct frrscript_codec frrscript_codecs_lib[] = {
        {.typename = "sockunion",
         .encoder = (encoder_func)lua_pushsockunion,
         .decoder = lua_tosockunion},
-       {.typename = "time_t",
-        .encoder = (encoder_func)lua_pushtimet,
-        .decoder = lua_totimet},
        {}};
 
 /* Type codecs */
index 7ba4f0cbdb03507ffb91483451e70fd0dcc0392c..df49b5718c1d335afe458c4ef0d609bded6a087d 100644 (file)
@@ -198,7 +198,6 @@ struct interface * : lua_pushinterface,                         \
 struct in_addr * : lua_pushinaddr,                              \
 struct in6_addr * : lua_pushin6addr,                            \
 union sockunion * : lua_pushsockunion,                          \
-time_t * : lua_pushtimet,                                       \
 char * : lua_pushstring_wrapper,                                \
 struct attr * : lua_pushattr,                                   \
 struct peer * : lua_pushpeer,                                   \
@@ -219,7 +218,6 @@ struct interface * : lua_decode_interface,                      \
 struct in_addr * : lua_decode_inaddr,                           \
 struct in6_addr * : lua_decode_in6addr,                         \
 union sockunion * : lua_decode_sockunion,                       \
-time_t * : lua_decode_timet,                                    \
 char * : lua_decode_stringp,                                    \
 struct attr * : lua_decode_attr,                                \
 struct peer * : lua_decode_noop,                                \
index 4f492db5bf1d88148ad8544de513feead86776cb..701e171c84ac8d5a92ab055c0dc64099b20d29ac 100644 (file)
@@ -22,10 +22,11 @@ static void test_encode_decode(void)
        assert(lua_gettop(L) == 0);
 
        time_t time_a = 100;
-       time_t time_b = time_a;
+       time_t time_b;
 
-       lua_pushtimet(L, &time_a);
-       lua_decode_timet(L, -1, &time_a);
+       lua_pushinteger(L, time_a);
+       time_b = lua_tointeger(L, -1);
+       lua_pop(L, 1);
        assert(time_a == time_b);
        assert(lua_gettop(L) == 0);