/ Check-in [0aaf3feb]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix a problem with SQLITE_TEST_REALLOC_STRESS.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0aaf3febb00f622c5ef0853b2491d69f7ca7a21e
User & Date: drh 2016-01-18 00:20:26
Context
2016-01-18
00:46
Simplification of the VDBE bytecode for incremental blob I/O. check-in: d23849f6 user: drh tags: trunk
00:20
Fix a problem with SQLITE_TEST_REALLOC_STRESS. check-in: 0aaf3feb user: drh tags: trunk
2016-01-16
21:06
Add extra tests to cover untested branches in fts5. check-in: 61deab04 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pragma.c.

   431    431         { OP_ResultRow,   1, 1,        0},
   432    432       };
   433    433       VdbeOp *aOp;
   434    434       sqlite3VdbeUsesBtree(v, iDb);
   435    435       if( !zRight ){
   436    436         setOneColumnName(v, "cache_size");
   437    437         pParse->nMem += 2;
   438         -      sqlite3VdbeVerifyAvailableSpace(v, ArraySize(getCacheSize));
          438  +      sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(getCacheSize));
   439    439         aOp = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize, iLn);
   440         -      assert( aOp!=0 );
          440  +      if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
   441    441         aOp[0].p1 = iDb;
   442    442         aOp[1].p1 = iDb;
   443    443         aOp[6].p1 = SQLITE_DEFAULT_CACHE_SIZE;
   444    444       }else{
   445    445         int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
   446    446         sqlite3BeginWriteOperation(pParse, 0, iDb);
   447    447         sqlite3VdbeAddOp2(v, OP_Integer, size, 1);
................................................................................
   684    684             { OP_If,             1,         0,                 0},    /* 2 */
   685    685             { OP_Halt,           SQLITE_OK, OE_Abort,          0},    /* 3 */
   686    686             { OP_Integer,        0,         1,                 0},    /* 4 */
   687    687             { OP_SetCookie,      0,         BTREE_INCR_VACUUM, 1},    /* 5 */
   688    688           };
   689    689           VdbeOp *aOp;
   690    690           int iAddr = sqlite3VdbeCurrentAddr(v);
   691         -        sqlite3VdbeVerifyAvailableSpace(v, ArraySize(setMeta6));
          691  +        sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(setMeta6));
   692    692           aOp = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6, iLn);
   693         -        assert( aOp!=0 );
          693  +        if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
   694    694           aOp[0].p1 = iDb;
   695    695           aOp[1].p1 = iDb;
   696    696           aOp[2].p2 = iAddr+4;
   697    697           aOp[4].p1 = eAuto - 1;
   698    698           aOp[5].p1 = iDb;
   699    699           sqlite3VdbeUsesBtree(v, iDb);
   700    700         }
................................................................................
  1728   1728         /* Write the specified cookie value */
  1729   1729         static const VdbeOpList setCookie[] = {
  1730   1730           { OP_Transaction,    0,  1,  0},    /* 0 */
  1731   1731           { OP_Integer,        0,  1,  0},    /* 1 */
  1732   1732           { OP_SetCookie,      0,  0,  1},    /* 2 */
  1733   1733         };
  1734   1734         VdbeOp *aOp;
  1735         -      sqlite3VdbeVerifyAvailableSpace(v, ArraySize(setCookie));
         1735  +      sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(setCookie));
  1736   1736         aOp = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0);
  1737         -      assert( aOp!=0 );
         1737  +      if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
  1738   1738         aOp[0].p1 = iDb;
  1739   1739         aOp[1].p1 = sqlite3Atoi(zRight);
  1740   1740         aOp[2].p1 = iDb;
  1741   1741         aOp[2].p2 = iCookie;
  1742   1742       }else{
  1743   1743         /* Read the specified cookie value */
  1744   1744         static const VdbeOpList readCookie[] = {
  1745   1745           { OP_Transaction,     0,  0,  0},    /* 0 */
  1746   1746           { OP_ReadCookie,      0,  1,  0},    /* 1 */
  1747   1747           { OP_ResultRow,       1,  1,  0}
  1748   1748         };
  1749   1749         VdbeOp *aOp;
  1750         -      sqlite3VdbeVerifyAvailableSpace(v, ArraySize(readCookie));
         1750  +      sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(readCookie));
  1751   1751         aOp = sqlite3VdbeAddOpList(v, ArraySize(readCookie),readCookie,0);
  1752         -      assert( aOp!=0 );
         1752  +      if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
  1753   1753         aOp[0].p1 = iDb;
  1754   1754         aOp[1].p1 = iDb;
  1755   1755         aOp[1].p3 = iCookie;
  1756   1756         sqlite3VdbeSetNumCols(v, 1);
  1757   1757         sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
  1758   1758       }
  1759   1759     }

