diff mbox series

BUG: bootenv functions not available

Message ID 20240703130807.433489-1-stefano.babic@swupdate.org
State Changes Requested
Headers show
Series BUG: bootenv functions not available | expand

Commit Message

Stefano Babic July 3, 2024, 1:08 p.m. UTC
commit f8153 introduced a regression bug. The bootenv functions are not
registered anymore and they cannot be called from scripts. They were
handled separately, but after switching to a Lua Session State, there is
no need for this and the function can be added together with the rest of
the interface.

Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
---
 corelib/lua_interface.c | 6 ------
 1 file changed, 6 deletions(-)

--
2.34.1

Comments

Storm, Christian July 3, 2024, 2:30 p.m. UTC | #1
Hi Stefano,

> commit f8153 introduced a regression bug. The bootenv functions are not
> registered anymore and they cannot be called from scripts. They were
> handled separately, but after switching to a Lua Session State, there is
> no need for this and the function can be added together with the rest of
> the interface.
> 
> Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
> ---
> corelib/lua_interface.c | 6 ------
> 1 file changed, 6 deletions(-)
> 
> diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
> index 74590ab6..86c2112d 100644
> --- a/corelib/lua_interface.c
> +++ b/corelib/lua_interface.c
> @@ -1195,10 +1195,6 @@ static const luaL_Reg l_swupdate[] = {
>         { "getversion", lua_get_swupdate_version },
>         { "progress", lua_notify_progress },
>         { "emmcbootpart", l_get_emmc_bootpart },
> -        { NULL, NULL }
> -};
> -
> -static const luaL_Reg l_swupdate_bootenv[] = {
>         { "get_bootenv", l_get_bootenv },
>         { "set_bootenv", l_set_bootenv },
>         { "get_selection", l_get_selection },
> @@ -1319,7 +1315,6 @@ static int l_handler_wrapper(struct img_type *img, void *data,
> }
> struct dict **udbootenv = lua_newuserdata(L, sizeof(struct dict*));
> *udbootenv = img->bootloader;

This is a local and now unused variable since it's no longer used for upvalue storage by the following removed line:

> - luaL_setfuncs(L, l_swupdate_bootenv, 1);
> lua_pop(L, 1);

This does leave the lua_getglobal(L, "swupdate") result on the stack.

> }
> 
> @@ -1549,7 +1544,6 @@ lua_State *lua_session_init(struct dict *bootenv)
> luaL_requiref(L, "swupdate", luaopen_swupdate, 1 );
> struct dict **udbootenv = lua_newuserdata(L, sizeof(struct dict*));
> *udbootenv = bootenv;

See above.

> - luaL_setfuncs(L, l_swupdate_bootenv, 1);
> lua_pop(L, 1); /* remove unused copy left on stack */

See above, this removes the pushed userdata but leaves the luaL_requiref(L, "swupdate", luaopen_swupdate, 1 ) return table on the stack.


With this and the other patch, I'm wondering where the upvalue used in l_set_bootenv() [https://github.com/sbabic/swupdate/blob/master/corelib/lua_interface.c#L886] is set? It's also removed for handlers in the follow-up patch but nowhere set? Am I missing something?



Kind regards,
  Christian
Stefano Babic July 3, 2024, 6:29 p.m. UTC | #2
Hi Christian,

On 03.07.24 16:30, 'Storm, Christian' via swupdate wrote:
> Hi Stefano,
>
>> commit f8153 introduced a regression bug. The bootenv functions are not
>> registered anymore and they cannot be called from scripts. They were
>> handled separately, but after switching to a Lua Session State, there is
>> no need for this and the function can be added together with the rest of
>> the interface.
>>
>> Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
>> ---
>> corelib/lua_interface.c | 6 ------
>> 1 file changed, 6 deletions(-)
>>
>> diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
>> index 74590ab6..86c2112d 100644
>> --- a/corelib/lua_interface.c
>> +++ b/corelib/lua_interface.c
>> @@ -1195,10 +1195,6 @@ static const luaL_Reg l_swupdate[] = {
>>          { "getversion", lua_get_swupdate_version },
>>          { "progress", lua_notify_progress },
>>          { "emmcbootpart", l_get_emmc_bootpart },
>> -        { NULL, NULL }
>> -};
>> -
>> -static const luaL_Reg l_swupdate_bootenv[] = {
>>          { "get_bootenv", l_get_bootenv },
>>          { "set_bootenv", l_set_bootenv },
>>          { "get_selection", l_get_selection },
>> @@ -1319,7 +1315,6 @@ static int l_handler_wrapper(struct img_type *img, void *data,
>> }
>> struct dict **udbootenv = lua_newuserdata(L, sizeof(struct dict*));
>> *udbootenv = img->bootloader;
>
> This is a local and now unused variable since it's no longer used for upvalue storage by the following removed line:
>
>> - luaL_setfuncs(L, l_swupdate_bootenv, 1);
>> lua_pop(L, 1);
>
> This does leave the lua_getglobal(L, "swupdate") result on the stack.
>
>> }
>>
>> @@ -1549,7 +1544,6 @@ lua_State *lua_session_init(struct dict *bootenv)
>> luaL_requiref(L, "swupdate", luaopen_swupdate, 1 );
>> struct dict **udbootenv = lua_newuserdata(L, sizeof(struct dict*));
>> *udbootenv = bootenv;
>
> See above.
>
>> - luaL_setfuncs(L, l_swupdate_bootenv, 1);
>> lua_pop(L, 1); /* remove unused copy left on stack */
>
> See above, this removes the pushed userdata but leaves the luaL_requiref(L, "swupdate", luaopen_swupdate, 1 ) return table on the stack.
>
>
> With this and the other patch, I'm wondering where the upvalue used in l_set_bootenv() [https://github.com/sbabic/swupdate/blob/master/corelib/lua_interface.c#L886] is set? It's also removed for handlers in the follow-up patch but nowhere set? Am I missing something?

No, you're absolutely right and this patch is *garbage*. I will create a
test first, and check in detail for next version. Both patches could be
discarded.

Thanks,
Stefano

>
>
>
> Kind regards,
>    Christian
>
diff mbox series

Patch

diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index 74590ab6..86c2112d 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -1195,10 +1195,6 @@  static const luaL_Reg l_swupdate[] = {
         { "getversion", lua_get_swupdate_version },
         { "progress", lua_notify_progress },
         { "emmcbootpart", l_get_emmc_bootpart },
-        { NULL, NULL }
-};
-
-static const luaL_Reg l_swupdate_bootenv[] = {
         { "get_bootenv", l_get_bootenv },
         { "set_bootenv", l_set_bootenv },
         { "get_selection", l_get_selection },
@@ -1319,7 +1315,6 @@  static int l_handler_wrapper(struct img_type *img, void *data,
 		}
 		struct dict **udbootenv = lua_newuserdata(L, sizeof(struct dict*));
 		*udbootenv = img->bootloader;
-		luaL_setfuncs(L, l_swupdate_bootenv, 1);
 		lua_pop(L, 1);
 	}

@@ -1549,7 +1544,6 @@  lua_State *lua_session_init(struct dict *bootenv)
 	luaL_requiref(L, "swupdate", luaopen_swupdate, 1 );
 	struct dict **udbootenv = lua_newuserdata(L, sizeof(struct dict*));
 	*udbootenv = bootenv;
-	luaL_setfuncs(L, l_swupdate_bootenv, 1);
 	lua_pop(L, 1); /* remove unused copy left on stack */

 	lua_handlers_init(L);