diff mbox series

Lua: Lua'ify l_register_handler() error path

Message ID 20171010102206.17038-1-christian.storm@siemens.com
State Accepted
Headers show
Series Lua: Lua'ify l_register_handler() error path | expand

Commit Message

Storm, Christian Oct. 10, 2017, 10:22 a.m. UTC
Since l_register_handler() is called from the Lua realm,
return the count of return values, which is 0, instead
of -1. Also clean up the stack in the error code path.

Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 corelib/lua_interface.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Stefano Babic Oct. 12, 2017, 9:37 a.m. UTC | #1
On 10/10/2017 12:22, Christian Storm wrote:
> Since l_register_handler() is called from the Lua realm,
> return the count of return values, which is 0, instead
> of -1. Also clean up the stack in the error code path.
> 
> Signed-off-by: Christian Storm <christian.storm@siemens.com>
> ---
>  corelib/lua_interface.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
> index 5b7860f..39ed01f 100644
> --- a/corelib/lua_interface.c
> +++ b/corelib/lua_interface.c
> @@ -480,7 +480,8 @@ static int l_register_handler( lua_State *L ) {
>  	int *l_func_ref = malloc(sizeof(int));
>  	if(!l_func_ref) {
>  		ERROR("lua handler: unable to allocate memory\n");
> -		return -1;
> +		lua_pop(L, 2);
> +		return 0;
>  	} else {
>  		const char *handler_desc = luaL_checkstring(L, 1);
>  		/* store the callback function in registry */
> 

Applied to -master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index 5b7860f..39ed01f 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -480,7 +480,8 @@  static int l_register_handler( lua_State *L ) {
 	int *l_func_ref = malloc(sizeof(int));
 	if(!l_func_ref) {
 		ERROR("lua handler: unable to allocate memory\n");
-		return -1;
+		lua_pop(L, 2);
+		return 0;
 	} else {
 		const char *handler_desc = luaL_checkstring(L, 1);
 		/* store the callback function in registry */