From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 18BEB70296; Thu, 11 Nov 2021 13:58:07 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 18BEB70296 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1636628287; bh=BL9pGtN5XsMNcuVlmcVxQ9wfnuJLt8HXUIYCU41XQmQ=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=XUEl75IY4Pyl0BqJm4Y3O/96lFs/RKfYjap+qd4cjIo5FNIoe8zXEbhraRgEY1/pr qttHah8ZzzbUm0xdQFY6k/n9vufNqO/vtC3oCHw2HxsayEyV/1/QK0DBt5RCH/jP3m 1hPAkf23pPUo8P38NFgMsLyB8ohBAFM8TkWhqFZ4= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id F1F747106E for ; Thu, 11 Nov 2021 13:49:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org F1F747106E Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1ml7du-00057b-5q; Thu, 11 Nov 2021 13:49:18 +0300 To: kyukhin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Thu, 11 Nov 2021 13:49:17 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9731B3922EC06397911A6D4ED1A8575E7BD5B9E03AA43849A00894C459B0CD1B973F82962D144509D315DB9115FA3B015BD7B9CED87D25567083B9DBA0D511FCC X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7B9FBA884A7C9B8BAEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006370F98874192B1BA168638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8B13D4AC49BED60B641A686A86FF48EDA117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B66F6A3E018CF4DC80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C7E9FEBB9C11794A16337B4D7FF0D6C2547FBF14789C9B4429C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFCDE59DDCCE53AF2B699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34BC3EEE75EF3BACCF51728757CD362223907E9833DA2A0211AE548DDB6082C421C96963663811CAE91D7E09C32AA3244C6D6B9AB0E8610BEA765701340B9B75FF435BF7150578642F729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj4t8MBgWr8bJ99o6P+Irwbg== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D601DECB6C259DE6F8B448B5A3D11471C83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 16/21] sql: refactor REPLACE() function X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Part of #4145 --- src/box/sql/func.c | 59 +++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index ed4d681fc..3b1e62ebf 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1496,34 +1496,27 @@ replaceFunc(struct sql_context *context, int argc, struct Mem *argv) int i, j; /* Loop counters */ assert(argc == 3); - UNUSED_PARAMETER(argc); - zStr = mem_as_ustr(&argv[0]); - if (zStr == 0) - return; - nStr = mem_len_unsafe(&argv[0]); - assert(zStr == mem_as_ustr(&argv[0])); /* No encoding change */ - zPattern = mem_as_ustr(&argv[1]); - if (zPattern == 0) { - assert(mem_is_null(&argv[1]) - || sql_context_db_handle(context)->mallocFailed); + (void)argc; + if (mem_is_any_null(&argv[0], &argv[1]) || mem_is_null(&argv[2])) return; - } - nPattern = mem_len_unsafe(&argv[1]); + assert(mem_is_bytes(&argv[0]) && mem_is_bytes(&argv[1]) && + mem_is_bytes(&argv[2])); + zStr = (const unsigned char *)argv[0].z; + nStr = argv[0].n; + zPattern = (const unsigned char *)argv[1].z; + nPattern = argv[1].n; if (nPattern == 0) { - assert(!mem_is_null(&argv[1])); - sql_result_value(context, &argv[0]); + if (mem_copy(context->pOut, &argv[0]) != 0) + context->is_aborted = true; return; } - assert(zPattern == mem_as_ustr(&argv[1])); /* No encoding change */ - zRep = mem_as_ustr(&argv[2]); - if (zRep == 0) - return; - nRep = mem_len_unsafe(&argv[2]); - assert(zRep == mem_as_ustr(&argv[2])); + zRep = (const unsigned char *)argv[2].z; + nRep = argv[2].n; nOut = nStr + 1; - assert(nOut < SQL_MAX_LENGTH); - zOut = contextMalloc(context, (i64) nOut); - if (zOut == 0) { + struct sql *db = sql_get(); + zOut = sqlDbMallocRawNN(db, nOut); + if (zOut == NULL) { + context->is_aborted = true; return; } loopLimit = nStr - nPattern; @@ -1533,22 +1526,12 @@ replaceFunc(struct sql_context *context, int argc, struct Mem *argv) zOut[j++] = zStr[i]; } else { u8 *zOld; - sql *db = sql_context_db_handle(context); nOut += nRep - nPattern; - testcase(nOut - 1 == db->aLimit[SQL_LIMIT_LENGTH]); - testcase(nOut - 2 == db->aLimit[SQL_LIMIT_LENGTH]); - if (nOut - 1 > db->aLimit[SQL_LIMIT_LENGTH]) { - diag_set(ClientError, ER_SQL_EXECUTE, "string "\ - "or binary string is too big"); - context->is_aborted = true; - sql_free(zOut); - return; - } zOld = zOut; - zOut = sql_realloc64(zOut, (int)nOut); - if (zOut == 0) { + zOut = sqlDbRealloc(db, zOut, nOut); + if (zOut == NULL) { context->is_aborted = true; - sql_free(zOld); + sqlDbFree(db, zOld); return; } memcpy(&zOut[j], zRep, nRep); @@ -1562,9 +1545,9 @@ replaceFunc(struct sql_context *context, int argc, struct Mem *argv) assert(j <= nOut); zOut[j] = 0; if (context->func->def->returns == FIELD_TYPE_STRING) - mem_set_str_dynamic(context->pOut, (char *)zOut, j); + mem_set_str_allocated(context->pOut, (char *)zOut, j); else - mem_set_bin_dynamic(context->pOut, (char *)zOut, j); + mem_set_bin_allocated(context->pOut, (char *)zOut, j); } /* -- 2.25.1