diff options
author | drh <drh@noemail.net> | 2018-02-26 15:31:39 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2018-02-26 15:31:39 +0000 |
commit | bc8f68a3a05ab6e37127685177d2ca182688f60f (patch) | |
tree | a190e3ae333c2d1dcb1e0aac0c2ea4815cba6d9b /src | |
parent | 007c843b0f9b832c21eac4274b361173544c9bb7 (diff) | |
parent | 1fcfa7240f9ab22d11f12d92378c64e89fbf36fb (diff) | |
download | sqlite-bc8f68a3a05ab6e37127685177d2ca182688f60f.tar.gz sqlite-bc8f68a3a05ab6e37127685177d2ca182688f60f.zip |
Merge the fix for determining truth of floating point values from trunk.
FossilOrigin-Name: 003dc140536d0dd4384252ae1b82827b5d8b2b399520f99549b9266a482009fb
Diffstat (limited to 'src')
-rw-r--r-- | src/vdbe.c | 41 | ||||
-rw-r--r-- | src/vdbeInt.h | 1 | ||||
-rw-r--r-- | src/vdbemem.c | 10 |
3 files changed, 24 insertions, 28 deletions
diff --git a/src/vdbe.c b/src/vdbe.c index 7115c8cf7..61fc55e4d 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2172,18 +2172,8 @@ case OP_Or: { /* same as TK_OR, in1, in2, out3 */ int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ - pIn1 = &aMem[pOp->p1]; - if( pIn1->flags & MEM_Null ){ - v1 = 2; - }else{ - v1 = sqlite3VdbeIntValue(pIn1)!=0; - } - pIn2 = &aMem[pOp->p2]; - if( pIn2->flags & MEM_Null ){ - v2 = 2; - }else{ - v2 = sqlite3VdbeIntValue(pIn2)!=0; - } + v1 = sqlite3VdbeBooleanValue(&aMem[pOp->p1], 2); + v2 = sqlite3VdbeBooleanValue(&aMem[pOp->p2], 2); if( pOp->opcode==OP_And ){ static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 }; v1 = and_logic[v1*3+v2]; @@ -2212,7 +2202,7 @@ case OP_Not: { /* same as TK_NOT, in1, out2 */ pIn1 = &aMem[pOp->p1]; pOut = &aMem[pOp->p2]; if( (pIn1->flags & MEM_Null)==0 ){ - sqlite3VdbeMemSetInt64(pOut, !sqlite3VdbeIntValue(pIn1)); + sqlite3VdbeMemSetInt64(pOut, !sqlite3VdbeBooleanValue(pIn1,0)); }else{ sqlite3VdbeMemSetNull(pOut); } @@ -2281,30 +2271,25 @@ case OP_Once: { /* jump */ ** is considered true if it is numeric and non-zero. If the value ** in P1 is NULL then take the jump if and only if P3 is non-zero. */ +case OP_If: { /* jump, in1 */ + int c; + c = sqlite3VdbeBooleanValue(&aMem[pOp->p1], pOp->p3); + VdbeBranchTaken(c!=0, 2); + if( c ) goto jump_to_p2; + break; +} + /* Opcode: IfNot P1 P2 P3 * * ** ** Jump to P2 if the value in register P1 is False. The value ** is considered false if it has a numeric value of zero. If the value ** in P1 is NULL then take the jump if and only if P3 is non-zero. */ -case OP_If: /* jump, in1 */ case OP_IfNot: { /* jump, in1 */ int c; - pIn1 = &aMem[pOp->p1]; - if( pIn1->flags & MEM_Null ){ - c = pOp->p3; - }else{ - if( pIn1->flags & MEM_Int ){ - c = pIn1->u.i!=0; - }else{ - c = sqlite3VdbeRealValue(pIn1)!=0.0; - } - if( pOp->opcode==OP_IfNot ) c = !c; - } + c = !sqlite3VdbeBooleanValue(&aMem[pOp->p1], !pOp->p3); VdbeBranchTaken(c!=0, 2); - if( c ){ - goto jump_to_p2; - } + if( c ) goto jump_to_p2; break; } diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 1e4f615ba..44f901abf 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -486,6 +486,7 @@ int sqlite3VdbeMemStringify(Mem*, u8, u8); i64 sqlite3VdbeIntValue(Mem*); int sqlite3VdbeMemIntegerify(Mem*); double sqlite3VdbeRealValue(Mem*); +int sqlite3VdbeBooleanValue(Mem*, int ifNull); void sqlite3VdbeIntegerAffinity(Mem*); int sqlite3VdbeMemRealify(Mem*); int sqlite3VdbeMemNumerify(Mem*); diff --git a/src/vdbemem.c b/src/vdbemem.c index c02370c73..8df3c0d53 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -573,6 +573,16 @@ double sqlite3VdbeRealValue(Mem *pMem){ } /* +** Return 1 if pMem represents true, and return 0 if pMem represents false. +** Return the value ifNull if pMem is NULL. +*/ +int sqlite3VdbeBooleanValue(Mem *pMem, int ifNull){ + if( pMem->flags & MEM_Int ) return pMem->u.i!=0; + if( pMem->flags & MEM_Null ) return ifNull; + return sqlite3VdbeRealValue(pMem)!=0.0; +} + +/* ** The MEM structure is already a MEM_Real. Try to also make it a ** MEM_Int if we can. */ |