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 01D0324B0B for ; Mon, 18 Jun 2018 21:12:18 -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 DFREJANFmsPQ for ; Mon, 18 Jun 2018 21:12:17 -0400 (EDT) Received: from smtp62.i.mail.ru (smtp62.i.mail.ru [217.69.128.42]) (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 421A424B02 for ; Mon, 18 Jun 2018 21:12:17 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [tarantool-patches] Re: [PATCH v2] sql: fix decode analyze sample From: "n.pettik" In-Reply-To: <20180601165014.30131-1-avkhatskevich@tarantool.org> Date: Tue, 19 Jun 2018 04:12:06 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: <20180601165014.30131-1-avkhatskevich@tarantool.org> 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: Alex Khatskevich Except for comments below, pls rebase on fresh 2.0. Your branch seems to be way behind current master. > int sqlite3Stat4ValueFromExpr(Parse *, Expr *, u8, sqlite3_value **); > void sqlite3Stat4ProbeFree(UnpackedRecord *); > -int sqlite3Stat4Column(sqlite3 *, const void *, int, int, = sqlite3_value **); > + > +/* Start comment with /** > + * Extract the iCol-th column from the record in pRec. Write > + * the column value into *ppVal. If *ppVal is initially NULL Lets move from Hungarian notation to Tarantool-style naming. Moreover, you didn=E2=80=99t specify args names in func prototype. > + * then a new sqlite3_value object is allocated. > + * > + * If *ppVal is initially NULL then the caller is responsible for > + * ensuring that the value written into *ppVal is eventually > + * freed. > + * > + * @param db Database handle. > + * @param pRec Pointer to buffer containing record. > + * @param iCol Column to extract. > + * @param[out] ppVal Extracted value. > + * > + * @retval Error code or SQLITE_OK. Or SQLITE_OK on success (or 0 after fixes). > + */ > +int > +sql_stat4_column(struct sqlite3 *, const void *, int, sqlite3_value = **); > char sqlite3IndexColumnAffinity(sqlite3 *, Index *, int); >=20 > /* > diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c > index f91d7119c..821d4db74 100644 > --- a/src/box/sql/vdbemem.c > +++ b/src/box/sql/vdbemem.c > @@ -1588,55 +1588,29 @@ sqlite3Stat4ValueFromExpr(Parse * pParse, = /* Parse context */ > return stat4ValueFromExpr(pParse, pExpr, affinity, 0, ppVal); > } >=20 > -/* > - * Extract the iCol-th column from the nRec-byte record in pRec. = Write > - * the column value into *ppVal. If *ppVal is initially NULL then a = new > - * sqlite3_value object is allocated. > - * > - * If *ppVal is initially NULL then the caller is responsible for > - * ensuring that the value written into *ppVal is eventually freed. > - */ > int > -sqlite3Stat4Column(sqlite3 * db, /* Database handle */ > - const void *pRec, /* Pointer to buffer containing = record */ > - int nRec, /* Size of buffer pRec in bytes */ > - int iCol, /* Column to extract */ > - sqlite3_value ** ppVal /* OUT: Extracted value = */ > - ) > +sql_stat4_column(struct sqlite3 *db, const void *record, int col_num, > + sqlite3_value **res) > { > - u32 t; /* a column type code */ > - int nHdr; /* Size of the header in the record */ > - int iHdr; /* Next unread header byte */ > - int iField; /* Next unread data byte */ > - int szField =3D 0; /* Size of the current data field */ > - int i; /* Column index */ > - u8 *a =3D (u8 *) pRec; /* Typecast byte array */ > - Mem *pMem =3D *ppVal; /* Write result into this Mem object */ > - > - assert(iCol > 0); > - iHdr =3D getVarint32(a, nHdr); > - if (nHdr > nRec || iHdr >=3D nHdr) > - return SQLITE_CORRUPT_BKPT; > - iField =3D nHdr; > - for (i =3D 0; i <=3D iCol; i++) { > - iHdr +=3D getVarint32(&a[iHdr], t); > - testcase(iHdr =3D=3D nHdr); > - testcase(iHdr =3D=3D nHdr + 1); > - if (iHdr > nHdr) > - return SQLITE_CORRUPT_BKPT; > - szField =3D sqlite3VdbeSerialTypeLen(t); > - iField +=3D szField; > - } > - testcase(iField =3D=3D nRec); > - testcase(iField =3D=3D nRec + 1); > - if (iField > nRec) > - return SQLITE_CORRUPT_BKPT; > - if (pMem =3D=3D 0) { > - pMem =3D *ppVal =3D sqlite3ValueNew(db); > - if (pMem =3D=3D 0) > - return SQLITE_NOMEM_BKPT; > + assert(col_num >=3D 0); > + /* Write result into this Mem object */ Put dots at the end of sentences. > + Mem *mem =3D *res; Lets use struct prefix. > + /* Typecast byte array */ > + const char *a =3D (const char *) record; Lets pass already const char*. AFAIK all routine connected with MsgPack accepts const char *, but not void *. > + assert(mp_typeof(a[0]) =3D=3D MP_ARRAY); > + int col_cnt =3D mp_decode_array(&a); > + assert(col_cnt > col_num); > + for (int i =3D 0; i < col_num; i++) > + mp_next(&a); > + if (mem =3D=3D 0) { =3D=3D NULL > + mem =3D *res =3D sqlite3ValueNew(db); Don=E2=80=99t use double assignments. > + if (mem =3D=3D 0) { =3D=3D NULL > + diag_set(OutOfMemory, sizeof(Mem), = "sqlite3ValeuNew=E2=80=9D, sqlite3ValueNew > + "mem"); > + return -1; > + } > } > - sqlite3VdbeSerialGet(&a[iField - szField], t, pMem); > + sqlite3VdbeMsgpackGet((const unsigned char *) record, mem); > return SQLITE_OK; Just return 0 (in fact, they are the same thing).