From a1ec38f3e0541742fc1c7a78f66df9bc10077beb Mon Sep 17 00:00:00 2001 From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> Date: Tue, 21 May 2019 19:59:56 +0300 Subject: [PATCH] swim: interpret no-payload as nil Empty string as a no-payload-flag was not a good idea, because then a user can't write something like: if not member:payload() then ... Follow up #3234 --- src/lua/swim.lua | 8 ++++++-- test/swim/swim.result | 14 +++++++------- test/swim/swim.test.lua | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/lua/swim.lua b/src/lua/swim.lua index dcb4968e24..d3d6b01e97 100644 --- a/src/lua/swim.lua +++ b/src/lua/swim.lua @@ -338,7 +338,11 @@ end -- local function swim_member_payload_str(m) local ptr = swim_check_member(m, 'member:payload_str()') - return ffi.string(swim_member_payload_raw(ptr)) + local cdata, size = swim_member_payload_raw(ptr) + if size > 0 then + return ffi.string(swim_member_payload_raw(ptr)) + end + return nil end -- @@ -367,7 +371,7 @@ local function swim_member_payload(m) local cdata, size = swim_member_payload_raw(ptr) local ok, result if size == 0 then - result = '' + result = nil else ok, result = pcall(msgpack.decode, cdata, size) if not ok then diff --git a/test/swim/swim.result b/test/swim/swim.result index 53a7cc6a40..dffacd999b 100644 --- a/test/swim/swim.result +++ b/test/swim/swim.result @@ -429,11 +429,11 @@ s:payload_cdata() ... s:payload_str() --- -- +- null ... s:payload() --- -- +- null ... s:is_dropped() --- @@ -536,7 +536,7 @@ s:set_payload() ... self:payload() --- -- +- null ... s:set_payload({a = 100}) --- @@ -603,7 +603,7 @@ s:set_payload() ... self:payload() --- -- +- null ... s:set_payload(100) --- @@ -619,7 +619,7 @@ s:set_payload_raw() ... self:payload() --- -- +- null ... -- Raw payload setting can be used when MessagePack is not needed, -- or already encoded. @@ -724,7 +724,7 @@ s1_view = s2:member_by_uuid(uuid(1)) ... s1_view:payload() --- -- +- null ... s1_view:incarnation() --- @@ -878,7 +878,7 @@ s1_self:payload() == p --- - true ... -while s1_view:payload() == '' do fiber.sleep(0.01) end +while not s1_view:payload() do fiber.sleep(0.01) end --- ... p = s1_view:payload() diff --git a/test/swim/swim.test.lua b/test/swim/swim.test.lua index b43160cc47..081d89b3a7 100644 --- a/test/swim/swim.test.lua +++ b/test/swim/swim.test.lua @@ -284,7 +284,7 @@ s1:set_payload({a = 100}) p = s1_self:payload() s1_self:payload() == p -while s1_view:payload() == '' do fiber.sleep(0.01) end +while not s1_view:payload() do fiber.sleep(0.01) end p = s1_view:payload() s1_view:payload() == p -- GitLab