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 E5D146EC55; Sat, 31 Jul 2021 01:13:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E5D146EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627683205; bh=zhHql+rRPQGLehufabPC+CzTK+vqG9giRpCIK8m3cR4=; 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=OsZ4XdaPuJbbp1D8J2UdD3ePmwdjsZnMXZ8Y662gEecktGObw9TLDWAxrXBvP6+Bz Vo6NFsehlY8h/TkH/k/dRrV/CzqiJLFVp9LyQIRVvY2NkflrZrg5HcPV9n6aWuUe1C zI+rQkIK4pIL+NUKICdm5JFj32iadNOhKmUjWJKE= Received: from smtpng3.i.mail.ru (smtpng3.i.mail.ru [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 726936EC55 for ; Sat, 31 Jul 2021 01:13:17 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 726936EC55 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1m9akm-0007Ov-9c; Sat, 31 Jul 2021 01:13:16 +0300 To: Vladimir Davydov , tarantool-patches@dev.tarantool.org References: Message-ID: Date: Sat, 31 Jul 2021 00:13:15 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C351B198F4576AC7B20CA14D9DFB46B94A182A05F53808504041A6B31D2A293C1BE97B33AE02E0A6D98F4897AB3B45BC35EE4BF83D719E34F7 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7CA8E915ACC910FBDEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378D08D652E28591A78638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8BDBB4DA3C8F9CE8A58370CE3AF18C13D117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B613439FA09F3DCB32089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B505C28EBB49D9AB9E42F6BA926626E7FFC2 X-C1DE0DAB: 0D63561A33F958A54FA186CB8D3F1DA41644114ECBE6ECAB8FD2511C3ABEE29CD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA751B940EDA0DFB0535410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D343D1F112031EF3D62717CDED59969BB3BBD2FB15D28593362459BF135AA7AFDC0C3BCE81AAF0493D91D7E09C32AA3244CB0573F49F974FCFA09D2AC4179F92173A8CE788DE6831205729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojWBddABnKmoLPNwrByRMAKA== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D36C717D23D7E684CD616DBA050A24D253841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH 12/20] net.box: rewrite error decoder in C 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 3 comments below. > diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c > index c0c3725e5350..e88db6323afa 100644 > --- a/src/box/lua/net_box.c > +++ b/src/box/lua/net_box.c > @@ -1082,6 +1084,63 @@ netbox_decode_method(struct lua_State *L) > +static int > +netbox_decode_error(struct lua_State *L) > +{ > + uint32_t ctypeid; > + const char **data = luaL_checkcdata(L, 1, &ctypeid); > + assert(ctypeid == CTID_CHAR_PTR || ctypeid == CTID_CONST_CHAR_PTR); > + uint32_t errcode = lua_tointeger(L, 2); > + struct error *error = NULL; > + assert(mp_typeof(**data) == MP_MAP); > + uint32_t map_size = mp_decode_map(data); > + for (uint32_t i = 0; i < map_size; ++i) { > + uint32_t key = mp_decode_uint(data); > + if (key == IPROTO_ERROR) { > + if (error != NULL) > + error_unref(error); > + error = error_unpack_unsafe(data); > + if (error == NULL) > + return luaT_error(L); > + error_ref(error); > + /* > + * IPROTO_ERROR comprises error encoded with > + * IPROTO_ERROR_24, so we may ignore content > + * of that key. > + */ > + break; > + } else if (key == IPROTO_ERROR_24) { > + if (error != NULL) > + error_unref(error); > + const char *reason = ""; > + uint32_t reason_len = 0; > + if (mp_typeof(**data) == MP_STR) > + reason = mp_decode_str(data, &reason_len); > + box_error_raise(errcode, "%.*s", reason_len, reason); > + error = box_error_last(); > + error_ref(error); > + continue; > + } > + mp_next(data); /* skip value */ 1. Could you please write comments on their own lines if possible? > diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua > index 9e41d6c0844b..d7394b088752 100644 > --- a/src/box/lua/net_box.lua > +++ b/src/box/lua/net_box.lua > @@ -73,14 +74,6 @@ local M_COUNT = 16 > -- Injects raw data into connection. Used by console and tests. > local M_INJECT = 17 > > -ffi.cdef[[ > -struct error * > -error_unpack_unsafe(const char **data); 2. You should be able to remove it from exports.h now. It is not used by FFI anymore. (error_unref() should stay in export.h - it is used by error Lua module.) > - > -void > -error_unref(struct error *e); > -]] > - > -- utility tables > local is_final_state = {closed = 1, error = 1} > > @@ -97,29 +90,6 @@ local function version_at_least(peer_version_id, major, minor, patch) > return peer_version_id >= version_id(major, minor, patch) > end > > -local function decode_error(raw_data) > - local ptr = ffi.new('const char *[1]', raw_data) > - local err = ffi.C.error_unpack_unsafe(ptr) > - if err ~= nil then > - err._refs = err._refs + 1 > - -- From FFI it is returned as 'struct error *', which is > - -- not considered equal to 'const struct error &', and is > - -- is not accepted by functions like box.error(). Need to > - -- cast explicitly. > - err = ffi.cast('const struct error &', err) > - err = ffi.gc(err, ffi.C.error_unref) > - else > - -- Error unpacker installs fail reason into diag. > - box.error() > - end > - return err, ptr[0] > -end > - > -local response_decoder = { > - [IPROTO_ERROR_24] = decode, > - [IPROTO_ERROR] = decode_error, 3. IPROTO_ERROR is now unused.