[Tarantool-patches] [PATCH v4 06/53] sql: remove unused MEM-related functions

imeevma at tarantool.org imeevma at tarantool.org
Tue Mar 23 12:35:00 MSK 2021


This patch removes remove unused MEM-related functions.

Part of #5818
---
 src/box/sql/sqlInt.h  |  4 ---
 src/box/sql/vdbe.c    |  8 ------
 src/box/sql/vdbeInt.h |  2 --
 src/box/sql/vdbeapi.c | 62 -----------------------------------------
 src/box/sql/vdbemem.c | 65 -------------------------------------------
 5 files changed, 141 deletions(-)

diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index c1a42fc2f..dd8163f5e 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -474,10 +474,6 @@ sql_column_text(sql_stmt *,
 enum mp_type
 sql_column_type(sql_stmt *stmt, int field_no);
 
-sql_value *
-sql_column_value(sql_stmt *,
-		     int iCol);
-
 /*
  * Terminate the current execution of an SQL statement and reset
  * it back to its starting state so that it can be reused.
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 21abdcbd5..dbbcc1013 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -166,14 +166,6 @@ vdbeTakeBranch(int iSrcLine, u8 I, u8 M)
 }
 #endif
 
-/*
- * Convert the given register into a string if it isn't one
- * already. Return non-zero if a malloc() fails.
- */
-#define Stringify(P)						\
-	if(((P)->flags&(MEM_Str|MEM_Blob))==0 && sqlVdbeMemStringify(P)) \
-	{ goto no_mem; }
-
 /*
  * An ephemeral string value (signified by the MEM_Ephem flag) contains
  * a pointer to a dynamically allocated string where some other entity
diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index 089ac7575..e619f6e59 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -333,8 +333,6 @@ int sqlVdbeList(Vdbe *);
 
 int sqlVdbeHalt(Vdbe *);
 
-int sqlVdbeMemFromBtree(BtCursor *, u32, u32, Mem *);
-
 /**
  * In terms of VDBE memory cell type, _BIN, _ARRAY and _MAP
  * messagepacks are stored as binary string (i.e. featuring
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 24fa99f17..671338361 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -101,63 +101,12 @@ sql_stmt_reset(sql_stmt *pStmt)
 	return rc;
 }
 
-/*
- * Set all the parameters in the compiled SQL statement to NULL.
- */
-int
-sql_clear_bindings(sql_stmt * pStmt)
-{
-	int i;
-	int rc = 0;
-	Vdbe *p = (Vdbe *) pStmt;
-	for (i = 0; i < p->nVar; i++) {
-		sqlVdbeMemRelease(&p->aVar[i]);
-		p->aVar[i].flags = MEM_Null;
-	}
-	return rc;
-}
-
 bool
 sql_metadata_is_full()
 {
 	return current_session()->sql_flags & SQL_FullMetadata;
 }
 
-/* Make a copy of an sql_value object
- */
-sql_value *
-sql_value_dup(const sql_value * pOrig)
-{
-	sql_value *pNew;
-	if (pOrig == 0)
-		return 0;
-	pNew = sql_malloc(sizeof(*pNew));
-	if (pNew == 0)
-		return 0;
-	memset(pNew, 0, sizeof(*pNew));
-	memcpy(pNew, pOrig, MEMCELLSIZE);
-	pNew->flags &= ~MEM_Dyn;
-	pNew->db = 0;
-	if (pNew->flags & (MEM_Str | MEM_Blob)) {
-		pNew->flags &= ~(MEM_Static | MEM_Dyn);
-		pNew->flags |= MEM_Ephem;
-		if (sqlVdbeMemMakeWriteable(pNew) != 0) {
-			sqlValueFree(pNew);
-			pNew = 0;
-		}
-	}
-	return pNew;
-}
-
-/* Destroy an sql_value object previously obtained from
- * sql_value_dup().
- */
-void
-sql_value_free(sql_value * pOld)
-{
-	sqlValueFree(pOld);
-}
-
 /**************************** sql_result_  ******************************
  * The following routines are used by user-defined functions to specify
  * the function result.
@@ -566,17 +515,6 @@ sql_column_text(sql_stmt * pStmt, int i)
 	return sql_value_text(columnMem(pStmt, i));
 }
 
-sql_value *
-sql_column_value(sql_stmt * pStmt, int i)
-{
-	Mem *pOut = columnMem(pStmt, i);
-	if (pOut->flags & MEM_Static) {
-		pOut->flags &= ~MEM_Static;
-		pOut->flags |= MEM_Ephem;
-	}
-	return (sql_value *) pOut;
-}
-
 enum mp_type
 sql_column_type(sql_stmt * pStmt, int i)
 {
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index d1a9f7e06..85d620a0a 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -44,71 +44,6 @@
 #include "box/tuple.h"
 #include "mpstream/mpstream.h"
 
-/*
- * Move data out of a btree key or data field and into a Mem structure.
- * The data is payload from the entry that pCur is currently pointing
- * to.  offset and amt determine what portion of the data or key to retrieve.
- * The result is written into the pMem element.
- *
- * The pMem object must have been initialized.  This routine will use
- * pMem->zMalloc to hold the content from the btree, if possible.  New
- * pMem->zMalloc space will be allocated if necessary.  The calling routine
- * is responsible for making sure that the pMem object is eventually
- * destroyed.
- *
- * If this routine fails for any reason (malloc returns NULL or unable
- * to read from the disk) then the pMem is left in an inconsistent state.
- */
-static SQL_NOINLINE int
-vdbeMemFromBtreeResize(BtCursor * pCur,	/* Cursor pointing at record to retrieve. */
-		       u32 offset,	/* Offset from the start of data to return bytes from. */
-		       u32 amt,	/* Number of bytes to return. */
-		       Mem * pMem	/* OUT: Return data in this Mem structure. */
-    )
-{
-	int rc;
-	pMem->flags = MEM_Null;
-	if (0 == (rc = sqlVdbeMemClearAndResize(pMem, amt + 2))) {
-		sqlCursorPayload(pCur, offset, amt, pMem->z);
-		pMem->z[amt] = 0;
-		pMem->z[amt + 1] = 0;
-		pMem->flags = MEM_Blob | MEM_Term;
-		pMem->n = (int) amt;
-	}
-	return rc;
-}
-
-int
-sqlVdbeMemFromBtree(BtCursor * pCur,	/* Cursor pointing at record to retrieve. */
-			u32 offset,	/* Offset from the start of data to return bytes from. */
-			u32 amt,	/* Number of bytes to return. */
-			Mem * pMem	/* OUT: Return data in this Mem structure. */
-    )
-{
-	char *zData;		/* Data from the btree layer */
-	u32 available = 0;	/* Number of bytes available on the local btree page */
-	int rc = 0;	/* Return code */
-
-	assert(sqlCursorIsValid(pCur));
-	assert(!VdbeMemDynamic(pMem));
-	assert(pCur->curFlags & BTCF_TaCursor ||
-	       pCur->curFlags & BTCF_TEphemCursor);
-
-
-	zData = (char *)tarantoolsqlPayloadFetch(pCur, &available);
-	assert(zData != 0);
-
-	if (offset + amt <= available) {
-		pMem->z = &zData[offset];
-		pMem->flags = MEM_Blob | MEM_Ephem;
-		pMem->n = (int)amt;
-	} else {
-		rc = vdbeMemFromBtreeResize(pCur, offset, amt, pMem);
-	}
-
-	return rc;
-}
-
 /*
  * Context object passed by sqlStat4ProbeSetValue() through to
  * valueNew(). See comments above valueNew() for details.
-- 
2.25.1



More information about the Tarantool-patches mailing list