Changes to src/sqliteInt.h.

   398    398   # define ALWAYS(X)      ((X)?1:(assert(0),0))
   399    399   # define NEVER(X)       ((X)?(assert(0),1):0)
   400    400   #else
   401    401   # define ALWAYS(X)      (X)
   402    402   # define NEVER(X)       (X)
   403    403   #endif
   404    404   
          405  +/*
          406  +** Some malloc failures are only possible if SQLITE_TEST_REALLOC_STRESS is
          407  +** defined.  We need to defend against those failures when testing with
          408  +** SQLITE_TEST_REALLOC_STRESS, but we don't want the unreachable branches
          409  +** during a normal build.  The following macro can be used to disable tests
          410  +** that are always false except when SQLITE_TEST_REALLOC_STRESS is set.
          411  +*/
          412  +#if defined(SQLITE_TEST_REALLOC_STRESS)
          413  +# define ONLY_IF_REALLOC_STRESS(X)  (X)
          414  +#elif !defined(NDEBUG)
          415  +# define ONLY_IF_REALLOC_STRESS(X)  ((X)?(assert(0),1):0)
          416  +#else
          417  +# define ONLY_IF_REALLOC_STRESS(X)  (0)
          418  +#endif
          419  +
   405    420   /*
   406    421   ** Declarations used for tracing the operating system interfaces.
   407    422   */
   408    423   #if defined(SQLITE_FORCE_OS_TRACE) || defined(SQLITE_TEST) || \
   409    424       (defined(SQLITE_DEBUG) && SQLITE_OS_WIN)
   410    425     extern int sqlite3OSTrace;
   411    426   # define OSTRACE(X)          if( sqlite3OSTrace ) sqlite3DebugPrintf X

Changes to src/vdbe.h.

   176    176   int sqlite3VdbeGoto(Vdbe*,int);
   177    177   int sqlite3VdbeLoadString(Vdbe*,int,const char*);
   178    178   void sqlite3VdbeMultiLoad(Vdbe*,int,const char*,...);
   179    179   int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
   180    180   int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
   181    181   int sqlite3VdbeAddOp4Dup8(Vdbe*,int,int,int,int,const u8*,int);
   182    182   int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
   183         -#ifdef SQLITE_DEBUG
   184         -  void sqlite3VdbeVerifyAvailableSpace(Vdbe *p, int N);
          183  +#if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS)
          184  +  void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N);
   185    185   #else
   186         -# define sqlite3VdbeVerifyAvailableSpace(A,B)
          186  +# define sqlite3VdbeVerifyNoMallocRequired(A,B)
   187    187   #endif
   188    188   VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno);
   189    189   void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
   190    190   void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8);
   191    191   void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
   192    192   void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
   193    193   void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);

Changes to src/vdbeaux.c.

   603    603   int sqlite3VdbeCurrentAddr(Vdbe *p){
   604    604     assert( p->magic==VDBE_MAGIC_INIT );
   605    605     return p->nOp;
   606    606   }
   607    607   
   608    608   /*
   609    609   ** Verify that at least N opcode slots are available in p without
   610         -** having to malloc for more space.  This interface is used for
   611         -** testing only.
          610  +** having to malloc for more space (except when compiled using
          611  +** SQLITE_TEST_REALLOC_STRESS).  This interface is used during testing
          612  +** to verify that certain calls to sqlite3VdbeAddOpList() can never
          613  +** fail due to a OOM fault and hence that the return value from
          614  +** sqlite3VdbeAddOpList() will always be non-NULL.
   612    615   */
   613         -#ifdef SQLITE_DEBUG
   614         -void sqlite3VdbeVerifyAvailableSpace(Vdbe *p, int N){
          616  +#if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS)
          617  +void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N){
   615    618     assert( p->nOp + N <= p->pParse->nOpAlloc );
   616    619   }
   617    620   #endif
   618    621   
   619    622   /*
   620    623   ** This function returns a pointer to the array of opcodes associated with
   621    624   ** the Vdbe passed as the first argument. It is the callers responsibility