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 1EAC424EEB for ; Thu, 24 May 2018 15:26:35 -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 sar7dV9qMgZz for ; Thu, 24 May 2018 15:26:35 -0400 (EDT) Received: from smtp33.i.mail.ru (smtp33.i.mail.ru [94.100.177.93]) (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 CC66424DF0 for ; Thu, 24 May 2018 15:26:34 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v7 2/7] box: introduce OPT_ARRAY opt_type to decode arrays References: From: Vladislav Shpilevoy Message-ID: <73780eb4-fbd6-68cd-fdcf-bec1e6c354a3@tarantool.org> Date: Thu, 24 May 2018 22:26:30 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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, Kirill Shcherbatov Thanks for the patch! See 1 comment below. On 23/05/2018 17:05, Kirill Shcherbatov wrote: > As we need to store Checks array in opt_def MsgPack in future > introduced special type and decode callback to_array used in opt_set > function. > > Part of #3272. > --- > src/box/opt_def.c | 9 +++++++++ > src/box/opt_def.h | 19 ++++++++++++++----- > 2 files changed, 23 insertions(+), 5 deletions(-) > > diff --git a/src/box/opt_def.c b/src/box/opt_def.c > index cd93c23..c8440c9 100644 > --- a/src/box/opt_def.c > +++ b/src/box/opt_def.c > @@ -44,6 +44,7 @@ const char *opt_type_strs[] = { > /* [OPT_STR] = */ "string", > /* [OPT_STRPTR] = */ "string", > /* [OPT_ENUM] = */ "enum", > + /* [OPT_ARRAY] = */ "array", > }; > > static int > @@ -135,6 +136,14 @@ opt_set(void *opts, const struct opt_def *def, const char **val, > unreachable(); > }; > break; > + case OPT_ARRAY: > + if (mp_typeof(**val) != MP_ARRAY) > + return -1; > + ival = mp_decode_array(val); > + assert(def->to_array != NULL); > + if (def->to_array(val, ival, opt) != 0) > + return -1; 1. If to_array is failed, the error is reset in opts_parse_key: snprintf(errmsg, sizeof(errmsg), "'%.*s' must be %s", key_len, key, opt_type_strs[def->type]); diag_set(ClientError, errcode, field_no, errmsg); So the original error is lost. You should refactor opt_set so that it sets diag on type mismatch instead of doing it in opts_parse_key. And opts_parse_key does nothing on error in opt_set - just return -1. > + break; > default: > unreachable(); > }