From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 510733249C for ; Thu, 27 Jun 2019 19:24:59 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HUCR7E2EUJaK for ; Thu, 27 Jun 2019 19:24:59 -0400 (EDT) Received: from smtp46.i.mail.ru (smtp46.i.mail.ru [94.100.177.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 1144F322E7 for ; Thu, 27 Jun 2019 19:24:59 -0400 (EDT) From: Vladislav Shpilevoy Subject: [tarantool-patches] [PATCH 3/4] swim: fix inability to set generation only Date: Fri, 28 Jun 2019 01:25:45 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: kostja@tarantool.org swim.new() is declared as allowed to be called before swim:cfg(). But in fact swim.new({generation = ...}) didn't work because after generation extraction the empty config {} was passed to swim:cfg() and led to an error. The patch allows to call swim.new() with generation only, as well as without parameters at all. Follow up #4280 --- src/lua/swim.lua | 5 +++++ test/swim/swim.result | 6 ++++++ test/swim/swim.test.lua | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/src/lua/swim.lua b/src/lua/swim.lua index 686c376cc..69d077c37 100644 --- a/src/lua/swim.lua +++ b/src/lua/swim.lua @@ -980,6 +980,11 @@ local function swim_new(cfg) -- Nullify in order to do not raise errors in the -- following swim:cfg() about unknown parameters. cfg.generation = nil + -- When only 'generation' is specified, empty config will + -- raise an error at swim:cfg(). It should not. + if next(cfg) == nil then + cfg = nil + end end local ptr = internal.swim_new(generation) if ptr == nil then diff --git a/test/swim/swim.result b/test/swim/swim.result index 318b4bed9..26f74f9f4 100644 --- a/test/swim/swim.result +++ b/test/swim/swim.result @@ -1574,6 +1574,12 @@ s1:delete() s2:delete() --- ... +-- It is allowed to create a SWIM with a generation value, but do +-- not configure it. +swim.new({generation = 0}) +--- +- [] +... -- -- Check that Lua triggers don't keep a reference of SWIM instance -- preventing its GC. diff --git a/test/swim/swim.test.lua b/test/swim/swim.test.lua index 16b77b602..496beced5 100644 --- a/test/swim/swim.test.lua +++ b/test/swim/swim.test.lua @@ -535,6 +535,10 @@ s1:cfg({generation = 5}) s1:delete() s2:delete() +-- It is allowed to create a SWIM with a generation value, but do +-- not configure it. +swim.new({generation = 0}) + -- -- Check that Lua triggers don't keep a reference of SWIM instance -- preventing its GC. -- 2.20.1 (Apple Git-117)