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 A36CC6EC5E; Sun, 11 Apr 2021 18:43:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A36CC6EC5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618155785; bh=rlaHZKaZrCEfuLjiKrmbysxZCYWw/lTRydaAjGKNB1E=; h=To:References:Date:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=BaAYPv3Nf57tBNlbB82mhjIigkMftapuHro9A7z3KIBX/z9JV8kP1io045jbUk9wB JfNrF6Xj+qiv3L14XC6RePuNNAuCejdOFtxoUSGHsKbWj5A3FEfJfB9sMgg5DBLLK3 +UKUDX2RT83U4FXVXi4mNDzHBR8sZvCrmijAqtCo= Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 17F1F6EC5E for ; Sun, 11 Apr 2021 18:43:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 17F1F6EC5E Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lVcEp-0003TA-By; Sun, 11 Apr 2021 18:43:04 +0300 To: Cyrill Gorcunov , tml References: <20210408164151.1759348-1-gorcunov@gmail.com> <20210408164151.1759348-7-gorcunov@gmail.com> Message-ID: Date: Sun, 11 Apr 2021 17:43:02 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E7480EBD5CA77A668ECB87DA2124B0A8E6609182A05F538085040949F0F3D14CB1A2BB378F481B85228D0464DAB0DC206D943B96B657911F727CA X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7CB9C0C663C74145DEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637B6B039AA0E19584A8638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2EB1AA61C9DE7B13F3CBFF4E3D8CFEAC2A033A18F845E317FD2E47CDBA5A96583C09775C1D3CA48CFCA5A41EBD8A3A0199FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3CA5A41EBD8A3A0199FA2833FD35BB23DF004C906525384302BEBFE083D3B9BA73A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735463FC242DBD691A6C4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A5FDD37FE8C73E430BBF29CFB9BB9A43EDD36CD035E2DBCA1FD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C53592357E805773C2537BC155F7A298991D9CDF33F8CB0AD813ABBD1A3CB607D894D616A41B1A991D7E09C32AA3244C5AD525AB67CE6E53CF4CD0CAA96D760ED08D48398F32B4A6927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojyKKJYJ15DtLf+IhIQg03zg== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822D20F847B491F69E237A91164CBCF86B23841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v21 6/6] test: add box.lib test 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: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for the patch! See below 4 comments, my diff in the end of the email, and on the branch in a separate commit. > diff --git a/test/box/lib.result b/test/box/lib.result > new file mode 100644 > index 000000000..2986df049 > --- /dev/null > +++ b/test/box/lib.result > @@ -0,0 +1,527 @@ <...> > + > +-- Cleanup new module data. > +new_cfunc_nop:unload() > + | --- > + | - true > + | ... > +new_cfunc_multireturn:unload() > + | --- > + | - true > + | ... > +new_cfunc_fetch_seq_evens:unload() > + | --- > + | - true > + | ... > +new_cfunc_args:unload() > + | --- > + | - true > + | ... > +new_cfunc_sum:unload() > + | --- > + | - true > + | ... > +new_module:unload() > + | --- > + | - true > + | ... > + > +-- Cleanup the generated symlink. > +_ = pcall(fio.unlink(cfunc_path)) > + | --- > + | ... > + > +-- Test double hashing: create function > +-- in box.schema.fun so that it should > +-- appear in box.lib hash. > +fio.symlink(cfunc3_path, cfunc_path) > + | --- > + | - true > + | ... > +box.schema.func.create('cfunc.cfunc_add', {language = "C"}) > + | --- > + | ... > +box.schema.user.grant('guest', 'execute', 'function', 'cfunc.cfunc_add') > + | --- > + | ... > +box.func['cfunc.cfunc_add']:call({1,2}) > + | --- > + | - 3 > + | ... > + > +old_module = box.lib.load('cfunc') > + | --- > + | ... > +assert(old_module['debug_refs'] == 3) -- box.lib + 2 box.schema.func 1. Why +2? There is only one function loaded from that module in box.schema.func. > + | --- > + | - true > + | ... > +old_func = old_module:load('cfunc_add') > + | --- > + | ... > +assert(old_module['debug_refs'] == 4) -- plus function instance > + | --- > + | - true > + | ... > +old_func(1,2) > + | --- > + | - 3 > + | ... > + > +-- Now update on disk and reload the module. > +_ = pcall(fio.unlink(cfunc_path)) > + | --- > + | ... > +fio.symlink(cfunc4_path, cfunc_path) > + | --- > + | - true > + | ... > + > +box.schema.func.reload("cfunc") > + | --- > + | ... > +box.func['cfunc.cfunc_add']:call({1,2}) > + | --- > + | - 13 > + | ... > + > +-- The box.lib instance should carry own > +-- references to the module and old > +-- function. And reloading must not > +-- affect old functions. Thus one for > +-- box.lib and one for box.lib function. 2. What do you mean "one for box.lib"? > +assert(old_module['debug_refs'] == 2) > + | --- > + | - true > + | ... > +old_func(1,2) > + | --- > + | - 3 > + | ... > +old_func:unload() > + | --- > + | - true > + | ... > +old_module:unload() > + | --- > + | - true > + | ... > + > +-- Same time the reload should update > +-- low level module cache, thus two > +-- for box and box function plus one 3. The same question. What is "for box"? What exactly keeps these references? > +-- new box.lib. > +new_module = box.lib.load('cfunc') > + | --- > + | ... > +assert(new_module['debug_refs'] == 3) > + | --- > + | - true > + | ... > + 4. In the previous review I asked you to add tests for automatic unload via GC. Please, add them. You can use collectgarbage('collect') functions, and setmetatable(..., {__mode = 'v'}) if it will help with anything. See below my review fixes and on the branch in a separate commit. ==================== diff --git a/test/box/cfunc1.c b/test/box/cfunc1.c index f6829372a..2ab0e8d78 100644 --- a/test/box/cfunc1.c +++ b/test/box/cfunc1.c @@ -1,7 +1,3 @@ -#include -#include -#include - #include "module.h" /* @@ -15,44 +11,17 @@ int cfunc_nop(box_function_ctx_t *ctx, const char *args, const char *args_end) { - (void)ctx; - (void)args; - (void)args_end; - return 0; -} - -int -cfunc_fetch_seq_evens(box_function_ctx_t *ctx, const char *args, const char *args_end) -{ - (void)ctx; - (void)args; - (void)args_end; - return 0; -} - -int -cfunc_multireturn(box_function_ctx_t *ctx, const char *args, const char *args_end) -{ - (void)ctx; - (void)args; - (void)args_end; return 0; } int -cfunc_args(box_function_ctx_t *ctx, const char *args, const char *args_end) +cfunc_echo(box_function_ctx_t *ctx, const char *args, const char *args_end) { - (void)ctx; - (void)args; - (void)args_end; return 0; } int cfunc_sum(box_function_ctx_t *ctx, const char *args, const char *args_end) { - (void)ctx; - (void)args; - (void)args_end; return 0; } diff --git a/test/box/cfunc2.c b/test/box/cfunc2.c index 8c583e993..6de40b866 100644 --- a/test/box/cfunc2.c +++ b/test/box/cfunc2.c @@ -1,7 +1,6 @@ -#include -#include -#include ==================== As I said earlier, for non-system headers we use "", not <>. ==================== +#include +#include "msgpuck.h" #include "module.h" /* @@ -10,9 +9,6 @@ int cfunc_nop(box_function_ctx_t *ctx, const char *args, const char *args_end) { - (void)ctx; - (void)args; - (void)args_end; return 0; } @@ -21,99 +17,22 @@ cfunc_nop(box_function_ctx_t *ctx, const char *args, const char *args_end) * arguments is not screwed). */ int -cfunc_fetch_seq_evens(box_function_ctx_t *ctx, const char *args, const char *args_end) -{ ==================== After more thinkning I still couldn't find a reason why this function has to be so complex. Why not solve an integral equation then? Or calculcate Fibonachi numbers? For your purpose a simple 'echo' function would solve both the arguments sanity check, and the miltireturn check. ==================== - int arg_count = mp_decode_array(&args); - if (arg_count != 1) { - return box_error_set(__FILE__, __LINE__, ER_PROC_C, "%s", - "invalid argument count"); - } - int field_count = mp_decode_array(&args); - if (field_count < 1) { - return box_error_set(__FILE__, __LINE__, ER_PROC_C, "%s", - "invalid array size"); - } - - /* - * We expect even numbers sequence here. The idea is - * to test invalid data an issue an error from inside - * of C function. - */ - for (int i = 1; i <= field_count; i++) { - int val = mp_decode_uint(&args); - int needed = 2 * i; - if (val != needed) { - char res[128]; - snprintf(res, sizeof(res), "%s %d != %d", - "invalid argument", val, needed); - return box_error_set(__FILE__, __LINE__, - ER_PROC_C, "%s", res); - } - } - - return 0; -} - -/* - * Return one element array twice. - */ -int -cfunc_multireturn(box_function_ctx_t *ctx, const char *args, const char *args_end) -{ - char tuple_buf[512]; - char *d = tuple_buf; - d = mp_encode_array(d, 1); - d = mp_encode_uint(d, 1); - assert(d <= tuple_buf + sizeof(tuple_buf)); - - box_tuple_format_t *fmt = box_tuple_format_default(); - box_tuple_t *tuple_a = box_tuple_new(fmt, tuple_buf, d); - if (tuple_a == NULL) - return -1; - int rc = box_return_tuple(ctx, tuple_a); - if (rc == 0) - return box_return_tuple(ctx, tuple_a); - return rc; -} - -/* - * Encode int + string pair back. - */ -int -cfunc_args(box_function_ctx_t *ctx, const char *args, const char *args_end) +cfunc_echo(box_function_ctx_t *ctx, const char *args, const char *args_end) { + const char *pos = args; + if (mp_check(&pos, args_end) != 0) + abort(); + if (mp_typeof(*args) != MP_ARRAY) + abort(); uint32_t arg_count = mp_decode_array(&args); - if (arg_count != 2) { - return box_error_set(__FILE__, __LINE__, ER_PROC_C, "%s", - "invalid argument count"); + for (uint32_t i = 0; i < arg_count; ++i) { + pos = args; + mp_next(&pos); + if (box_return_mp(ctx, args, pos) != 0) + return -1; + args = pos; } - - if (mp_typeof(*args) != MP_UINT) { - return box_error_set(__FILE__, __LINE__, ER_PROC_C, "%s", - "tuple field must be uint"); - } - uint32_t num = mp_decode_uint(&args); - - if (mp_typeof(*args) != MP_STR) { - return box_error_set(__FILE__, __LINE__, ER_PROC_C, "%s", - "tuple field must be string"); - } - const char *str = args; - uint32_t len = mp_decode_strl(&str); - - char tuple_buf[512]; - char *d = tuple_buf; - d = mp_encode_array(d, 2); - d = mp_encode_uint(d, num); - d = mp_encode_str(d, str, len); - assert(d <= tuple_buf + sizeof(tuple_buf)); - - box_tuple_format_t *fmt = box_tuple_format_default(); - box_tuple_t *tuple = box_tuple_new(fmt, tuple_buf, d); - if (tuple == NULL) - return -1; - - return box_return_tuple(ctx, tuple); + return 0; } /* diff --git a/test/box/cfunc3.c b/test/box/cfunc3.c index 668790fbf..71fe2717a 100644 --- a/test/box/cfunc3.c +++ b/test/box/cfunc3.c @@ -1,7 +1,4 @@ -#include -#include -#include - +#include "msgpuck.h" #include "module.h" /* diff --git a/test/box/cfunc4.c b/test/box/cfunc4.c index cc079b335..a03a23026 100644 --- a/test/box/cfunc4.c +++ b/test/box/cfunc4.c @@ -1,7 +1,4 @@ -#include -#include #include - #include "module.h" /* diff --git a/test/box/lib.result b/test/box/lib.result index 2986df049..58acb9c06 100644 --- a/test/box/lib.result +++ b/test/box/lib.result @@ -82,19 +82,13 @@ assert(old_module['debug_refs'] == 1) old_cfunc_nop = old_module:load('cfunc_nop') | --- | ... -old_cfunc_fetch_seq_evens = old_module:load('cfunc_fetch_seq_evens') - | --- - | ... -old_cfunc_multireturn = old_module:load('cfunc_multireturn') - | --- - | ... -old_cfunc_args = old_module:load('cfunc_args') +old_cfunc_echo = old_module:load('cfunc_echo') | --- | ... old_cfunc_sum = old_module:load('cfunc_sum') | --- | ... -assert(old_module['debug_refs'] == 6) +assert(old_module['debug_refs'] == 4) | --- | - true | ... @@ -112,13 +106,7 @@ assert(err ~= nil) old_cfunc_nop() | --- | ... -old_cfunc_fetch_seq_evens() - | --- - | ... -old_cfunc_multireturn() - | --- - | ... -old_cfunc_args() +old_cfunc_echo() | --- | ... old_cfunc_sum() @@ -133,20 +121,14 @@ old_module:unload() | - true | ... -- Test refs via function name. -assert(old_cfunc_nop['debug_module_refs'] == 5) +assert(old_cfunc_nop['debug_module_refs'] == 3) | --- | - true | ... old_cfunc_nop() | --- | ... -old_cfunc_fetch_seq_evens() - | --- - | ... -old_cfunc_multireturn() - | --- - | ... -old_cfunc_args() +old_cfunc_echo() | --- | ... old_cfunc_sum() @@ -170,15 +152,7 @@ old_cfunc_nop:unload() | --- | - true | ... -old_cfunc_fetch_seq_evens:unload() - | --- - | - true - | ... -old_cfunc_multireturn:unload() - | --- - | - true - | ... -old_cfunc_args:unload() +old_cfunc_echo:unload() | --- | - true | ... @@ -239,13 +213,7 @@ assert(old_module_ptr ~= new_module_ptr) old_cfunc_nop = old_module:load('cfunc_nop') | --- | ... -old_cfunc_fetch_seq_evens = old_module:load('cfunc_fetch_seq_evens') - | --- - | ... -old_cfunc_multireturn = old_module:load('cfunc_multireturn') - | --- - | ... -old_cfunc_args = old_module:load('cfunc_args') +old_cfunc_echo = old_module:load('cfunc_echo') | --- | ... old_cfunc_sum = old_module:load('cfunc_sum') @@ -255,15 +223,7 @@ assert(old_cfunc_nop['debug_module_ptr'] == old_module_ptr) | --- | - true | ... -assert(old_cfunc_fetch_seq_evens['debug_module_ptr'] == old_module_ptr) - | --- - | - true - | ... -assert(old_cfunc_multireturn['debug_module_ptr'] == old_module_ptr) - | --- - | - true - | ... -assert(old_cfunc_args['debug_module_ptr'] == old_module_ptr) +assert(old_cfunc_echo['debug_module_ptr'] == old_module_ptr) | --- | - true | ... @@ -271,7 +231,7 @@ assert(old_cfunc_sum['debug_module_ptr'] == old_module_ptr) | --- | - true | ... -assert(old_module['debug_refs'] == 6) +assert(old_module['debug_refs'] == 4) | --- | - true | ... @@ -280,13 +240,7 @@ assert(old_module['debug_refs'] == 6) new_cfunc_nop = new_module:load('cfunc_nop') | --- | ... -new_cfunc_fetch_seq_evens = new_module:load('cfunc_fetch_seq_evens') - | --- - | ... -new_cfunc_multireturn = new_module:load('cfunc_multireturn') - | --- - | ... -new_cfunc_args = new_module:load('cfunc_args') +new_cfunc_echo = new_module:load('cfunc_echo') | --- | ... new_cfunc_sum = new_module:load('cfunc_sum') @@ -296,15 +250,7 @@ assert(new_cfunc_nop['debug_module_ptr'] == new_module_ptr) | --- | - true | ... -assert(new_cfunc_fetch_seq_evens['debug_module_ptr'] == new_module_ptr) - | --- - | - true - | ... -assert(new_cfunc_multireturn['debug_module_ptr'] == new_module_ptr) - | --- - | - true - | ... -assert(new_cfunc_args['debug_module_ptr'] == new_module_ptr) +assert(new_cfunc_echo['debug_module_ptr'] == new_module_ptr) | --- | - true | ... @@ -312,7 +258,7 @@ assert(new_cfunc_sum['debug_module_ptr'] == new_module_ptr) | --- | - true | ... -assert(new_module['debug_refs'] == 6) +assert(new_module['debug_refs'] == 4) | --- | - true | ... @@ -321,13 +267,7 @@ assert(new_module['debug_refs'] == 6) old_cfunc_nop() | --- | ... -old_cfunc_fetch_seq_evens() - | --- - | ... -old_cfunc_multireturn() - | --- - | ... -old_cfunc_args() +old_cfunc_echo() | --- | ... old_cfunc_sum() @@ -338,27 +278,21 @@ old_cfunc_sum() new_cfunc_nop() | --- | ... -new_cfunc_multireturn() +new_cfunc_echo({1, 2, 3}) | --- - | - [1] - | - [1] + | - [1, 2, 3] | ... -new_cfunc_fetch_seq_evens({2,4,6}) +new_cfunc_echo(1, 2, 3) | --- - | ... -new_cfunc_fetch_seq_evens({1,2,3}) -- error, odd numbers sequence - | --- - | - error: invalid argument 1 != 2 - | ... -new_cfunc_args(1, "hello") - | --- - | - [1, 'hello'] + | - 1 + | - 2 + | - 3 | ... new_cfunc_sum(1) -- error, one arg passed | --- | - error: invalid argument count | ... -new_cfunc_sum(1,2) +new_cfunc_sum(1, 2) | --- | - 3 | ... @@ -368,15 +302,7 @@ old_cfunc_nop:unload() | --- | - true | ... -old_cfunc_fetch_seq_evens:unload() - | --- - | - true - | ... -old_cfunc_multireturn:unload() - | --- - | - true - | ... -old_cfunc_args:unload() +old_cfunc_echo:unload() | --- | - true | ... @@ -394,15 +320,7 @@ new_cfunc_nop:unload() | --- | - true | ... -new_cfunc_multireturn:unload() - | --- - | - true - | ... -new_cfunc_fetch_seq_evens:unload() - | --- - | - true - | ... -new_cfunc_args:unload() +new_cfunc_echo:unload() | --- | - true | ... @@ -433,7 +351,7 @@ box.schema.func.create('cfunc.cfunc_add', {language = "C"}) box.schema.user.grant('guest', 'execute', 'function', 'cfunc.cfunc_add') | --- | ... -box.func['cfunc.cfunc_add']:call({1,2}) +box.func['cfunc.cfunc_add']:call({1, 2}) | --- | - 3 | ... @@ -452,7 +370,7 @@ assert(old_module['debug_refs'] == 4) -- plus function instance | --- | - true | ... -old_func(1,2) +old_func(1, 2) | --- | - 3 | ... @@ -469,7 +387,7 @@ fio.symlink(cfunc4_path, cfunc_path) box.schema.func.reload("cfunc") | --- | ... -box.func['cfunc.cfunc_add']:call({1,2}) +box.func['cfunc.cfunc_add']:call({1, 2}) | --- | - 13 | ... @@ -483,7 +401,7 @@ assert(old_module['debug_refs'] == 2) | --- | - true | ... -old_func(1,2) +old_func(1, 2) | --- | - 3 | ... @@ -509,7 +427,7 @@ assert(new_module['debug_refs'] == 3) | ... -- Box function should carry own module. -box.func['cfunc.cfunc_add']:call({1,2}) +box.func['cfunc.cfunc_add']:call({1, 2}) | --- | - 13 | ... diff --git a/test/box/lib.test.lua b/test/box/lib.test.lua index 387c813c4..e0e4b9e4d 100644 --- a/test/box/lib.test.lua +++ b/test/box/lib.test.lua @@ -32,11 +32,9 @@ assert(old_module_copy['debug_refs'] == 2) old_module_copy:unload() assert(old_module['debug_refs'] == 1) old_cfunc_nop = old_module:load('cfunc_nop') -old_cfunc_fetch_seq_evens = old_module:load('cfunc_fetch_seq_evens') -old_cfunc_multireturn = old_module:load('cfunc_multireturn') -old_cfunc_args = old_module:load('cfunc_args') +old_cfunc_echo = old_module:load('cfunc_echo') old_cfunc_sum = old_module:load('cfunc_sum') -assert(old_module['debug_refs'] == 6) +assert(old_module['debug_refs'] == 4) -- Test for error on nonexisting function. _, err = pcall(old_module.load, old_module, 'no-such-func') @@ -44,9 +42,7 @@ assert(err ~= nil) -- Make sure they all are callable. old_cfunc_nop() -old_cfunc_fetch_seq_evens() -old_cfunc_multireturn() -old_cfunc_args() +old_cfunc_echo() old_cfunc_sum() -- Unload the module but keep old functions alive, so @@ -54,11 +50,9 @@ old_cfunc_sum() -- and still callable. old_module:unload() -- Test refs via function name. -assert(old_cfunc_nop['debug_module_refs'] == 5) +assert(old_cfunc_nop['debug_module_refs'] == 3) old_cfunc_nop() -old_cfunc_fetch_seq_evens() -old_cfunc_multireturn() -old_cfunc_args() +old_cfunc_echo() old_cfunc_sum() -- The module is unloaded I should not be able @@ -69,9 +63,7 @@ old_module:unload() -- Clean old functions. old_cfunc_nop:unload() -old_cfunc_fetch_seq_evens:unload() -old_cfunc_multireturn:unload() -old_cfunc_args:unload() +old_cfunc_echo:unload() assert(old_cfunc_sum['debug_module_refs'] == 1) old_cfunc_sum:unload() @@ -96,59 +88,43 @@ assert(old_module_ptr ~= new_module_ptr) -- All functions from old module should be loadable. old_cfunc_nop = old_module:load('cfunc_nop') -old_cfunc_fetch_seq_evens = old_module:load('cfunc_fetch_seq_evens') -old_cfunc_multireturn = old_module:load('cfunc_multireturn') -old_cfunc_args = old_module:load('cfunc_args') +old_cfunc_echo = old_module:load('cfunc_echo') old_cfunc_sum = old_module:load('cfunc_sum') assert(old_cfunc_nop['debug_module_ptr'] == old_module_ptr) -assert(old_cfunc_fetch_seq_evens['debug_module_ptr'] == old_module_ptr) -assert(old_cfunc_multireturn['debug_module_ptr'] == old_module_ptr) -assert(old_cfunc_args['debug_module_ptr'] == old_module_ptr) +assert(old_cfunc_echo['debug_module_ptr'] == old_module_ptr) assert(old_cfunc_sum['debug_module_ptr'] == old_module_ptr) -assert(old_module['debug_refs'] == 6) +assert(old_module['debug_refs'] == 4) -- Lookup for updated symbols. new_cfunc_nop = new_module:load('cfunc_nop') -new_cfunc_fetch_seq_evens = new_module:load('cfunc_fetch_seq_evens') -new_cfunc_multireturn = new_module:load('cfunc_multireturn') -new_cfunc_args = new_module:load('cfunc_args') +new_cfunc_echo = new_module:load('cfunc_echo') new_cfunc_sum = new_module:load('cfunc_sum') assert(new_cfunc_nop['debug_module_ptr'] == new_module_ptr) -assert(new_cfunc_fetch_seq_evens['debug_module_ptr'] == new_module_ptr) -assert(new_cfunc_multireturn['debug_module_ptr'] == new_module_ptr) -assert(new_cfunc_args['debug_module_ptr'] == new_module_ptr) +assert(new_cfunc_echo['debug_module_ptr'] == new_module_ptr) assert(new_cfunc_sum['debug_module_ptr'] == new_module_ptr) -assert(new_module['debug_refs'] == 6) +assert(new_module['debug_refs'] == 4) -- Call old functions. old_cfunc_nop() -old_cfunc_fetch_seq_evens() -old_cfunc_multireturn() -old_cfunc_args() +old_cfunc_echo() old_cfunc_sum() -- Call new functions. new_cfunc_nop() -new_cfunc_multireturn() -new_cfunc_fetch_seq_evens({2,4,6}) -new_cfunc_fetch_seq_evens({1,2,3}) -- error, odd numbers sequence -new_cfunc_args(1, "hello") +new_cfunc_echo({1, 2, 3}) +new_cfunc_echo(1, 2, 3) new_cfunc_sum(1) -- error, one arg passed -new_cfunc_sum(1,2) +new_cfunc_sum(1, 2) -- Cleanup old module's functions. old_cfunc_nop:unload() -old_cfunc_fetch_seq_evens:unload() -old_cfunc_multireturn:unload() -old_cfunc_args:unload() +old_cfunc_echo:unload() old_cfunc_sum:unload() old_module:unload() -- Cleanup new module data. new_cfunc_nop:unload() -new_cfunc_multireturn:unload() -new_cfunc_fetch_seq_evens:unload() -new_cfunc_args:unload() +new_cfunc_echo:unload() new_cfunc_sum:unload() new_module:unload() @@ -161,20 +137,20 @@ _ = pcall(fio.unlink(cfunc_path)) fio.symlink(cfunc3_path, cfunc_path) box.schema.func.create('cfunc.cfunc_add', {language = "C"}) box.schema.user.grant('guest', 'execute', 'function', 'cfunc.cfunc_add') -box.func['cfunc.cfunc_add']:call({1,2}) +box.func['cfunc.cfunc_add']:call({1, 2}) old_module = box.lib.load('cfunc') assert(old_module['debug_refs'] == 3) -- box.lib + 2 box.schema.func old_func = old_module:load('cfunc_add') assert(old_module['debug_refs'] == 4) -- plus function instance -old_func(1,2) +old_func(1, 2) -- Now update on disk and reload the module. _ = pcall(fio.unlink(cfunc_path)) fio.symlink(cfunc4_path, cfunc_path) box.schema.func.reload("cfunc") -box.func['cfunc.cfunc_add']:call({1,2}) +box.func['cfunc.cfunc_add']:call({1, 2}) -- The box.lib instance should carry own -- references to the module and old @@ -182,7 +158,7 @@ box.func['cfunc.cfunc_add']:call({1,2}) -- affect old functions. Thus one for -- box.lib and one for box.lib function. assert(old_module['debug_refs'] == 2) -old_func(1,2) +old_func(1, 2) old_func:unload() old_module:unload() @@ -194,7 +170,7 @@ new_module = box.lib.load('cfunc') assert(new_module['debug_refs'] == 3) -- Box function should carry own module. -box.func['cfunc.cfunc_add']:call({1,2}) +box.func['cfunc.cfunc_add']:call({1, 2}) -- Cleanup. _ = pcall(fio.unlink(cfunc_path))