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 A72426E46D; Fri, 8 Oct 2021 20:40:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A72426E46D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1633714848; bh=c2j5SotJ1XGNn79K98iYiHroqDpivTcHOiHtPRLV8yU=; 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=fL4hW33OK9qYBF0gSIAtwRhCkyvwPmpcOnm2eje4GEov4KkU9QQId3L9OU9At/t96 yIlYttSGYF+14Ax3Cpqj2xk8WOQo/upgUsTBzFOMNuq0qkcrHCCJd/s68G9ghRD5MA OS4AizL1ipDIfxlz45h3D0gjxYnzU7dLxjd8k51c= 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 217AD70202 for ; Fri, 8 Oct 2021 20:32:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 217AD70202 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mYtj3-0008Bs-Ef; Fri, 08 Oct 2021 20:32:05 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 8 Oct 2021 20:32:05 +0300 Message-Id: <431c5ea816ff1264a0672d54e25fb2a8a22a6c20.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: 4F1203BC0FB41BD9A6D4E3B1981C4C7DECD3BE02BC5B2D4F269A0E3D85100611182A05F538085040F8A9AB0CDE594AFF57681AB0AEFA5C3D0784DF0E0F278E04894E19F9952C9978 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7B9D6DADD6B53929DEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637BBB1CE3B4DF50705EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F264B527D6CC12CAEA0A33002DF28DF2ABCC7F00164DA146DAFE8445B8C89999728AA50765F7900637DCE3DBD6F8E38AFD389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8FA486DC37A503D0BF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8B953A8A48A05D51F175ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C650BD2383FF25EF54F414EAA15D55E50B3F0755B9985EC059C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF520746E264B47742699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34951738D4D62E58A49EBE9A39AB1676476FFFDB709D0DCC8847A61C320CFDEA10AC3441DCDAA499781D7E09C32AA3244CE3271FB7CDEAD3BD51B7190B694735E91DD47778AE04E04D729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojMZ06aokA6brHCZII7LVILA== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DB88FC7C23AE80D2DE74EEB357DD7EE4683D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 18/21] sql: remove unused code 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" Some of the code is no longer used after changes in the SQL built-in functions. This patch removes part of the unused code. Needed for #4145 --- src/box/bind.c | 5 +- src/box/sql/mem.c | 11 -- src/box/sql/mem.h | 71 ------------- src/box/sql/sqlInt.h | 53 +--------- src/box/sql/vdbeapi.c | 238 +++--------------------------------------- 5 files changed, 19 insertions(+), 359 deletions(-) diff --git a/src/box/bind.c b/src/box/bind.c index 58fff0b98..e75e36283 100644 --- a/src/box/bind.c +++ b/src/box/bind.c @@ -185,12 +185,11 @@ sql_bind_column(struct sql_stmt *stmt, const struct sql_bind *p, * there is no need to copy the packet and we can * use SQL_STATIC. */ - return sql_bind_text64(stmt, pos, p->s, p->bytes, SQL_STATIC); + return sql_bind_str_static(stmt, pos, p->s, p->bytes); case MP_NIL: return sql_bind_null(stmt, pos); case MP_BIN: - return sql_bind_blob64(stmt, pos, (const void *) p->s, p->bytes, - SQL_STATIC); + return sql_bind_bin_static(stmt, pos, p->s, p->bytes); case MP_EXT: assert(p->ext_type == MP_UUID || p->ext_type == MP_DECIMAL); if (p->ext_type == MP_UUID) diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index fe32a7ad7..895003580 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -2633,17 +2633,6 @@ mem_mp_type(const struct Mem *mem) return MP_NIL; } -/* EVIDENCE-OF: R-12793-43283 Every value in sql has one of five - * fundamental datatypes: 64-bit signed integer 64-bit IEEE floating - * point number string BLOB NULL - */ -enum mp_type -sql_value_type(sql_value *pVal) -{ - struct Mem *mem = (struct Mem *) pVal; - return mem_mp_type(mem); -} - #ifdef SQL_DEBUG /* * Check invariants on a Mem object. diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h index 7f7382961..1d995726f 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -351,54 +351,6 @@ mem_set_str0_dynamic(struct Mem *mem, char *value); void mem_set_str0_allocated(struct Mem *mem, char *value); -static inline void -mem_set_strl_ephemeral(struct Mem *mem, char *value, int len_hint) -{ - if (len_hint < 0) - mem_set_str0_ephemeral(mem, value); - else - mem_set_str_ephemeral(mem, value, len_hint); -} - -static inline void -mem_set_strl_static(struct Mem *mem, char *value, int len_hint) -{ - if (len_hint < 0) - mem_set_str0_static(mem, value); - else - mem_set_str_static(mem, value, len_hint); -} - -static inline void -mem_set_strl_dynamic(struct Mem *mem, char *value, int len_hint) -{ - if (len_hint < 0) - mem_set_str0_dynamic(mem, value); - else - mem_set_str_dynamic(mem, value, len_hint); -} - -static inline void -mem_set_strl_allocated(struct Mem *mem, char *value, int len_hint) -{ - if (len_hint < 0) - mem_set_str0_allocated(mem, value); - else - mem_set_str_allocated(mem, value, len_hint); -} - -static inline void -mem_set_strl(struct Mem *mem, char *value, int len_hint, - void (*custom_free)(void *)) -{ - if (custom_free == SQL_STATIC) - return mem_set_strl_static(mem, value, len_hint); - if (custom_free == SQL_DYNAMIC) - return mem_set_strl_allocated(mem, value, len_hint); - if (custom_free != SQL_TRANSIENT) - return mem_set_strl_dynamic(mem, value, len_hint); -} - /** Copy string to a newly allocated memory. The MEM type becomes STRING. */ int mem_copy_str(struct Mem *mem, const char *value, uint32_t len); @@ -410,14 +362,6 @@ mem_copy_str(struct Mem *mem, const char *value, uint32_t len); int mem_copy_str0(struct Mem *mem, const char *value); -static inline int -mem_copy_strl(struct Mem *mem, const char *value, int len_hint) -{ - if (len_hint < 0) - return mem_copy_str0(mem, value); - return mem_copy_str(mem, value, len_hint); -} - /** * Clear MEM and set it to VARBINARY. The binary value belongs to another * object. @@ -446,18 +390,6 @@ mem_set_bin_dynamic(struct Mem *mem, char *value, uint32_t size); void mem_set_bin_allocated(struct Mem *mem, char *value, uint32_t size); -static inline void -mem_set_binl(struct Mem *mem, char *value, uint32_t size, - void (*custom_free)(void *)) -{ - if (custom_free == SQL_STATIC) - return mem_set_bin_static(mem, value, size); - if (custom_free == SQL_DYNAMIC) - return mem_set_bin_allocated(mem, value, size); - if (custom_free != SQL_TRANSIENT) - return mem_set_bin_dynamic(mem, value, size); -} - /** * Copy binary value to a newly allocated memory. The MEM type becomes * VARBINARY. @@ -905,9 +837,6 @@ mem_type_to_str(const struct Mem *p); enum mp_type mem_mp_type(const struct Mem *mem); -enum mp_type -sql_value_type(struct Mem *); - #ifdef SQL_DEBUG int sqlVdbeCheckMemInvariants(struct Mem *); void sqlVdbeMemPrettyPrint(Mem * pMem, char *zBuf); diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 72f349944..9ccbe4ea3 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -355,45 +355,6 @@ sql_stricmp(const char *, const char *); int sql_strnicmp(const char *, const char *, int); -sql * -sql_context_db_handle(sql_context *); - - -void -sql_result_blob(sql_context *, const void *, - int, void (*)(void *)); - -void -sql_result_blob64(sql_context *, const void *, - sql_uint64, void (*)(void *)); - -void -sql_result_double(sql_context *, double); - -void -sql_result_uint(sql_context *ctx, uint64_t u_val); - -void -sql_result_int(sql_context *ctx, int64_t val); - -void -sql_result_bool(struct sql_context *ctx, bool value); - -void -sql_result_null(sql_context *); - -void -sql_result_text(sql_context *, const char *, - int, void (*)(void *)); - -void -sql_result_text64(sql_context *, const char *, - sql_uint64, void (*)(void *)); - -void -sql_result_value(sql_context *, - sql_value *); - char * sql_mprintf(const char *, ...); char * @@ -567,14 +528,6 @@ sql_vfs_register(sql_vfs *, int makeDflt); void sql_unbind(struct sql_stmt *stmt); -int -sql_bind_blob(sql_stmt *, int, const void *, - int n, void (*)(void *)); - -int -sql_bind_blob64(sql_stmt *, int, const void *, - sql_uint64, void (*)(void *)); - int sql_bind_double(sql_stmt *, int, double); @@ -602,8 +555,10 @@ int sql_bind_null(sql_stmt *, int); int -sql_bind_text64(sql_stmt *, int, const char *, - sql_uint64, void (*)(void *)); +sql_bind_str_static(sql_stmt *stmt, int i, const char *str, uint32_t len); + +int +sql_bind_bin_static(sql_stmt *stmt, int i, const char *str, uint32_t size); int sql_bind_uuid(struct sql_stmt *stmt, int i, const struct tt_uuid *uuid); diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index 8f7e28ffb..59d01da88 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -107,135 +107,6 @@ sql_metadata_is_full() return current_session()->sql_flags & SQL_FullMetadata; } -/**************************** sql_result_ ****************************** - * The following routines are used by user-defined functions to specify - * the function result. - * - * The setStrOrError() function sets the result as a string or blob but - * if the string or blob is too large, it then sets the error code. - * - * The invokeValueDestructor(P,X) routine invokes destructor function X() - * on value P is not going to be used and need to be destroyed. - */ -static void -setResultStrOrError(sql_context * pCtx, /* Function context */ - const char *z, /* String pointer */ - int n, /* Bytes in string, or negative */ - void (*xDel) (void *) /* Destructor function */ - ) -{ - if (xDel != SQL_TRANSIENT) - return mem_set_strl(pCtx->pOut, (char *)z, n, xDel); - if (mem_copy_strl(pCtx->pOut, z, n) != 0) - pCtx->is_aborted = true; -} - -static int -invokeValueDestructor(const void *p, /* Value to destroy */ - void (*xDel) (void *), /* The destructor */ - sql_context *pCtx /* Set an error if no NULL */ - ) -{ - assert(xDel != SQL_DYNAMIC); - if (xDel == 0) { - /* noop */ - } else if (xDel == SQL_TRANSIENT) { - /* noop */ - } else { - xDel((void *)p); - } - if (pCtx) { - diag_set(ClientError, ER_SQL_EXECUTE, "string or binary string"\ - "is too big"); - pCtx->is_aborted = true; - } - return -1; -} - -void -sql_result_blob(sql_context * pCtx, - const void *z, int n, void (*xDel) (void *) - ) -{ - assert(n >= 0); - if (xDel != SQL_TRANSIENT) - mem_set_binl(pCtx->pOut, (char *)z, n, xDel); - else if (mem_copy_bin(pCtx->pOut, z, n) != 0) - pCtx->is_aborted = true; -} - -void -sql_result_blob64(sql_context * pCtx, - const void *z, sql_uint64 n, void (*xDel) (void *) - ) -{ - assert(xDel != SQL_DYNAMIC); - if (n > 0x7fffffff) { - (void)invokeValueDestructor(z, xDel, pCtx); - } else { - setResultStrOrError(pCtx, z, (int)n, xDel); - } -} - -void -sql_result_double(sql_context * pCtx, double rVal) -{ - mem_set_double(pCtx->pOut, rVal); -} - -void -sql_result_uint(sql_context *ctx, uint64_t u_val) -{ - mem_set_uint(ctx->pOut, u_val); -} - -void -sql_result_int(sql_context *ctx, int64_t val) -{ - mem_set_int(ctx->pOut, val, val < 0); -} - -void -sql_result_bool(struct sql_context *ctx, bool value) -{ - mem_set_bool(ctx->pOut, value); -} - -void -sql_result_null(sql_context * pCtx) -{ - mem_set_null(pCtx->pOut); -} - -void -sql_result_text(sql_context * pCtx, - const char *z, int n, void (*xDel) (void *) - ) -{ - setResultStrOrError(pCtx, z, n, xDel); -} - -void -sql_result_text64(sql_context * pCtx, - const char *z, - sql_uint64 n, - void (*xDel) (void *)) -{ - assert(xDel != SQL_DYNAMIC); - if (n > 0x7fffffff) { - (void)invokeValueDestructor(z, xDel, pCtx); - } else { - setResultStrOrError(pCtx, z, (int)n, xDel); - } -} - -void -sql_result_value(sql_context * pCtx, sql_value * pValue) -{ - if (mem_copy(pCtx->pOut, pValue) != 0) - pCtx->is_aborted = true; -} - /* * Execute the statement pStmt, either until a row of data is ready, the * statement is completely executed or an error occurs. @@ -313,23 +184,6 @@ sql_step(sql_stmt * pStmt) return sqlStep(v); } -/* - * Extract the user data from a sql_context structure and return a - * pointer to it. - * - * IMPLEMENTATION-OF: R-46798-50301 The sql_context_db_handle() interface - * returns a copy of the pointer to the database connection (the 1st - * parameter) of the sql_create_function() and - * sql_create_function16() routines that originally registered the - * application defined function. - */ -sql * -sql_context_db_handle(sql_context * p) -{ - assert(p && p->pOut); - return p->pOut->db; -} - /* * Return the number of columns in the result set for the statement pStmt. */ @@ -579,73 +433,6 @@ sql_unbind(struct sql_stmt *stmt) } } -/* - * Bind a text or BLOB value. - */ -static int -bindText(sql_stmt * pStmt, /* The statement to bind against */ - int i, /* Index of the parameter to bind */ - const void *zData, /* Pointer to the data to be bound */ - int nData, /* Number of bytes of data to be bound */ - void (*xDel) (void *) /* Destructor for the data */ - ) -{ - Vdbe *p = (Vdbe *) pStmt; - Mem *pVar; - if (vdbeUnbind(p, i) != 0) { - if (xDel != SQL_STATIC && xDel != SQL_TRANSIENT) - xDel((void *)zData); - return -1; - } - if (zData == NULL) - return 0; - pVar = &p->aVar[i - 1]; - if (xDel != SQL_TRANSIENT) - mem_set_strl(pVar, (char *)zData, nData, xDel); - else if (mem_copy_strl(pVar, zData, nData) != 0) - return -1; - return sql_bind_type(p, i, "text"); -} - -/* - * Bind a blob value to an SQL statement variable. - */ -int -sql_bind_blob(sql_stmt * pStmt, - int i, const void *zData, int nData, void (*xDel) (void *) - ) -{ - struct Vdbe *p = (Vdbe *) pStmt; - if (vdbeUnbind(p, i) != 0) { - if (xDel != SQL_STATIC && xDel != SQL_TRANSIENT) - xDel((void *)zData); - return -1; - } - if (zData == NULL) - return 0; - struct Mem *var = &p->aVar[i - 1]; - if (xDel != SQL_TRANSIENT) - mem_set_binl(var, (char *)zData, nData, xDel); - else if (mem_copy_bin(var, zData, nData) != 0) - return -1; - return sql_bind_type(p, i, "varbinary"); -} - -int -sql_bind_blob64(sql_stmt * pStmt, - int i, - const void *zData, - sql_uint64 nData, void (*xDel) (void *) - ) -{ - assert(xDel != SQL_DYNAMIC); - if (nData > 0x7fffffff) { - return invokeValueDestructor(zData, xDel, 0); - } else { - return sql_bind_blob(pStmt, i, zData, (int)nData, xDel); - } -} - int sql_bind_double(sql_stmt * pStmt, int i, double rValue) { @@ -719,18 +506,19 @@ sql_bind_ptr(struct sql_stmt *stmt, int i, void *ptr) } int -sql_bind_text64(sql_stmt * pStmt, - int i, - const char *zData, - sql_uint64 nData, - void (*xDel) (void *)) -{ - assert(xDel != SQL_DYNAMIC); - if (nData > 0x7fffffff) { - return invokeValueDestructor(zData, xDel, 0); - } else { - return bindText(pStmt, i, zData, (int)nData, xDel); - } +sql_bind_str_static(sql_stmt *stmt, int i, const char *str, uint32_t len) +{ + struct Vdbe *vdbe = (struct Vdbe *)stmt; + mem_set_str_static(&vdbe->aVar[i - 1], (char *)str, len); + return sql_bind_type(vdbe, i, "text"); +} + +int +sql_bind_bin_static(sql_stmt *stmt, int i, const char *str, uint32_t size) +{ + struct Vdbe *vdbe = (struct Vdbe *)stmt; + mem_set_bin_static(&vdbe->aVar[i - 1], (char *)str, size); + return sql_bind_type(vdbe, i, "text"); } int -- 2.25.1