From ebaf611123e405af3fcf1f59aa542198bc5c95b3 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 27 Oct 2013 22:02:20 +0000 Subject: [PATCH] Avoid endless recursion in export ucl to lua. --- src/lua/lua_common.h | 2 +- src/lua/lua_config.c | 4 ++-- src/lua/lua_rcl.c | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index c878a50f3..e2e2f032a 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -107,7 +107,7 @@ void free_lua_locked (struct lua_locked_state *st); * @param L lua state * @param obj object to push */ -gint lua_rcl_obj_push (lua_State *L, ucl_object_t *obj); +gint lua_rcl_obj_push (lua_State *L, ucl_object_t *obj, gboolean allow_array); /** * Extract rcl object from lua object diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index df8526d0f..4e8e6eb6d 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -163,7 +163,7 @@ lua_config_get_module_opt (lua_State * L) if (mname && optname) { obj = get_module_opt (cfg, mname, optname); if (obj) { - return lua_rcl_obj_push (L, obj); + return lua_rcl_obj_push (L, obj, TRUE); } } } @@ -198,7 +198,7 @@ lua_config_get_all_opt (lua_State * L) if (mname) { obj = ucl_obj_get_key (cfg->rcl_obj, mname); if (obj != NULL) { - return lua_rcl_obj_push (L, obj); + return lua_rcl_obj_push (L, obj, TRUE); } } } diff --git a/src/lua/lua_rcl.c b/src/lua/lua_rcl.c index b695f4f11..1c03fa62b 100644 --- a/src/lua/lua_rcl.c +++ b/src/lua/lua_rcl.c @@ -28,7 +28,7 @@ */ static gint lua_rcl_obj_push_array (lua_State *L, ucl_object_t *obj); -static gint lua_rcl_obj_push_simple (lua_State *L, ucl_object_t *obj); +static gint lua_rcl_obj_push_simple (lua_State *L, ucl_object_t *obj, gboolean allow_array); static void lua_rcl_table_get (lua_State *L, ucl_object_t *top, gint idx); static void lua_rcl_elt_get (lua_State *L, ucl_object_t *top, gint idx); @@ -42,7 +42,7 @@ static void lua_rcl_obj_push_elt (lua_State *L, const char *key, ucl_object_t *obj) { lua_pushstring (L, key); - lua_rcl_obj_push (L, obj); + lua_rcl_obj_push (L, obj, TRUE); lua_settable (L, -3); } @@ -85,7 +85,7 @@ lua_rcl_obj_push_array (lua_State *L, ucl_object_t *obj) lua_newtable (L); LL_FOREACH (obj, cur) { - lua_rcl_obj_push (L, cur); + lua_rcl_obj_push (L, cur, FALSE); lua_rawseti (L, -2, i); i ++; } @@ -97,9 +97,9 @@ lua_rcl_obj_push_array (lua_State *L, ucl_object_t *obj) * Push a simple object to lua depending on its actual type */ static gint -lua_rcl_obj_push_simple (lua_State *L, ucl_object_t *obj) +lua_rcl_obj_push_simple (lua_State *L, ucl_object_t *obj, gboolean allow_array) { - if (obj->next != NULL) { + if (allow_array && obj->next != NULL) { /* Actually we need to push this as an array */ return lua_rcl_obj_push_array (L, obj); } @@ -136,7 +136,7 @@ lua_rcl_obj_push_simple (lua_State *L, ucl_object_t *obj) * @param obj object to push */ gint -lua_rcl_obj_push (lua_State *L, ucl_object_t *obj) +lua_rcl_obj_push (lua_State *L, ucl_object_t *obj, gboolean allow_array) { switch (obj->type) { case UCL_OBJECT: @@ -144,7 +144,7 @@ lua_rcl_obj_push (lua_State *L, ucl_object_t *obj) case UCL_ARRAY: return lua_rcl_obj_push_array (L, obj->value.ov); default: - return lua_rcl_obj_push_simple (L, obj); + return lua_rcl_obj_push_simple (L, obj, allow_array); } } -- 2.39.5