From b8b02bc0f6523496e4e14192897454deaa4f0f62 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov <kostja@tarantool.org> Date: Mon, 2 Sep 2013 19:25:54 +0400 Subject: [PATCH] yaml-null-conv: review fixes Add comment. Fix style. Update tests. --- src/lua/init.cc | 12 ++++++++++-- test/big/tree_pk_multipart.result | 4 ++-- test/box/alter.result | 6 +++--- test/box/fiber.result | 6 +++--- test/box/info.result | 6 +++--- test/box/ipc.result | 2 +- test/box/lua.result | 14 +++++++++----- test/box/lua_misc.result | 2 +- test/box/net.box.result | 2 +- third_party/lua-yaml/lyaml.c | 6 +++--- 10 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/lua/init.cc b/src/lua/init.cc index 394b204f04..0dccc9f95c 100644 --- a/src/lua/init.cc +++ b/src/lua/init.cc @@ -663,10 +663,18 @@ tarantool_lua(struct lua_State *L, lua_newtable(L); for (int i = 1; i <= top; i++) { lua_pushnumber(L, i); - if (lua_isnil(L, i)) + if (lua_isnil(L, i)) { + /** + * When storing a nil in a Lua table, + * there is no way to distinguish nil + * value from no value. This is a trick + * to make sure yaml converter correctly + * outputs nil values on the return stack. + */ lua_pushlightuserdata(L, NULL); - else + } else { lua_pushvalue(L, i); + } lua_rawset(L, -3); } lua_replace(L, 1); diff --git a/test/big/tree_pk_multipart.result b/test/big/tree_pk_multipart.result index edd9fbd95d..31adc49e68 100644 --- a/test/big/tree_pk_multipart.result +++ b/test/big/tree_pk_multipart.result @@ -395,7 +395,7 @@ k,v = space.index[1]:next(k) ... v --- -{} +- null ... collectgarbage('collect') --- @@ -403,7 +403,7 @@ collectgarbage('collect') ... v --- -{} +- null ... t = {} --- diff --git a/test/box/alter.result b/test/box/alter.result index 7d78da47fb..5e54f331de 100644 --- a/test/box/alter.result +++ b/test/box/alter.result @@ -94,7 +94,7 @@ space.arity ... space.index[0] --- -{} +- null ... -- -- check dml - the space has no indexes yet, but must not crash on DML @@ -127,7 +127,7 @@ space_deleted = box.space[box.unpack('i', t[0])] ... space_deleted --- -{} +- null ... space:replace(0) --- @@ -179,5 +179,5 @@ box.space[1000]:drop() ... box.space[1000] --- -{} +- null ... diff --git a/test/box/fiber.result b/test/box/fiber.result index ff6dd688e9..e1cd4b41f7 100644 --- a/test/box/fiber.result +++ b/test/box/fiber.result @@ -271,15 +271,15 @@ collectgarbage('collect') -- check that these newly created fibers are garbage collected box.fiber.find(900) --- -{} +- null ... box.fiber.find(910) --- -{} +- null ... box.fiber.find(920) --- -{} +- null ... space:drop() --- diff --git a/test/box/info.result b/test/box/info.result index 6e495a32db..d3d8d0d21f 100644 --- a/test/box/info.result +++ b/test/box/info.result @@ -2,15 +2,15 @@ -- make sure it's a valid YAML box.info.unknown_variable --- -{} +- null ... box.info[23] --- -{} +- null ... box.info['unknown_variable'] --- -{} +- null ... string.match(box.info.version, '^[1-9]') ~= nil --- diff --git a/test/box/ipc.result b/test/box/ipc.result index 3909a516fa..944381fc49 100644 --- a/test/box/ipc.result +++ b/test/box/ipc.result @@ -11,7 +11,7 @@ ch:is_empty() ... ch:get(.1) --- -{} +- null ... ch:put() --- diff --git a/test/box/lua.result b/test/box/lua.result index 964f54eab7..6cff707a91 100644 --- a/test/box/lua.result +++ b/test/box/lua.result @@ -230,6 +230,7 @@ f1() - -1 - 1.123 - 1e+123 +- null ... call f1() Found 7 tuples: @@ -749,6 +750,8 @@ f=box.fiber.create(r) box.fiber.resume(f) --- - true +- null +- null ... f=box.fiber.create(r) --- @@ -757,6 +760,7 @@ box.fiber.resume(f, 'hello') --- - true - hello +- null ... f=box.fiber.create(r) --- @@ -826,15 +830,15 @@ collectgarbage('collect') ... box.fiber.find(900) --- -{} +- null ... box.fiber.find(910) --- -{} +- null ... box.fiber.find(920) --- -{} +- null ... f = function() box.fiber.wrap(f) end --- @@ -860,7 +864,7 @@ result ... box.fiber.wrap(function() result = box.fiber.status() end) --- -{} +- null ... result --- @@ -1379,7 +1383,7 @@ box.space[0]:truncate() ffi --- -{} +- null ... # diff --git a/test/box/lua_misc.result b/test/box/lua_misc.result index a4cbf57030..9c5b84b88c 100644 --- a/test/box/lua_misc.result +++ b/test/box/lua_misc.result @@ -73,7 +73,7 @@ type(box.space); ... box.cfg.memcached_space; --- -{} +- null ... t = {}; --- diff --git a/test/box/net.box.result b/test/box/net.box.result index d0c9c6f104..9062bde9dd 100644 --- a/test/box/net.box.result +++ b/test/box/net.box.result @@ -126,7 +126,7 @@ remote:call('box.fiber.sleep', '.01') ... remote:timeout(0.01):call('box.fiber.sleep', '10') --- -{} +- null ... -- setopt delimiter ';' pstart = box.time(); diff --git a/third_party/lua-yaml/lyaml.c b/third_party/lua-yaml/lyaml.c index f9aab98f03..968591c972 100644 --- a/third_party/lua-yaml/lyaml.c +++ b/third_party/lua-yaml/lyaml.c @@ -443,9 +443,9 @@ static int dump_scalar(struct lua_yaml_dumper *dumper) { } else if (type == LUA_TLIGHTUSERDATA) { void *ptr = luaL_checkudata(dumper->L, -1, NULL); if (ptr == NULL) { - str = "null"; - len = 4; - style = YAML_PLAIN_SCALAR_STYLE; + str = "null"; + len = 4; + style = YAML_PLAIN_SCALAR_STYLE; } else { str = dump_tostring(dumper->L, -1); len = strlen(str); -- GitLab