From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp14.mail.ru (smtp14.mail.ru [94.100.181.95]) (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 86808469710 for ; Tue, 19 May 2020 23:48:30 +0300 (MSK) References: <22a830fb9d2dbc3883b9710d36ab88c638101002.1589240704.git.v.shpilevoy@tarantool.org> <20200519115151.yzemh35jqmsxaj54@tkn_work_nb> From: Vladislav Shpilevoy Message-ID: <143c9744-de57-2b69-55df-49fd14378f1b@tarantool.org> Date: Tue, 19 May 2020 22:48:28 +0200 MIME-Version: 1.0 In-Reply-To: <20200519115151.yzemh35jqmsxaj54@tkn_work_nb> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [Tarantool-patches] [PATCH 4/5] error: provide MP_ERROR extension serializer List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Turenko Cc: tarantool-patches@dev.tarantool.org Thanks for the review! On 19/05/2020 13:51, Alexander Turenko wrote: >> + const char *field_to_key[MP_ERROR_MAX] = { >> + /* MP_ERROR_TYPE = */ "\"type\": ", >> + /* MP_ERROR_FILE = */ "\"file\": ", >> + /* MP_ERROR_LINE = */ "\"line\": ", >> + /* MP_ERROR_MESSAGE = */ "\"message\": ", >> + /* MP_ERROR_ERRNO = */ "\"errno\": ", >> + /* MP_ERROR_CODE = */ "\"code\": ", >> + /* MP_ERROR_FIELDS = */ "\"fields\": ", >> + }; > > Should be static? I can do it static, but only outside of the function and the of the whole template then. Otherwise we will have 2 copies of this array, because mp_print_error_one() is turned into 2 functions: mp_sprint_error_one() and mp_fprint_error_one(). ==================== diff --git a/src/box/mp_error.cc b/src/box/mp_error.cc index 23a74d0a9..badf7ee92 100644 --- a/src/box/mp_error.cc +++ b/src/box/mp_error.cc @@ -561,6 +561,16 @@ error_unpack_unsafe(const char **data) return err; } +static const char *const mp_error_field_to_json_key[MP_ERROR_MAX] = { + [MP_ERROR_TYPE] = "\"type\": ", + [MP_ERROR_FILE] = "\"file\": ", + [MP_ERROR_LINE] = "\"line\": ", + [MP_ERROR_MESSAGE] = "\"message\": ", + [MP_ERROR_ERRNO] = "\"errno\": ", + [MP_ERROR_CODE] = "\"code\": ", + [MP_ERROR_FIELDS] = "\"fields\": ", +}; + /** * Include this file into self with a few template parameters * to create mp_snprint_error() and mp_fprint_error() functions @@ -634,15 +644,6 @@ mp_print_error_one(MP_PRINT_ARGS_DECL, const char **data, int depth) MP_PRINT(total, "...}"); return total; } - const char *field_to_key[MP_ERROR_MAX] = { - [MP_ERROR_TYPE] = "\"type\": ", - [MP_ERROR_FILE] = "\"file\": ", - [MP_ERROR_LINE] = "\"line\": ", - [MP_ERROR_MESSAGE] = "\"message\": ", - [MP_ERROR_ERRNO] = "\"errno\": ", - [MP_ERROR_CODE] = "\"code\": ", - [MP_ERROR_FIELDS] = "\"fields\": ", - }; --depth; if (mp_typeof(**data) != MP_MAP) return -1; @@ -654,7 +655,7 @@ mp_print_error_one(MP_PRINT_ARGS_DECL, const char **data, int depth) return -1; uint64_t key = mp_decode_uint(data); if (key < MP_ERROR_MAX) - MP_PRINT(total, "%s", field_to_key[key]); + MP_PRINT(total, "%s", mp_error_field_to_json_key[key]); else MP_PRINT(total, "%llu: ", key); MP_PRINT_2(total, mp_print_common, data, depth);