From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Fri, 17 Aug 2018 18:57:34 +0300 From: Vladimir Davydov Subject: Re: [tarantool-patches] Re: [PATCH v2] Introduce separate entity object types for entity privileges. Message-ID: <20180817155734.cdyvqlnttszp5e26@esperanza> References: <20180802105558.20488-1-sergepetrenko@tarantool.org> <20180807163842.agnqqk7gyua2vwzv@esperanza> <305E5CD8-68DD-4897-9E77-347F290091A6@tarantool.org> <20180817091931.r45zifiikkwzuycu@esperanza> <93712A9E-2004-4609-8506-4ACB043A627B@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <93712A9E-2004-4609-8506-4ACB043A627B@tarantool.org> To: Serge Petrenko Cc: Konstantin Osipov , tarantool-patches@freelists.org List-ID: On Fri, Aug 17, 2018 at 03:19:29PM +0300, Serge Petrenko wrote: > diff --git a/src/box/alter.cc b/src/box/alter.cc > index 3007a131d..f586a2695 100644 > --- a/src/box/alter.cc > +++ b/src/box/alter.cc > @@ -2537,10 +2537,35 @@ priv_def_create_from_tuple(struct priv_def *priv, struct tuple *tuple) > { > priv->grantor_id = tuple_field_u32_xc(tuple, BOX_PRIV_FIELD_ID); > priv->grantee_id = tuple_field_u32_xc(tuple, BOX_PRIV_FIELD_UID); > + > const char *object_type = > tuple_field_cstr_xc(tuple, BOX_PRIV_FIELD_OBJECT_TYPE); > - priv->object_id = tuple_field_u32_xc(tuple, BOX_PRIV_FIELD_OBJECT_ID); > priv->object_type = schema_object_type(object_type); > + > + const char *data = tuple_field(tuple, BOX_PRIV_FIELD_OBJECT_ID); > + if (data == NULL) { > + tnt_raise(ClientError, ER_NO_SUCH_FIELD, Bad indentation - should be a tab here. Please fix. > + * > + * When adding new types please keep the > + * same order between objects and corresponding entity types. > + * schema_entity_type() relies on this convention. > */ > enum schema_object_type { > SC_UNKNOWN = 0, > @@ -228,9 +232,21 @@ enum schema_object_type { > SC_ROLE = 5, > SC_SEQUENCE = 6, > SC_COLLATION = 7, > - schema_object_type_MAX = 8 > + schema_object_type_MAX = 8, Please add a comment here that says that below this point only entity types are supposed to be defined. > + SC_ENTITY_SPACE, > + SC_ENTITY_FUNCTION, > + SC_ENTITY_USER, > + SC_ENTITY_ROLE, > + SC_ENTITY_SEQUENCE, > + SC_ENTITY_COLLATION > }; > +enum schema_object_type > +schema_entity_type(enum schema_object_type type) > +{ > + assert((int) type < (int) schema_object_type_MAX); > + return type + schema_object_type_MAX - 1; > +} No. Too fragile - easy to make a mistake when adding a new type. And this -1 looks suspicious. Kostja isn't going to like it. I vote for rewriting this code with a simple switch-case.