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 DAA1929E3E for ; Tue, 9 Apr 2019 10:52:42 -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 ApAzJygTwCkb for ; Tue, 9 Apr 2019 10:52:42 -0400 (EDT) Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 1D82529DE0 for ; Tue, 9 Apr 2019 10:52:42 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) Subject: [tarantool-patches] Re: [PATCH 1/2] sql: make aggregate functions types more strict From: "n.pettik" In-Reply-To: Date: Tue, 9 Apr 2019 17:52:39 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <0E8891A8-AA2A-451F-8880-DD5F485843C1@tarantool.org> References: 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 Cc: Ivan Koptelov Please, don=E2=80=99t use the same commit message within patch-set. In this particular case, I=E2=80=99d say: sql: fix code style of functions implementing min/max aggregates > On 5 Apr 2019, at 17:57, Ivan Koptelov = wrote: >=20 > Let's firstly fix code-style. > --- > src/box/sql/func.c | 31 +++++++++++++++---------------- > 1 file changed, 15 insertions(+), 16 deletions(-) >=20 > diff --git a/src/box/sql/func.c b/src/box/sql/func.c > index b86a95d9a..b1bfc886e 100644 > --- a/src/box/sql/func.c > +++ b/src/box/sql/func.c > @@ -1585,23 +1585,22 @@ countFinalize(sql_context * context) > * Routines to implement min() and max() aggregate functions. > */ diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 379f28252..ad8e373ae 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1597,7 +1597,7 @@ countFinalize(sql_context * context) sql_result_int64(context, p ? p->n : 0); } =20 -/* +/** * Routines to implement min() and max() aggregate functions. */ static void > static void > -minmaxStep(sql_context * context, int NotUsed, sql_value ** argv) > +minmaxStep(sql_context *context, int not_used, sql_value **argv) FIx name of function -> minmax_agg_step() > { > - Mem *pArg =3D (Mem *) argv[0]; > - Mem *pBest; > - UNUSED_PARAMETER(NotUsed); > + UNUSED_PARAMETER(not_used); > + sql_value *arg =3D argv[0]; > + sql_value *best =3D sql_aggregate_context(context, = sizeof(*best)); What is best? Use more specific name or add comment. I got it only after 30 minutes... >=20 > - pBest =3D (Mem *) sql_aggregate_context(context, = sizeof(*pBest)); > - if (!pBest) > + if (best =3D=3D NULL) > return; >=20 > if (sql_value_type(argv[0]) =3D=3D SQL_NULL) { > - if (pBest->flags) > + if (best->flags !=3D 0) > sqlSkipAccumulatorLoad(context); > - } else if (pBest->flags) { > + } else if (best->flags !=3D 0) { > int max; > int cmp; > - struct coll *pColl =3D sqlGetFuncCollSeq(context); > + struct coll *coll =3D sqlGetFuncCollSeq(context); > /* This step function is used for both the min() and = max() aggregates, > * the only difference between the two being that the = sense of the > * comparison is inverted. For the max() aggregate, the Fix comment formatting: @@ -1658,12 +1658,15 @@ minmaxStep(sql_context *context, int not_used, = sql_value **argv) int max; int cmp; struct coll *coll =3D sqlGetFuncCollSeq(context); - /* This step function is used for both the min() and = max() aggregates, - * the only difference between the two being that the = sense of the - * comparison is inverted. For the max() aggregate, the - * sql_user_data() function returns (void *)-1. For = min() it - * returns (void *)db, where db is the sql* database = pointer. - * Therefore the next statement sets variable 'max' to 1 = for the max() + /* + * This step function is used for both the min() + * and max() aggregates, the only difference + * between the two being that the sense of the + * comparison is inverted. For the max() aggregate, + * the sql_user_data() function returns (void *)-1. + * For min() it returns (void *)db, where db is the + * sql* database pointer. Therefore the next + * statement sets variable 'max' to 1 for the max() * aggregate, or 0 for min(). */ > @@ -1611,15 +1610,15 @@ minmaxStep(sql_context * context, int NotUsed, = sql_value ** argv) > * aggregate, or 0 for min(). > */ > max =3D sql_user_data(context) !=3D 0; > - cmp =3D sqlMemCompare(pBest, pArg, pColl); > - if ((max && cmp < 0) || (!max && cmp > 0)) { > - sqlVdbeMemCopy(pBest, pArg); > + cmp =3D sqlMemCompare(best, arg, coll); > + if ((max !=3D 0 && cmp < 0) || (max =3D=3D 0 && cmp > = 0)) { > + sqlVdbeMemCopy(best, arg); > } else { > sqlSkipAccumulatorLoad(context); > } > } else { > - pBest->db =3D sql_context_db_handle(context); > - sqlVdbeMemCopy(pBest, pArg); > + best->db =3D sql_context_db_handle(context); > + sqlVdbeMemCopy(best, arg); > } > } >=20 > @@ -1628,8 +1627,8 @@ minMaxFinalize(sql_context * context) Finish refactoring of this function. > { > sql_value *pRes; > pRes =3D (sql_value *) sql_aggregate_context(context, 0); > - if (pRes) { > - if (pRes->flags) { > + if (pRes !=3D NULL) { > + if (pRes->flags !=3D 0) { > sql_result_value(context, pRes); > } > sqlVdbeMemRelease(pRes); > --=20