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 483D36E46B; Fri, 8 Oct 2021 20:39:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 483D36E46B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1633714788; bh=HnyU5Zgxh1risDZRRx9C8KWc9hOQ19EOhraUEv3/lHU=; 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=Q6nvUjaVCDoUyayVmMixHzen01vsTjUOHrsQLzlNIJ1G4+I53Wo/Ne5wgiWvSHfET GTXtn5mZFIpfKDSRa6mCV4191T+5yKZO46JMxOH9Zr6XW+84+npNmTLFDixT823u/R YHRwjb5ZI/Vf6vjzGejNEJD6JcmvSjSXehS84ubY= 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 EB3526DB06 for ; Fri, 8 Oct 2021 20:32:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EB3526DB06 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mYtj0-0008Ag-Aj; Fri, 08 Oct 2021 20:32:02 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 8 Oct 2021 20:32:02 +0300 Message-Id: <1a76cd1ebe317799fc224382efffb9365b075968.1633713432.git.imeevma@gmail.com> 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: 4F1203BC0FB41BD9A6D4E3B1981C4C7DC9765195527EE77661ADD44F6E79FA5A182A05F5380850408C052783355F95EC223EC7464F063A13145704BFC109B22D196A7352E0D0D7AC X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7DECE8D0A5E25C0FCEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637651D61939D0B3DD78638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8D10EAC66305117067A708CEAD4AE4F18117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B62CFFCC7B69C47339089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C650BD2383FF25EF5FCA70F4FAD658E3AD6BA2365A7F1CF059C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF520746E264B47742699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3435B1F14A93C4073FD45F70974E448A4A78A2119F1B0D9063660BA5314CD9239EA2D2E46ADAA4C39F1D7E09C32AA3244C4F5CA9B43E273EA2E8D33B3974C0D1CF1E098CBE561D6343729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojMZ06aokA6bomlc+wIMDSRQ== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DC77C1A49E61A135D0EEC20C30788D8E583D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B 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 | 58 ++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 38 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index a3ca53545..f26d101e9 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1460,34 +1460,26 @@ 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); + 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; @@ -1497,22 +1489,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); @@ -1526,9 +1508,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