From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 5191746971A for ; Thu, 5 Dec 2019 22:14:01 +0300 (MSK) Received: by mail-lj1-f196.google.com with SMTP id m6so4909130ljc.1 for ; Thu, 05 Dec 2019 11:14:01 -0800 (PST) Date: Thu, 5 Dec 2019 22:13:57 +0300 From: Cyrill Gorcunov Message-ID: <20191205191357.GB2469@uranus> References: <0218889f41f954a10bbe36c6d0c43f32fa7dd4b4.1575468493.git.roman.habibov@tarantool.org> <20191204175450.GD19235@atlas> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Subject: Re: [Tarantool-patches] [PATCH v2 3/3] box: let only box handle constraint dup errors List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Roman Khabibov Cc: Konstantin Osipov , tarantool-patches@dev.tarantool.org, Vladislav Shpilevoy On Thu, Dec 05, 2019 at 09:59:33PM +0300, Roman Khabibov wrote: > > Vlad, please, don’t see the previous. > > Cyrill, I added both for sure. Thanks! > +/** > + * Just return string with constraint type to print it in error > + * message. > + */ > +static inline const char * > +cosntraint_type_str(struct constraint_def *def) { > + assert(def->type == CONSTRAINT_TYPE_PK || def->type == > + CONSTRAINT_TYPE_UNIQUE || def->type == CONSTRAINT_TYPE_FK || > + def->type == CONSTRAINT_TYPE_CK); > + switch (def->type) { > + case CONSTRAINT_TYPE_PK: > + return "PRIMARY KEY"; > + case CONSTRAINT_TYPE_UNIQUE: > + return "UNIQUE"; > + case CONSTRAINT_TYPE_FK: > + return "FOREIGN KEY"; > + case CONSTRAINT_TYPE_CK: > + return "CHECK"; > + default: > + break; > + } > + return NULL; > +} This is a way better than it was. To be honest I'm not strong in the whole context of the series, but when I need to provide some symbolic name I do something like /** * popen_state_str - get process state string representation * @state: process state */ const char * popen_state_str(unsigned int state) { /* * A process may be in a number of states, * running/sleeping/disk sleep/stopped and etc * but we are interested only if it is alive * or dead (via plain exit or kill signal). * * Thus while it present in a system and not * yet reaped we call it "alive". * * Note this is API for lua, so change with * caution if needed. */ static const char * state_str[POPEN_STATE_MAX] = { [POPEN_STATE_NONE] = "none", [POPEN_STATE_RUNNING] = "alive", [POPEN_STATE_EXITED] = "exited", [POPEN_STATE_SIGNALED] = "signaled", }; return state < POPEN_STATE_MAX ? state_str[state] : "unknown"; } but note that I know the number of entries so it might not fit your needs thus I'm fine with your current code. Thanks!