mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-12 13:01:09 +03:00
Merge the latest trunk enhancements into the wal-shm-exceptions branch.
FossilOrigin-Name: f655d08d019bab0c578886e91ca24fd956d1b3dea9b9c9104812b3cf62e5e556
This commit is contained in:
@@ -5341,6 +5341,7 @@ static int moveToChild(BtCursor *pCur, u32 newPgno){
|
||||
pCur->ix = 0;
|
||||
pCur->iPage++;
|
||||
rc = getAndInitPage(pCur->pBt, newPgno, &pCur->pPage, pCur->curPagerFlags);
|
||||
assert( pCur->pPage!=0 || rc!=SQLITE_OK );
|
||||
if( rc==SQLITE_OK
|
||||
&& (pCur->pPage->nCell<1 || pCur->pPage->intKey!=pCur->curIntKey)
|
||||
){
|
||||
@@ -5569,7 +5570,7 @@ int sqlite3BtreeFirst(BtCursor *pCur, int *pRes){
|
||||
*pRes = 0;
|
||||
rc = moveToLeftmost(pCur);
|
||||
}else if( rc==SQLITE_EMPTY ){
|
||||
assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
|
||||
assert( pCur->pgnoRoot==0 || (pCur->pPage!=0 && pCur->pPage->nCell==0) );
|
||||
*pRes = 1;
|
||||
rc = SQLITE_OK;
|
||||
}
|
||||
|
||||
25
src/func.c
25
src/func.c
@@ -1704,11 +1704,14 @@ static void kahanBabuskaNeumaierStep(
|
||||
** Add a (possibly large) integer to the running sum.
|
||||
*/
|
||||
static void kahanBabuskaNeumaierStepInt64(volatile SumCtx *pSum, i64 iVal){
|
||||
volatile double rVal = (double)iVal;
|
||||
kahanBabuskaNeumaierStep(pSum, rVal);
|
||||
if( iVal<=-4503599627370496 || iVal>=+4503599627370496 ){
|
||||
double rDiff = (double)(iVal - (i64)rVal);
|
||||
kahanBabuskaNeumaierStep(pSum, rDiff);
|
||||
if( iVal<=-4503599627370496LL || iVal>=+4503599627370496LL ){
|
||||
i64 iBig, iSm;
|
||||
iSm = iVal % 16384;
|
||||
iBig = iVal - iSm;
|
||||
kahanBabuskaNeumaierStep(pSum, iBig);
|
||||
kahanBabuskaNeumaierStep(pSum, iSm);
|
||||
}else{
|
||||
kahanBabuskaNeumaierStep(pSum, (double)iVal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1716,11 +1719,17 @@ static void kahanBabuskaNeumaierStepInt64(volatile SumCtx *pSum, i64 iVal){
|
||||
** Initialize the Kahan-Babaska-Neumaier sum from a 64-bit integer
|
||||
*/
|
||||
static void kahanBabuskaNeumaierInit(
|
||||
volatile SumCtx *pSum,
|
||||
volatile SumCtx *p,
|
||||
i64 iVal
|
||||
){
|
||||
pSum->rSum = (double)iVal;
|
||||
pSum->rErr = (double)(iVal - (i64)pSum->rSum);
|
||||
if( iVal<=-4503599627370496LL || iVal>=+4503599627370496LL ){
|
||||
i64 iSm = iVal % 16384;
|
||||
p->rSum = (double)(iVal - iSm);
|
||||
p->rErr = (double)iSm;
|
||||
}else{
|
||||
p->rSum = (double)iVal;
|
||||
p->rErr = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -243,7 +243,7 @@ SQLITE_WSD struct Sqlite3Config sqlite3Config = {
|
||||
SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */
|
||||
0, /* bSmallMalloc */
|
||||
1, /* bExtraSchemaChecks */
|
||||
sizeof(long double)>8, /* bUseLongDouble */
|
||||
sizeof(LONGDOUBLE_TYPE)>8, /* bUseLongDouble */
|
||||
0x7ffffffe, /* mxStrlen */
|
||||
0, /* neverCorrupt */
|
||||
SQLITE_DEFAULT_LOOKASIDE, /* szLookaside, nLookaside */
|
||||
|
||||
@@ -4472,11 +4472,14 @@ int sqlite3_test_control(int op, ...){
|
||||
|
||||
/* sqlite3_test_control(SQLITE_TESTCTRL_USELONGDOUBLE, int X);
|
||||
**
|
||||
** Enable long double usage if X>0. Disable if X==0. No-op if X<0.
|
||||
** Return the status of long double usage afterwards.
|
||||
** X<0 Make no changes to the bUseLongDouble. Just report value.
|
||||
** X==0 Disable bUseLongDouble
|
||||
** X==1 Enable bUseLongDouble
|
||||
** X==2 Set bUseLongDouble to its default value for this platform
|
||||
*/
|
||||
case SQLITE_TESTCTRL_USELONGDOUBLE: {
|
||||
int b = va_arg(ap, int);
|
||||
if( b==2 ) b = sizeof(LONGDOUBLE_TYPE)>8;
|
||||
if( b>=0 ) sqlite3Config.bUseLongDouble = b>0;
|
||||
rc = sqlite3Config.bUseLongDouble!=0;
|
||||
break;
|
||||
|
||||
@@ -10876,7 +10876,7 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
{"seek_count", SQLITE_TESTCTRL_SEEK_COUNT, 0, "" },
|
||||
{"sorter_mmap", SQLITE_TESTCTRL_SORTER_MMAP, 0, "NMAX" },
|
||||
{"tune", SQLITE_TESTCTRL_TUNE, 1, "ID VALUE" },
|
||||
{"uselongdouble", SQLITE_TESTCTRL_USELONGDOUBLE,0,"BOOLEAN" },
|
||||
{"uselongdouble", SQLITE_TESTCTRL_USELONGDOUBLE,0,"?BOOLEAN|\"default\"?"},
|
||||
};
|
||||
int testctrl = -1;
|
||||
int iCtrl = -1;
|
||||
@@ -11000,7 +11000,14 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
|
||||
/* sqlite3_test_control(int, int) */
|
||||
case SQLITE_TESTCTRL_USELONGDOUBLE: {
|
||||
int opt = nArg==3 ? booleanValue(azArg[2]) : -1;
|
||||
int opt = -1;
|
||||
if( nArg==3 ){
|
||||
if( cli_strcmp(azArg[2],"default")==0 ){
|
||||
opt = 2;
|
||||
}else{
|
||||
opt = booleanValue(azArg[2]);
|
||||
}
|
||||
}
|
||||
rc2 = sqlite3_test_control(testctrl, opt);
|
||||
isOk = 1;
|
||||
break;
|
||||
|
||||
@@ -4608,7 +4608,8 @@ struct FpDecode {
|
||||
char isSpecial; /* 1: Infinity 2: NaN */
|
||||
int n; /* Significant digits in the decode */
|
||||
int iDP; /* Location of the decimal point */
|
||||
char z[24]; /* Significiant digits */
|
||||
char *z; /* Start of significant digits */
|
||||
char zBuf[24]; /* Storage for significant digits */
|
||||
};
|
||||
|
||||
void sqlite3FpDecode(FpDecode*,double,int,int);
|
||||
|
||||
17
src/test1.c
17
src/test1.c
@@ -7099,11 +7099,14 @@ static int SQLITE_TCLAPI extra_schema_checks(
|
||||
}
|
||||
|
||||
/*
|
||||
** tclcmd: use_long_double INT
|
||||
** tclcmd: use_long_double BOOLEAN|"default"
|
||||
**
|
||||
** Enable or disable the use of long double. Enable if the argument is
|
||||
** positive. Disable if the argument is zero. No-op if the argument is
|
||||
** negative.
|
||||
** If no argument, report the current value of the use-long-double flag.
|
||||
**
|
||||
** If argument is "default", set the use-long-double flag to the default
|
||||
** value for this build, based on the size of LONGDOUBLE_TYPE.
|
||||
**
|
||||
** If argument is a boolean, set the use-long-double flag accordingly.
|
||||
**
|
||||
** Return the new setting.
|
||||
*/
|
||||
@@ -7115,7 +7118,11 @@ static int SQLITE_TCLAPI use_long_double(
|
||||
){
|
||||
int i = -1;
|
||||
if( objc==2 ){
|
||||
if( Tcl_GetBooleanFromObj(interp,objv[1],&i) ) return TCL_ERROR;
|
||||
if( strcmp(Tcl_GetString(objv[1]),"default")==0 ){
|
||||
i = 2;
|
||||
}else{
|
||||
if( Tcl_GetBooleanFromObj(interp,objv[1],&i) ) return TCL_ERROR;
|
||||
}
|
||||
}
|
||||
i = sqlite3_test_control(SQLITE_TESTCTRL_USELONGDOUBLE, i);
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(i));
|
||||
|
||||
33
src/util.c
33
src/util.c
@@ -422,11 +422,11 @@ static void dekkerMul2(volatile double *x, double y, double yy){
|
||||
double hx, hy;
|
||||
u64 m;
|
||||
memcpy(&m, (void*)&x[0], 8);
|
||||
m &= 0xfffffffffc000000L;
|
||||
m &= 0xfffffffffc000000LL;
|
||||
memcpy(&hx, &m, 8);
|
||||
tx = x[0] - hx;
|
||||
memcpy(&m, &y, 8);
|
||||
m &= 0xfffffffffc000000L;
|
||||
m &= 0xfffffffffc000000LL;
|
||||
memcpy(&hy, &m, 8);
|
||||
ty = y - hy;
|
||||
p = hx*hy;
|
||||
@@ -950,12 +950,18 @@ int sqlite3Atoi(const char *z){
|
||||
** n is positive. Or round to -n signficant digits after the
|
||||
** decimal point if n is negative. No rounding is performed if
|
||||
** n is zero.
|
||||
**
|
||||
** The significant digits of the decimal representation are
|
||||
** stored in p->z[] which is a often (but not always) a pointer
|
||||
** into the middle of p->zBuf[]. There are p->n significant digits.
|
||||
** The p->z[] array is *not* zero-terminated.
|
||||
*/
|
||||
void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){
|
||||
int i;
|
||||
u64 v;
|
||||
int e, exp = 0;
|
||||
p->isSpecial = 0;
|
||||
p->z = p->zBuf;
|
||||
|
||||
/* Convert negative numbers to positive. Deal with Infinity, 0.0, and
|
||||
** NaN. */
|
||||
@@ -966,7 +972,7 @@ void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){
|
||||
p->sign = '+';
|
||||
p->n = 1;
|
||||
p->iDP = 1;
|
||||
p->z[0] = '0';
|
||||
p->z = "0";
|
||||
return;
|
||||
}else{
|
||||
p->sign = '+';
|
||||
@@ -974,7 +980,7 @@ void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){
|
||||
memcpy(&v,&r,8);
|
||||
e = v>>52;
|
||||
if( (e&0x7ff)==0x7ff ){
|
||||
p->isSpecial = 1 + (v!=0x7ff0000000000000L);
|
||||
p->isSpecial = 1 + (v!=0x7ff0000000000000LL);
|
||||
p->n = 0;
|
||||
p->iDP = 0;
|
||||
return;
|
||||
@@ -1040,21 +1046,25 @@ void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){
|
||||
|
||||
|
||||
/* Extract significant digits. */
|
||||
i = sizeof(p->z)-1;
|
||||
while( v ){ p->z[i--] = (v%10) + '0'; v /= 10; }
|
||||
p->n = sizeof(p->z) - 1 - i;
|
||||
i = sizeof(p->zBuf)-1;
|
||||
assert( v>0 );
|
||||
while( v ){ p->zBuf[i--] = (v%10) + '0'; v /= 10; }
|
||||
assert( i>=0 && i<sizeof(p->zBuf)-1 );
|
||||
p->n = sizeof(p->zBuf) - 1 - i;
|
||||
assert( p->n>0 );
|
||||
assert( p->n<sizeof(p->zBuf) );
|
||||
p->iDP = p->n + exp;
|
||||
if( iRound<0 ){
|
||||
iRound = p->iDP - iRound;
|
||||
if( iRound==0 && p->z[i+1]>='5' ){
|
||||
if( iRound==0 && p->zBuf[i+1]>='5' ){
|
||||
iRound = 1;
|
||||
p->z[i--] = '0';
|
||||
p->zBuf[i--] = '0';
|
||||
p->n++;
|
||||
p->iDP++;
|
||||
}
|
||||
}
|
||||
if( iRound>0 && (iRound<p->n || p->n>mxRound) ){
|
||||
char *z = &p->z[i+1];
|
||||
char *z = &p->zBuf[i+1];
|
||||
if( iRound>mxRound ) iRound = mxRound;
|
||||
p->n = iRound;
|
||||
if( z[iRound]>='5' ){
|
||||
@@ -1074,7 +1084,8 @@ void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){
|
||||
}
|
||||
}
|
||||
}
|
||||
memmove(p->z, &p->z[i+1], p->n);
|
||||
p->z = &p->zBuf[i+1];
|
||||
assert( i+p->n < sizeof(p->zBuf) );
|
||||
while( ALWAYS(p->n>0) && p->z[p->n-1]=='0' ){ p->n--; }
|
||||
}
|
||||
|
||||
|
||||
@@ -731,8 +731,8 @@ int sqlite3RealSameAsInt(double r1, sqlite3_int64 i){
|
||||
** from UBSAN.
|
||||
*/
|
||||
i64 sqlite3RealToI64(double r){
|
||||
if( r<=(double)SMALLEST_INT64 ) return SMALLEST_INT64;
|
||||
if( r>=(double)LARGEST_INT64) return LARGEST_INT64;
|
||||
if( r<-9223372036854774784.0 ) return SMALLEST_INT64;
|
||||
if( r>+9223372036854774784.0 ) return LARGEST_INT64;
|
||||
return (i64)r;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user