diff options
| author | Donatas Abraitis <donatas@opensourcerouting.org> | 2023-08-01 14:08:25 +0300 |
|---|---|---|
| committer | Mergify <37929162+mergify[bot]@users.noreply.github.com> | 2023-08-02 04:53:38 +0000 |
| commit | 85728c9c4fddb1b62b4bf83ffcf4d5e92000cceb (patch) | |
| tree | e1a55eb11934893adc4eb609778615c19f26aece | |
| parent | 728976960bc669594e670c08de3b13779fdb06d8 (diff) | |
lib: Do not use time_t as a special Lua encoder/decoder
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)
| -rw-r--r-- | bgpd/bgp_script.c | 6 | ||||
| -rw-r--r-- | lib/frrlua.c | 19 | ||||
| -rw-r--r-- | lib/frrlua.h | 15 | ||||
| -rw-r--r-- | lib/frrscript.c | 3 | ||||
| -rw-r--r-- | lib/frrscript.h | 2 | ||||
| -rw-r--r-- | tests/lib/test_frrlua.c | 7 |
6 files changed, 7 insertions, 45 deletions
diff --git a/bgpd/bgp_script.c b/bgpd/bgp_script.c index f4ab233524..68df175c18 100644 --- a/bgpd/bgp_script.c +++ b/bgpd/bgp_script.c @@ -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"); diff --git a/lib/frrlua.c b/lib/frrlua.c index 5b49d32a9c..e626efe20b 100644 --- a/lib/frrlua.c +++ b/lib/frrlua.c @@ -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); diff --git a/lib/frrlua.h b/lib/frrlua.h index bf6eb5fd91..d248312d62 100644 --- a/lib/frrlua.h +++ b/lib/frrlua.h @@ -100,21 +100,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. */ void lua_pushsockunion(lua_State *L, const union sockunion *su); diff --git a/lib/frrscript.c b/lib/frrscript.c index 1b99c7e2c6..50410fb58b 100644 --- a/lib/frrscript.c +++ b/lib/frrscript.c @@ -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 */ diff --git a/lib/frrscript.h b/lib/frrscript.h index 7ba4f0cbdb..df49b5718c 100644 --- a/lib/frrscript.h +++ b/lib/frrscript.h @@ -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, \ diff --git a/tests/lib/test_frrlua.c b/tests/lib/test_frrlua.c index 4f492db5bf..701e171c84 100644 --- a/tests/lib/test_frrlua.c +++ b/tests/lib/test_frrlua.c @@ -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); |
