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 0509A28F84 for ; Mon, 11 Mar 2019 11:04:50 -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 C56lYwOTlWEp for ; Mon, 11 Mar 2019 11:04:49 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (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 A83D128C01 for ; Mon, 11 Mar 2019 11:04:49 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v2 1/7] sql: refactor sql_alloc_src_list to set diag References: <9bc544e742ad88f4fd6a3738fb4993d789832bc6.1551265819.git.kshcherbatov@tarantool.org> <1aa67789-567f-4e38-0d7d-db45f302c6d4@tarantool.org> From: Kirill Shcherbatov Message-ID: Date: Mon, 11 Mar 2019 18:04:47 +0300 MIME-Version: 1.0 In-Reply-To: <1aa67789-567f-4e38-0d7d-db45f302c6d4@tarantool.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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, Vladislav Shpilevoy On 07.03.2019 20:34, Vladislav Shpilevoy wrote: > Hi! Thanks for the patch! Hi! Thank you for review. ===================================================== Refactored sqlAllocSrcList routine as sql_src_list_new and reworked it to use diag_set in case of memory allocation error. This will ensure that the sqlSrcListAppend function throws an error using diag in subsequent patches. This patch refers to a series of preparatory patches that provide the use of Tarantool errors in the call tree that includes sqlNormalizeName, since this call can later return errors. This patch is not self-sufficient, its usage in sqlSrcListAppend remained to be non-Tarantool (for now). It means, that if sql_src_list_new fails in sqlSrcListAppend and sets a diag, it is never thrown to a user (now). Part of #3931 --- src/box/sql/build.c | 34 +++++++++++++++++++--------------- src/box/sql/select.c | 2 +- src/box/sql/sqlInt.h | 13 +++++++++++-- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/box/sql/build.c b/src/box/sql/build.c index e9851d9a1..760054552 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -1396,9 +1396,12 @@ vdbe_emit_stat_space_clear(struct Parse *parse, const char *stat_table_name, assert(idx_name != NULL || table_name != NULL); struct sql *db = parse->db; assert(!db->mallocFailed); - struct SrcList *src_list = sql_alloc_src_list(db); - if (src_list != NULL) - src_list->a[0].zName = sqlDbStrDup(db, stat_table_name); + struct SrcList *src_list = sql_src_list_new(db); + if (src_list == NULL) { + sql_parser_error(parse); + return; + } + src_list->a[0].zName = sqlDbStrDup(db, stat_table_name); struct Expr *where = NULL; if (idx_name != NULL) { struct Expr *expr = sql_id_eq_str_expr(parse, "idx", idx_name); @@ -2666,19 +2669,20 @@ sqlSrcListEnlarge(sql * db, /* Database connection to notify of OOM errors */ return pSrc; } -SrcList * -sql_alloc_src_list(sql *db) +struct SrcList * +sql_src_list_new(struct sql *db) { - SrcList *pList; - - pList = sqlDbMallocRawNN(db, sizeof(SrcList)); - if (pList == 0) + struct SrcList *src_list = sqlDbMallocRawNN(db, sizeof(SrcList)); + if (src_list == NULL) { + diag_set(OutOfMemory, sizeof(SrcList), "sqlDbMallocRawNN", + "src_list"); return NULL; - pList->nAlloc = 1; - pList->nSrc = 1; - memset(&pList->a[0], 0, sizeof(pList->a[0])); - pList->a[0].iCursor = -1; - return pList; + } + src_list->nAlloc = 1; + src_list->nSrc = 1; + memset(&src_list->a[0], 0, sizeof(src_list->a[0])); + src_list->a[0].iCursor = -1; + return src_list; } /* @@ -2724,7 +2728,7 @@ sqlSrcListAppend(sql * db, /* Connection to notify of malloc failures */ struct SrcList_item *pItem; assert(db != 0); if (pList == 0) { - pList = sql_alloc_src_list(db); + pList = sql_src_list_new(db); if (pList == 0) return 0; } else { diff --git a/src/box/sql/select.c b/src/box/sql/select.c index 782da1f7c..16d535076 100644 --- a/src/box/sql/select.c +++ b/src/box/sql/select.c @@ -315,7 +315,7 @@ sql_select_expand_from_tables(struct Select *select) { assert(select != NULL); struct Walker walker; - struct SrcList *table_names = sql_alloc_src_list(sql_get()); + struct SrcList *table_names = sql_src_list_new(sql_get()); if (table_names == NULL) return NULL; memset(&walker, 0, sizeof(walker)); diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 1d8fae5b0..4a4a748ba 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -3391,8 +3391,17 @@ void *sqlArrayAllocate(sql *, void *, int, int *, int *); IdList *sqlIdListAppend(sql *, IdList *, Token *); int sqlIdListIndex(IdList *, const char *); SrcList *sqlSrcListEnlarge(sql *, SrcList *, int, int); -SrcList * -sql_alloc_src_list(sql *db); + +/** + * Allocate a new empty SrcList object. + * + * @param db The database connection. + * @retval Not NULL list pointer on success. + * @retval NULL Otherwise. The diag message is set. + */ +struct SrcList * +sql_src_list_new(struct sql *db); + SrcList *sqlSrcListAppend(sql *, SrcList *, Token *); SrcList *sqlSrcListAppendFromTerm(Parse *, SrcList *, Token *, Token *, Select *, Expr *, IdList *); -- 2.21.0