mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-07-27 11:44:16 +00:00
Merge pull request #14128 from FRRouting/mergify/bp/stable/9.0/pr-14125
lib: Do not use time_t as a special Lua encoder/decoder (backport #14125)
This commit is contained in:
commit
7e2130bb03
@ -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");
|
||||
|
19
lib/frrlua.c
19
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);
|
||||
|
15
lib/frrlua.h
15
lib/frrlua.h
@ -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.
|
||||
*/
|
||||
|
@ -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 */
|
||||
|
@ -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, \
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user