From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id CF7D3480007; Fri, 6 Oct 2023 16:51:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CF7D3480007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1696600292; bh=jWt71NNX34T+P6ktiAyMlIpxjyeueZDwRU0fykLgKQs=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=fFU3EPqm6kRXTbbxtYznvrAoSYgNKVw/Doamwl4E2A1QwqstsL+MOnvcI5Bs15S2s /b+DWOzAp6PComvDIFjcHF9D0fUaZaCnj61YBafleE1O20+N7wnwWrQhLltW7LkwfG d/aERILLgACm23rMNF25hz0YasIQTKaE41xhmyZo= Received: from smtp58.i.mail.ru (smtp58.i.mail.ru [95.163.41.96]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 2B73A480007 for ; Fri, 6 Oct 2023 16:51:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2B73A480007 Received: by smtp58.i.mail.ru with esmtpa (envelope-from ) id 1qolEn-00FGIQ-2S; Fri, 06 Oct 2023 16:51:30 +0300 Message-ID: <921a2fdc-956b-4879-8637-ccb6b4286d9c@tarantool.org> Date: Fri, 6 Oct 2023 16:51:29 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Maxim Kokryashkin Cc: Sergey Bronnikov , max.kokryashkin@gmail.com, tarantool-patches@dev.tarantool.org References: <26636e3dcb8ade3bdc23d9544f9a7e2ffe4322b2.1695711374.git.sergeyb@tarantool.org> <2e683729-401b-1b86-5a60-54a2cd39dc84@tarantool.org> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9FE0487E502468146EC9FB4099193202C3CCBF29BAB5B817F00894C459B0CD1B90C1D738113424F0351451DCF6C03BE2FD621CBAEF966F107D1FFACA8F48D2A96 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7D77100FFB2844417EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637BC6099E116BE74F18638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D847D0CBA81FA7A04BCC15E0DF70BB8B77117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC292D688DDAD4E7BC389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC878444BBB7636F62AF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C5E3BF8C76DC23F74C0837EA9F3D197644AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C31B9641C7FFD9FDBABA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE7EDFA0E72C3EE0C08731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A55C3C2A19E417E1144A97E0F6019E5886B53BF95D14A621FAF87CCE6106E1FC07E67D4AC08A07B9B0AD0E433DBF1FBFA3CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFCFA8AD02BFF071ECC3538B8E64F0135B97E5B3F3C5B13FC5A2679B847E9E14529AB7DC20417E211573F688399A8929A2F38233466C57E37BD862F8A5763F4F3CA74DFFEFA5DC0E7F02C26D483E81D6BE0DBAE6F56676BC7117BB6831D7356A2DEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj0Piy1iZpfs5BOexOjBbBtA== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A769F0C6E566259827CC4719EA2EA61CEE61E5E949923882BAADEBA65886582A37BD66FEC6BF5C9C28D98A98C1125256619760D574B6FC815AB872D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] LJ_GC64: Fix lua_concat(). X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Max On 10/4/23 13:48, Maxim Kokryashkin wrote: > Hi, Sergey! > Thanks for the fixes! > LGTM, except for the single comment below. > > > + Info info; >>>> + info.value = 7; > I am really sorry, that I didn't noticed that in the first round, > but the test case can be reduced a bit more. We don't really need > the `Info` structure and can use some basic type like `int`, for > example. One might argue that such change can reduce the readability > a bit, so I leave the final decision up to you. > > > Thanks for suggestion, it has reduced test a bit. Below is a patch where struct was replaced with int (changes force-pushed and I'll send v2 as you requested): diff --git a/test/tarantool-c-tests/lj-881-fix-lua-concat.test.c b/test/tarantool-c-tests/lj-881-fix-lua-concat.test.c index 83925445..1b1f146f 100644 --- a/test/tarantool-c-tests/lj-881-fix-lua-concat.test.c +++ b/test/tarantool-c-tests/lj-881-fix-lua-concat.test.c @@ -12,31 +12,18 @@   * See https://github.com/LuaJIT/LuaJIT/issues/881 for details.   */ -#define TYPE_NAME_INFO "Info" - -typedef struct Info -{ -    int payload; -} Info; - -static void lua_pushinfo(lua_State *L, Info *info) -{ -    Info *infop = (Info *)lua_newuserdata(L, sizeof(Info)); -    *infop = *info; - -    luaL_getmetatable(L, TYPE_NAME_INFO); -    lua_setmetatable(L, -2); -} +#define MT_NAME "int"  static int INFO_concat(lua_State *L)  {      const char *s = luaL_checkstring(L, 1); -    Info *info = (Info*)luaL_checkudata(L, 2, TYPE_NAME_INFO); -    lua_pushfstring(L, "%s[%s.payload=%d]", s, TYPE_NAME_INFO, info->payload); +    int *n = (int *)luaL_checkudata(L, 2, MT_NAME); +    /* Do non-default concatenation. */ +    lua_pushfstring(L, "%s + %d", s, *n);      return 1;  } -static const luaL_Reg INFO_meta[] = +static const luaL_Reg mt[] =  {      {"__concat",    INFO_concat},      {NULL, NULL} @@ -46,17 +33,12 @@ static int lua_concat_testcase(void *test_state)  {      /* Setup. */      lua_State *L = test_state; -    Info info = { -        .payload = 7 -    };      const int top = 4; -    const int n = 2; - -    /* Create metatable and add it to the Lua registry. */ -    luaL_newmetatable(L, TYPE_NAME_INFO); +    /* Create metatable and put it to the Lua registry. */ +    luaL_newmetatable(L, MT_NAME);      /* Fill metatable. */ -    luaL_register(L, 0, INFO_meta); +    luaL_register(L, 0, mt);      lua_pop(L, 1);      assert_int_equal(lua_gettop(L), 0); @@ -64,13 +46,18 @@ static int lua_concat_testcase(void *test_state)      lua_pushliteral(L, "C");      lua_pushliteral(L, "B");      lua_pushliteral(L, "A"); -    lua_pushinfo(L, &info); -    assert_true(lua_gettop(L) == top); +    int *n = (int *)lua_newuserdata(L, sizeof(int)); +    *n = 100; + +    luaL_getmetatable(L, MT_NAME); +    lua_setmetatable(L, -2); + +    assert_int_equal(lua_gettop(L), top);      /* Test body. */ -    /** +    /*       * void lua_concat (lua_State *L, int n);       *       * Concatenates the n values at the top of the stack, @@ -80,11 +67,13 @@ static int lua_concat_testcase(void *test_state)       *       * 1. https://www.lua.org/manual/5.1/manual.html       */ -    lua_concat(L, n); + +    /* Concatenate two elements on top. */ +    lua_concat(L, 2);      const char *str = lua_tostring(L, -1); -    assert_true(top - n + 1 == lua_gettop(L)); -    const char expected_str[] = "A[Info.payload=7]"; +    assert_int_equal(lua_gettop(L), top - 2 + 1); +    const char expected_str[] = "A + 100";      assert_str_equal(str, expected_str, strlen(expected_str));      /* Teardown. */