[tarantool-patches] [PATCH 1/8] sql: cleanup code from obsolete macros
Stanislav Zudin
szudin at tarantool.org
Mon Apr 29 20:26:04 MSK 2019
Removes obsolete and not applicable for the project macros.
Part of #3978
---
src/box/sql/cursor.h | 25 -------------
src/box/sql/date.c | 8 ++---
src/box/sql/expr.c | 4 +--
src/box/sql/fault.c | 3 --
src/box/sql/global.c | 6 ----
src/box/sql/random.c | 2 --
src/box/sql/sqlInt.h | 76 +++------------------------------------
src/box/sql/util.c | 86 --------------------------------------------
src/box/sql/vdbe.c | 2 +-
9 files changed, 11 insertions(+), 201 deletions(-)
diff --git a/src/box/sql/cursor.h b/src/box/sql/cursor.h
index 237411613..e5c49d736 100644
--- a/src/box/sql/cursor.h
+++ b/src/box/sql/cursor.h
@@ -101,29 +101,4 @@ int sqlCursorIsValidNN(BtCursor *);
#define CURSOR_INVALID 0
#define CURSOR_VALID 1
-/*
- * Routines to read or write a two- and four-byte big-endian integer values.
- */
-#define get2byte(x) ((x)[0]<<8 | (x)[1])
-#define put2byte(p,v) ((p)[0] = (u8)((v)>>8), (p)[1] = (u8)(v))
-#define get4byte sqlGet4byte
-#define put4byte sqlPut4byte
-
-/*
- * get2byteAligned(), unlike get2byte(), requires that its argument point to a
- * two-byte aligned address. get2bytea() is only used for accessing the
- * cell addresses in a btree header.
- */
-#if SQL_BYTEORDER==4321
-#define get2byteAligned(x) (*(u16*)(x))
-#elif SQL_BYTEORDER==1234 && !defined(SQL_DISABLE_INTRINSIC) \
- && GCC_VERSION>=4008000
-#define get2byteAligned(x) __builtin_bswap16(*(u16*)(x))
-#elif SQL_BYTEORDER==1234 && !defined(SQL_DISABLE_INTRINSIC) \
- && defined(_MSC_VER) && _MSC_VER>=1300
-#define get2byteAligned(x) _byteswap_ushort(*(u16*)(x))
-#else
-#define get2byteAligned(x) ((x)[0]<<8 | (x)[1])
-#endif
-
#endif /* SQL_CURSOR_H */
diff --git a/src/box/sql/date.c b/src/box/sql/date.c
index 07a57ab2a..26afd18d8 100644
--- a/src/box/sql/date.c
+++ b/src/box/sql/date.c
@@ -550,18 +550,18 @@ osLocaltime(time_t * t, struct tm *pTm)
#if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S
struct tm *pX;
pX = localtime(t);
-#ifndef SQL_UNTESTABLE
+
if (sqlGlobalConfig.bLocaltimeFault)
pX = 0;
-#endif
+
if (pX)
*pTm = *pX;
rc = pX == 0;
#else
-#ifndef SQL_UNTESTABLE
+
if (sqlGlobalConfig.bLocaltimeFault)
return 1;
-#endif
+
#if HAVE_LOCALTIME_R
rc = localtime_r(t, pTm) == 0;
#else
diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
index ba7eea59d..00992388c 100644
--- a/src/box/sql/expr.c
+++ b/src/box/sql/expr.c
@@ -3603,7 +3603,7 @@ sqlExprCodeMove(Parse * pParse, int iFrom, int iTo, int nReg)
sqlExprCacheRemove(pParse, iFrom, nReg);
}
-#if defined(SQL_DEBUG) || defined(SQL_COVERAGE_TEST)
+#if defined(SQL_DEBUG)
/*
* Return true if any register in the range iFrom..iTo (inclusive)
* is used as part of the column cache.
@@ -3623,7 +3623,7 @@ usedAsColumnCache(Parse * pParse, int iFrom, int iTo)
}
return 0;
}
-#endif /* SQL_DEBUG || SQL_COVERAGE_TEST */
+#endif /* SQL_DEBUG */
/*
* Convert a scalar expression node to a TK_REGISTER referencing
diff --git a/src/box/sql/fault.c b/src/box/sql/fault.c
index 8ee774e4c..26eeaeedb 100644
--- a/src/box/sql/fault.c
+++ b/src/box/sql/fault.c
@@ -47,8 +47,6 @@
#include "sqlInt.h"
-#ifndef SQL_UNTESTABLE
-
/*
* Global variables.
*/
@@ -104,4 +102,3 @@ sqlEndBenignMalloc(void)
}
}
-#endif /* #ifndef SQL_UNTESTABLE */
diff --git a/src/box/sql/global.c b/src/box/sql/global.c
index 9af671a5e..b6a01731b 100644
--- a/src/box/sql/global.c
+++ b/src/box/sql/global.c
@@ -204,9 +204,7 @@ SQL_WSD struct sqlConfig sqlConfig = {
0, /* xVdbeBranch */
0, /* pVbeBranchArg */
#endif
-#ifndef SQL_UNTESTABLE
0, /* xTestCallback */
-#endif
0, /* bLocaltimeFault */
0x7ffffffe /* iOnceResetThreshold */
};
@@ -246,7 +244,3 @@ int sqlPendingByte = 0x40000000;
*/
const unsigned char sqlOpcodeProperty[] = OPFLG_INITIALIZER;
-/*
- * Name of the default collating sequence
- */
-const char sqlStrBINARY[] = "BINARY";
diff --git a/src/box/sql/random.c b/src/box/sql/random.c
index 9e1122b22..618cb96d6 100644
--- a/src/box/sql/random.c
+++ b/src/box/sql/random.c
@@ -108,7 +108,6 @@ sql_randomness(int N, void *pBuf)
} while (--N);
}
-#ifndef SQL_UNTESTABLE
/*
* For testing purposes, we sometimes want to preserve the state of
* PRNG and restore the PRNG to its saved state at a later time, or
@@ -132,4 +131,3 @@ sqlPrngRestoreState(void)
sizeof(sqlPrng)
);
}
-#endif /* SQL_UNTESTABLE */
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 76ea9fb17..1691d89ca 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -228,19 +228,14 @@
* can insure that all cases are evaluated.
*
*/
-#ifdef SQL_COVERAGE_TEST
-void sqlCoverage(int);
-#define testcase(X) if( X ){ sqlCoverage(__LINE__); }
-#else
#define testcase(X)
-#endif
/*
* The TESTONLY macro is used to enclose variable declarations or
* other bits of code that are needed to support the arguments
* within testcase() and assert() macros.
*/
-#if !defined(NDEBUG) || defined(SQL_COVERAGE_TEST)
+#if !defined(NDEBUG)
#define TESTONLY(X) X
#else
#define TESTONLY(X)
@@ -270,15 +265,8 @@ void sqlCoverage(int);
* hint of unplanned behavior.
*
* In other words, ALWAYS and NEVER are added for defensive code.
- *
- * When doing coverage testing ALWAYS and NEVER are hard-coded to
- * be true and false so that the unreachable code they specify will
- * not be counted as untested code.
*/
-#if defined(SQL_COVERAGE_TEST) || defined(SQL_MUTATION_TEST)
-#define ALWAYS(X) (1)
-#define NEVER(X) (0)
-#elif !defined(NDEBUG)
+#if !defined(NDEBUG)
#define ALWAYS(X) ((X)?1:(assert(0),0))
#define NEVER(X) ((X)?(assert(0),1):0)
#else
@@ -1163,41 +1151,6 @@ typedef u64 uptr;
*/
#define SQL_WITHIN(P,S,E) (((uptr)(P)>=(uptr)(S))&&((uptr)(P)<(uptr)(E)))
-/*
- * Macros to determine whether the machine is big or little endian,
- * and whether or not that determination is run-time or compile-time.
- *
- * For best performance, an attempt is made to guess at the byte-order
- * using C-preprocessor macros. If that is unsuccessful, or if
- * -Dsql_RUNTIME_BYTEORDER=1 is set, then byte-order is determined
- * at run-time.
- */
-#if (defined(i386) || defined(__i386__) || defined(_M_IX86) || \
- defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
- defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \
- defined(__arm__)) && !defined(SQL_RUNTIME_BYTEORDER)
-#define SQL_BYTEORDER 1234
-#define SQL_BIGENDIAN 0
-#define SQL_LITTLEENDIAN 1
-#endif
-#if (defined(sparc) || defined(__ppc__)) \
- && !defined(SQL_RUNTIME_BYTEORDER)
-#define SQL_BYTEORDER 4321
-#define SQL_BIGENDIAN 1
-#define SQL_LITTLEENDIAN 0
-#endif
-#if !defined(SQL_BYTEORDER)
-#ifdef SQL_AMALGAMATION
-const int sqlone = 1;
-#else
-extern const int sqlone;
-#endif
-#define SQL_BYTEORDER 0 /* 0 means "unknown at compile-time" */
-#define SQL_BIGENDIAN (*(char *)(&sqlone)==0)
-#define SQL_LITTLEENDIAN (*(char *)(&sqlone)==1)
-#define SQL_UTF16NATIVE (SQL_BIGENDIAN?SQL_UTF16BE:SQL_UTF16LE)
-#endif
-
/*
* Constants for the largest and smallest possible 64-bit signed integers.
* These macros are designed to work correctly on both 32-bit and 64-bit
@@ -2910,9 +2863,7 @@ 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 */
};
@@ -3032,9 +2983,7 @@ void sqlScratchFree(void *);
void *sqlPageMalloc(int);
void sqlPageFree(void *);
void sqlMemSetDefault(void);
-#ifndef SQL_UNTESTABLE
void sqlBenignMallocHooks(void (*)(void), void (*)(void));
-#endif
int sqlHeapNearlyFull(void);
/*
@@ -3371,11 +3320,7 @@ 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.
@@ -3677,10 +3622,8 @@ void sqlExprAnalyzeAggregates(NameContext *, Expr *);
void sqlExprAnalyzeAggList(NameContext *, ExprList *);
int sqlFunctionUsesThisSrc(Expr *, SrcList *);
Vdbe *sqlGetVdbe(Parse *);
-#ifndef SQL_UNTESTABLE
void sqlPrngSaveState(void);
void sqlPrngRestoreState(void);
-#endif
void sqlRollbackAll(Vdbe *);
/**
@@ -4493,16 +4436,14 @@ sql_value *sqlValueNew(sql *);
int sqlValueFromExpr(sql *, Expr *, enum field_type type,
sql_value **);
void sql_value_apply_type(sql_value *val, enum field_type type);
-#ifndef SQL_AMALGAMATION
+
extern const unsigned char sqlOpcodeProperty[];
-extern const char sqlStrBINARY[];
extern const unsigned char sqlUpperToLower[];
extern const unsigned char sqlCtypeMap[];
extern const Token sqlIntTokens[];
extern SQL_WSD struct sqlConfig sqlConfig;
extern FuncDefHash sqlBuiltinFunctions;
extern int sqlPendingByte;
-#endif
/**
* Generate code to implement the "ALTER TABLE xxx RENAME TO yyy"
@@ -4887,16 +4828,10 @@ fk_constraint_is_required(struct space *space, const int *changes);
/*
* The interface to the code in fault.c used for identifying "benign"
- * malloc failures. This is only present if sql_UNTESTABLE
- * is not defined.
+ * malloc failures.
*/
-#ifndef SQL_UNTESTABLE
void sqlBeginBenignMalloc(void);
void sqlEndBenignMalloc(void);
-#else
-#define sqlBeginBenignMalloc()
-#define sqlEndBenignMalloc()
-#endif
/*
* Allowed return values from sqlFindInIndex()
@@ -4922,9 +4857,6 @@ int sqlExprCheckHeight(Parse *, int);
#define sqlExprCheckHeight(x,y)
#endif
-u32 sqlGet4byte(const u8 *);
-void sqlPut4byte(u8 *, u32);
-
#ifdef SQL_DEBUG
void sqlParserTrace(FILE *, char *);
#endif
diff --git a/src/box/sql/util.c b/src/box/sql/util.c
index d5c93f8aa..4a93ddf09 100644
--- a/src/box/sql/util.c
+++ b/src/box/sql/util.c
@@ -38,25 +38,11 @@
*/
#include "sqlInt.h"
#include <stdarg.h>
-#if HAVE_ISNAN || SQL_HAVE_ISNAN
#include <math.h>
-#endif
#include "coll/coll.h"
#include <unicode/ucasemap.h>
#include "errinj.h"
-/*
- * Routine needed to support the testcase() macro.
- */
-#ifdef SQL_COVERAGE_TEST
-void
-sqlCoverage(int x)
-{
- static unsigned dummy = 0;
- dummy += (unsigned)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
@@ -68,14 +54,12 @@ sqlCoverage(int x)
* 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).
@@ -87,30 +71,7 @@ int
sqlIsNaN(double x)
{
int rc; /* The value return */
-#if !SQL_HAVE_ISNAN && !HAVE_ISNAN
- /*
- * Systems that support the isnan() library function should probably
- * make use
- *
- * This NaN test sometimes fails if compiled on GCC with -ffast-math.
- * On the other hand, the use of -ffast-math comes with the following
- * warning:
- *
- * This option [-ffast-math] should never be turned on by any
- * -O option since it can result in incorrect output for programs
- * which depend on an exact implementation of IEEE or ISO
- * rules/specifications for math functions.
- */
-#ifdef __FAST_MATH__
-#error sql will not work correctly with the -ffast-math option of GCC.
-#endif
- volatile double y = x;
- volatile double z = y;
- rc = (y != z);
-#else /* if HAVE_ISNAN */
rc = isnan(x);
-#endif /* HAVE_ISNAN */
- testcase(rc);
return rc;
}
@@ -1123,53 +1084,6 @@ sqlVarintLen(u64 v)
return i;
}
-/*
- * Read or write a four-byte big-endian integer value.
- */
-u32
-sqlGet4byte(const u8 * p)
-{
-#if SQL_BYTEORDER==4321
- u32 x;
- memcpy(&x, p, 4);
- return x;
-#elif SQL_BYTEORDER==1234 && !defined(SQL_DISABLE_INTRINSIC) \
- && defined(__GNUC__) && GCC_VERSION>=4003000
- u32 x;
- memcpy(&x, p, 4);
- return __builtin_bswap32(x);
-#elif SQL_BYTEORDER==1234 && !defined(SQL_DISABLE_INTRINSIC) \
- && defined(_MSC_VER) && _MSC_VER>=1300
- u32 x;
- memcpy(&x, p, 4);
- return _byteswap_ulong(x);
-#else
- testcase(p[0] & 0x80);
- return ((unsigned)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
-#endif
-}
-
-void
-sqlPut4byte(unsigned char *p, u32 v)
-{
-#if SQL_BYTEORDER==4321
- memcpy(p, &v, 4);
-#elif SQL_BYTEORDER==1234 && !defined(SQL_DISABLE_INTRINSIC) \
- && defined(__GNUC__) && GCC_VERSION>=4003000
- u32 x = __builtin_bswap32(v);
- memcpy(p, &x, 4);
-#elif SQL_BYTEORDER==1234 && !defined(SQL_DISABLE_INTRINSIC) \
- && defined(_MSC_VER) && _MSC_VER>=1300
- u32 x = _byteswap_ulong(v);
- memcpy(p, &x, 4);
-#else
- p[0] = (u8) (v >> 24);
- p[1] = (u8) (v >> 16);
- p[2] = (u8) (v >> 8);
- p[3] = (u8) v;
-#endif
-}
-
/*
* Translate a single byte of Hex into an integer.
* This routine only works if h really is a valid hexadecimal
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 3bd82234e..ce609a578 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -147,7 +147,7 @@ int sql_found_count = 0;
* Test a register to see if it exceeds the current maximum blob size.
* If it does, record the new maximum blob size.
*/
-#if defined(SQL_TEST) && !defined(SQL_UNTESTABLE)
+#if defined(SQL_TEST)
# define UPDATE_MAX_BLOBSIZE(P) updateMaxBlobsize(P)
#else
# define UPDATE_MAX_BLOBSIZE(P)
--
2.17.1
More information about the Tarantool-patches
mailing list