/ Check-in [35c45461]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Improve the comments associated with SQLITE_TEST_REALLOC_STRESS and add an extra assert() to prove an assumption.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 35c454616321d480ecbc4efdf6869bbcdf0d3aa2
User & Date: drh 2014-08-12 14:29:20
Context
2014-08-12
16:13
Fix compilation issue in the Win32 VFS when manually defining SQLITE_WIN32_NO_ANSI. check-in: 67159912 user: mistachkin tags: trunk
14:29
Improve the comments associated with SQLITE_TEST_REALLOC_STRESS and add an extra assert() to prove an assumption. check-in: 35c45461 user: drh tags: trunk
14:06
Run a test with TEST_REALLOC_STRESS and OMIT_LOOKASIDE defined as part of releasetest.tcl on Linux/x86-64. check-in: a1baf3a7 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/vdbeaux.c.

    81     81     pA->zSql = pB->zSql;
    82     82     pB->zSql = zTmp;
    83     83     pB->isPrepareV2 = pA->isPrepareV2;
    84     84   }
    85     85   
    86     86   /*
    87     87   ** Resize the Vdbe.aOp array so that it is at least nOp elements larger 
    88         -** its current size. nOp is guaranteed to be less than or equal to 1024.
           88  +** than its current size. nOp is guaranteed to be less than or equal
           89  +** to 1024/sizeof(Op).
    89     90   **
    90     91   ** If an out-of-memory error occurs while resizing the array, return
    91     92   ** SQLITE_NOMEM. In this case Vdbe.aOp and Parse.nOpAlloc remain 
    92     93   ** unchanged (this is so that any opcodes already allocated can be 
    93     94   ** correctly deallocated along with the rest of the Vdbe).
    94     95   */
    95     96   static int growOpArray(Vdbe *v, int nOp){
    96     97     VdbeOp *pNew;
    97     98     Parse *p = v->pParse;
    98     99   
    99         -  /* If SQLITE_TEST_REALLOC_STRESS is defined and the current op array is
   100         -  ** less than 512 entries in size, grow the op array by the minimum amount 
   101         -  ** required. Otherwise, allocate either double the current size of the 
   102         -  ** array or 1KB of space, whichever is smaller.  */
          100  +  /* The SQLITE_TEST_REALLOC_STRESS compile-time option is designed to force
          101  +  ** more frequent reallocs and hence provide more opportunities for 
          102  +  ** simulated OOM faults.  SQLITE_TEST_REALLOC_STRESS is generally used
          103  +  ** during testing only.  With SQLITE_TEST_REALLOC_STRESS grow the op array
          104  +  ** by the minimum* amount required until the size reaches 512.  Normal
          105  +  ** operation (without SQLITE_TEST_REALLOC_STRESS) is to double the current
          106  +  ** size of the op array or add 1KB of space, whichever is smaller. */
   103    107   #ifdef SQLITE_TEST_REALLOC_STRESS
   104    108     int nNew = (p->nOpAlloc>=512 ? p->nOpAlloc*2 : p->nOpAlloc+nOp);
   105    109   #else
   106    110     int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op)));
   107    111     UNUSED_PARAMETER(nOp);
   108    112   #endif
   109    113   
          114  +  assert( nOp<=(1024/sizeof(Op)) );
   110    115     assert( nNew>=(p->nOpAlloc+nOp) );
   111    116     pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
   112    117     if( pNew ){
   113    118       p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
   114    119       v->aOp = pNew;
   115    120     }
   116    121     return (pNew ? SQLITE_OK : SQLITE_NOMEM);