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 C95522E6C5 for ; Mon, 10 Jun 2019 09:56:34 -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 iQ6aigbkpN3E for ; Mon, 10 Jun 2019 09:56:34 -0400 (EDT) Received: from smtp39.i.mail.ru (smtp39.i.mail.ru [94.100.177.99]) (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 624AE2E6AA for ; Mon, 10 Jun 2019 09:56:34 -0400 (EDT) From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v1 05/28] sql: remove unused functions of SQL error system Date: Mon, 10 Jun 2019 16:56:32 +0300 Message-Id: <06d524d0b75c16a201616dfd9ab10080e1c03930.1560174553.git.imeevma@gmail.com> In-Reply-To: References: 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: v.shpilevoy@tarantool.org Cc: tarantool-patches@freelists.org These functions are not currently used and should be removed. --- src/box/sql.c | 7 ---- src/box/sql/global.c | 3 -- src/box/sql/legacy.c | 3 +- src/box/sql/main.c | 34 ------------------- src/box/sql/prepare.c | 4 +-- src/box/sql/sqlInt.h | 13 -------- src/box/sql/tarantoolInt.h | 3 -- src/box/sql/util.c | 81 ---------------------------------------------- src/box/sql/vdbeapi.c | 40 ++--------------------- src/box/sql/vdbesort.c | 11 ++----- 10 files changed, 8 insertions(+), 191 deletions(-) diff --git a/src/box/sql.c b/src/box/sql.c index f2ef5b3..ae92ba0 100644 --- a/src/box/sql.c +++ b/src/box/sql.c @@ -155,13 +155,6 @@ cursor_seek(BtCursor *pCur, int *pRes); static int cursor_advance(BtCursor *pCur, int *pRes); -const char *tarantoolErrorMessage() -{ - if (diag_is_empty(&fiber()->diag)) - return NULL; - return box_error_message(box_error_last()); -} - const void *tarantoolsqlPayloadFetch(BtCursor *pCur, u32 *pAmt) { assert(pCur->curFlags & BTCF_TaCursor || diff --git a/src/box/sql/global.c b/src/box/sql/global.c index 9af671a..e394db8 100644 --- a/src/box/sql/global.c +++ b/src/box/sql/global.c @@ -204,9 +204,6 @@ SQL_WSD struct sqlConfig sqlConfig = { 0, /* xVdbeBranch */ 0, /* pVbeBranchArg */ #endif -#ifndef SQL_UNTESTABLE - 0, /* xTestCallback */ -#endif 0, /* bLocaltimeFault */ 0x7ffffffe /* iOnceResetThreshold */ }; diff --git a/src/box/sql/legacy.c b/src/box/sql/legacy.c index d519991..1a3804e 100644 --- a/src/box/sql/legacy.c +++ b/src/box/sql/legacy.c @@ -64,8 +64,7 @@ sql_exec(sql * db, /* The database on which the SQL executes */ char **azCols = 0; /* Names of result columns */ int callbackIsInit; /* True if callback data is initialized */ - if (!sqlSafetyCheckOk(db)) - return SQL_MISUSE; + assert(db != NULL); if (zSql == 0) zSql = ""; diff --git a/src/box/sql/main.c b/src/box/sql/main.c index f35c84f..450f7d1 100644 --- a/src/box/sql/main.c +++ b/src/box/sql/main.c @@ -302,40 +302,6 @@ sqlRollbackAll(Vdbe * pVdbe) } /* - * Return a static string that describes the kind of error specified in the - * argument. - */ -const char * -sqlErrStr(int rc) -{ - static const char *const aMsg[] = { - /* SQL_OK */ "not an error", - /* SQL_ERROR */ "SQL logic error or missing database", - /* SQL_PERM */ "access permission denied", - /* SQL_ABORT */ "callback requested query abort", - /* SQL_BUSY */ "database is locked", - /* SQL_LOCKED */ "database table is locked", - /* SQL_NOMEM */ "out of memory", - /* SQL_IOERR */ "disk I/O error", - /* SQL_NOTFOUND */ "unknown operation", - /* SQL_FULL */ "database or disk is full", - /* SQL_CANTOPEN */ "unable to open database file", - /* SQL_SCHEMA */ "database schema has changed", - /* SQL_TOOBIG */ "string or blob too big", - /* SQL_CONSTRAINT */ "constraint failed", - /* SQL_MISUSE */ - "library routine called out of sequence", - /* SQL_RANGE */ "bind or column index out of range", - /* SQL_TARANTOOL_ERROR */ "SQL-/Tarantool error", - }; - const char *zErr = "unknown error"; - rc &= 0xff; - if (ALWAYS(rc >= 0) && rc < ArraySize(aMsg) && aMsg[rc] != 0) - zErr = aMsg[rc]; - return zErr; -} - -/* * This function is exactly the same as sql_create_function(), except * that it is designed to be called by internal code. The difference is * that if a malloc() fails in sql_create_function(), an error code diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c index e692be0..2b3ac29 100644 --- a/src/box/sql/prepare.c +++ b/src/box/sql/prepare.c @@ -193,9 +193,7 @@ sqlLockAndPrepare(sql * db, /* Database handle. */ int rc; *ppStmt = 0; - if (!sqlSafetyCheckOk(db) || zSql == 0) { - return SQL_MISUSE; - } + assert(zSql != NULL && db != NULL); rc = sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail); if (rc == SQL_SCHEMA) { diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 2b7aa8b..7c00990 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -2908,9 +2908,6 @@ struct sqlConfig { void (*xVdbeBranch) (void *, int iSrcLine, u8 eThis, u8 eMx); /* Callback */ void *pVdbeBranchArg; /* 1st argument */ #endif -#ifndef SQL_UNTESTABLE - int (*xTestCallback) (int); /* Invoked by sqlFaultSim() */ -#endif int bLocaltimeFault; /* True to fail localtime() calls */ int iOnceResetThreshold; /* When to reset OP_Once counters */ }; @@ -3369,12 +3366,6 @@ int vdbe_emit_open_cursor(struct Parse *parse, int cursor, int index_id, struct space *space); -#ifdef SQL_UNTESTABLE -#define sqlFaultSim(X) SQL_OK -#else -int sqlFaultSim(int); -#endif - /** * The parser calls this routine in order to create a new VIEW. * @@ -3936,8 +3927,6 @@ FuncDef *sqlFindFunction(sql *, const char *, int, u8); void sqlRegisterBuiltinFunctions(void); void sqlRegisterDateTimeFunctions(void); void sqlRegisterPerConnectionBuiltinFunctions(sql *); -int sqlSafetyCheckOk(sql *); -int sqlSafetyCheckSickOrOk(sql *); /** * Evaluate a view and store its result in an ephemeral table. @@ -4460,8 +4449,6 @@ sql_dec_or_hex_to_i64(const char *z, int64_t *val); void *sqlHexToBlob(sql *, const char *z, int n); u8 sqlHexToInt(int h); -const char *sqlErrStr(int); - /** * Return the collation sequence for the expression pExpr. If * there is no defined collating sequence, return NULL. diff --git a/src/box/sql/tarantoolInt.h b/src/box/sql/tarantoolInt.h index f688a02..375a8cc 100644 --- a/src/box/sql/tarantoolInt.h +++ b/src/box/sql/tarantoolInt.h @@ -10,9 +10,6 @@ struct fk_constraint_def; -/* Misc */ -const char *tarantoolErrorMessage(); - /* Storage interface. */ const void *tarantoolsqlPayloadFetch(BtCursor * pCur, u32 * pAmt); diff --git a/src/box/sql/util.c b/src/box/sql/util.c index d5f6447..713e535 100644 --- a/src/box/sql/util.c +++ b/src/box/sql/util.c @@ -58,26 +58,6 @@ sqlCoverage(int x) #endif /* - * Give a callback to the test harness that can be used to simulate faults - * in places where it is difficult or expensive to do so purely by means - * of inputs. - * - * The intent of the integer argument is to let the fault simulator know - * which of multiple sqlFaultSim() calls has been hit. - * - * Return whatever integer value the test callback returns, or return - * SQL_OK if no test callback is installed. - */ -#ifndef SQL_UNTESTABLE -int - sqlFaultSim(int iTest) -{ - int (*xCallback) (int) = sqlGlobalConfig.xTestCallback; - return xCallback ? xCallback(iTest) : SQL_OK; -} -#endif - -/* * Return true if the floating point value is Not a Number (NaN). * * Use the math library isnan() function if compiled with SQL_HAVE_ISNAN. @@ -1131,67 +1111,6 @@ sqlHexToBlob(sql * db, const char *z, int n) #endif /* !SQL_OMIT_BLOB_LITERAL || SQL_HAS_CODEC */ /* - * Log an error that is an API call on a connection pointer that should - * not have been used. The "type" of connection pointer is given as the - * argument. The zType is a word like "NULL" or "closed" or "invalid". - */ -static void -logBadConnection(const char *zType) -{ - sql_log(SQL_MISUSE, - "API call with %s database connection pointer", zType); -} - -/* - * Check to make sure we have a valid db pointer. This test is not - * foolproof but it does provide some measure of protection against - * misuse of the interface such as passing in db pointers that are - * NULL or which have been previously closed. If this routine returns - * 1 it means that the db pointer is valid and 0 if it should not be - * dereferenced for any reason. The calling function should invoke - * SQL_MISUSE immediately. - * - * sqlSafetyCheckOk() requires that the db pointer be valid for - * use. sqlSafetyCheckSickOrOk() allows a db pointer that failed to - * open properly and is not fit for general use but which can be - * used as an argument to sql_errmsg() or sql_close(). - */ -int -sqlSafetyCheckOk(sql * db) -{ - u32 magic; - if (db == 0) { - logBadConnection("NULL"); - return 0; - } - magic = db->magic; - if (magic != SQL_MAGIC_OPEN) { - if (sqlSafetyCheckSickOrOk(db)) { - testcase(sqlGlobalConfig.xLog != 0); - logBadConnection("unopened"); - } - return 0; - } else { - return 1; - } -} - -int -sqlSafetyCheckSickOrOk(sql * db) -{ - u32 magic; - magic = db->magic; - if (magic != SQL_MAGIC_SICK && - magic != SQL_MAGIC_OPEN && magic != SQL_MAGIC_BUSY) { - testcase(sqlGlobalConfig.xLog != 0); - logBadConnection("invalid"); - return 0; - } else { - return 1; - } -} - -/* * Attempt to add, substract, or multiply the 64-bit signed value iB against * the other 64-bit signed integer at *pA and store the result in *pA. * Return 0 on success. Or if the operation would have resulted in an diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index c151a52..d52fc21 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -37,35 +37,6 @@ #include "sqlInt.h" #include "vdbeInt.h" -/* - * Check on a Vdbe to make sure it has not been finalized. Log - * an error and return true if it has been finalized (or is otherwise - * invalid). Return false if it is ok. - */ -static int -vdbeSafety(Vdbe * p) -{ - if (p->db == 0) { - sql_log(SQL_MISUSE, - "API called with finalized prepared statement"); - return 1; - } else { - return 0; - } -} - -static int -vdbeSafetyNotNull(Vdbe * p) -{ - if (p == 0) { - sql_log(SQL_MISUSE, - "API called with NULL prepared statement"); - return 1; - } else { - return vdbeSafety(p); - } -} - #ifndef SQL_OMIT_TRACE /* * Invoke the profile callback. This routine is only called if we already @@ -120,8 +91,7 @@ sql_finalize(sql_stmt * pStmt) } else { Vdbe *v = (Vdbe *) pStmt; sql *db = v->db; - if (vdbeSafety(v)) - return SQL_MISUSE; + assert(db != NULL); checkProfileCallback(db, v); rc = sqlVdbeFinalize(v); rc = sqlApiExit(db, rc); @@ -541,9 +511,7 @@ sql_step(sql_stmt * pStmt) Vdbe *v = (Vdbe *) pStmt; /* the prepared statement */ int cnt = 0; /* Counter to prevent infinite loop of reprepares */ - if (vdbeSafetyNotNull(v)) { - return SQL_MISUSE; - } + assert(v != NULL); v->doingRerun = 0; while ((rc = sqlStep(v)) == SQL_SCHEMA && cnt++ < SQL_MAX_SCHEMA_RETRY) { @@ -1022,9 +990,7 @@ static int vdbeUnbind(Vdbe * p, int i) { Mem *pVar; - if (vdbeSafetyNotNull(p)) { - return SQL_MISUSE; - } + assert(p != NULL); if (p->magic != VDBE_MAGIC_RUN || p->pc >= 0) { sql_log(SQL_MISUSE, "bind on a busy prepared statement: [%s]", p->zSql); diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c index 779e832..da9ee3e 100644 --- a/src/box/sql/vdbesort.c +++ b/src/box/sql/vdbesort.c @@ -679,8 +679,6 @@ vdbePmaReaderSeek(SortSubtask * pTask, /* Task context */ assert(pReadr->pIncr == 0 || pReadr->pIncr->bEof == 0); - if (sqlFaultSim(201)) - return SQL_IOERR_READ; if (pReadr->aMap) { sqlOsUnfetch(pReadr->pFd, 0, pReadr->aMap); pReadr->aMap = 0; @@ -1105,8 +1103,7 @@ vdbeMergeEngineNew(int nReader) N += N; nByte = sizeof(MergeEngine) + N * (sizeof(int) + sizeof(PmaReader)); - pNew = - sqlFaultSim(100) ? 0 : (MergeEngine *) sqlMallocZero(nByte); + pNew = (MergeEngine *) sqlMallocZero(nByte); if (pNew) { pNew->nTree = N; pNew->pTask = 0; @@ -1243,8 +1240,6 @@ vdbeSorterOpenTempFile(sql * db, /* Database handle doing sort */ sql_file ** ppFd) { int rc; - if (sqlFaultSim(202)) - return SQL_IOERR_ACCESS; rc = sqlOsOpenMalloc(db->pVfs, 0, ppFd, SQL_OPEN_READWRITE | SQL_OPEN_CREATE | SQL_OPEN_EXCLUSIVE | @@ -2001,8 +1996,8 @@ vdbeIncrMergerNew(SortSubtask * pTask, /* The thread that will be using the new ) { int rc = SQL_OK; - IncrMerger *pIncr = *ppOut = (IncrMerger *) - (sqlFaultSim(100) ? 0 : sqlMallocZero(sizeof(*pIncr))); + IncrMerger *pIncr = *ppOut = + (IncrMerger *) sqlMallocZero(sizeof(*pIncr)); if (pIncr) { pIncr->pMerger = pMerger; pIncr->pTask = pTask; -- 2.7.4