Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Serge Petrenko <sergepetrenko@tarantool.org>
Cc: Konstantin Osipov <kostja@tarantool.org>,
	tarantool-patches@freelists.org
Subject: Re: [tarantool-patches] Re: [PATCH v2] Introduce separate entity object types for entity privileges.
Date: Fri, 17 Aug 2018 18:57:34 +0300	[thread overview]
Message-ID: <20180817155734.cdyvqlnttszp5e26@esperanza> (raw)
In-Reply-To: <93712A9E-2004-4609-8506-4ACB043A627B@tarantool.org>

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.

      reply	other threads:[~2018-08-17 15:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-02 10:55 [tarantool-patches] " Serge Petrenko
2018-08-07 16:38 ` Vladimir Davydov
2018-08-14 13:41   ` Serge Petrenko
2018-08-17  9:19     ` Vladimir Davydov
2018-08-17 12:19       ` [tarantool-patches] " Serge Petrenko
2018-08-17 15:57         ` Vladimir Davydov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180817155734.cdyvqlnttszp5e26@esperanza \
    --to=vdavydov.dev@gmail.com \
    --cc=kostja@tarantool.org \
    --cc=sergepetrenko@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] Re: [PATCH v2] Introduce separate entity object types for entity privileges.' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox