/ Check-in [4c291827]
Login

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

Overview
Comment:If SQLITE_TEST_REALLOC_STRESS is defined, extend the op-code array used by virtual-machine programs by one element at a time, instead of doubling its size with each realloc().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4c291827224b84487a38e7ccba2edabc0f15b5ba
User & Date: dan 2014-08-12 13:38:52
Context
2014-08-12
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
13:38
If SQLITE_TEST_REALLOC_STRESS is defined, extend the op-code array used by virtual-machine programs by one element at a time, instead of doubling its size with each realloc(). check-in: 4c291827 user: dan tags: trunk
12:19
Fix typos in the VxWorks code of os_unix.c. check-in: 19682e8f user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbeaux.c.

    80     80     zTmp = pA->zSql;
    81     81     pA->zSql = pB->zSql;
    82     82     pB->zSql = zTmp;
    83     83     pB->isPrepareV2 = pA->isPrepareV2;
    84     84   }
    85     85   
    86     86   /*
    87         -** Resize the Vdbe.aOp array so that it is at least one op larger than 
    88         -** it was.
           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.
    89     89   **
    90     90   ** If an out-of-memory error occurs while resizing the array, return
    91         -** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain 
           91  +** SQLITE_NOMEM. In this case Vdbe.aOp and Parse.nOpAlloc remain 
    92     92   ** unchanged (this is so that any opcodes already allocated can be 
    93     93   ** correctly deallocated along with the rest of the Vdbe).
    94     94   */
    95         -static int growOpArray(Vdbe *v){
           95  +static int growOpArray(Vdbe *v, int nOp){
    96     96     VdbeOp *pNew;
    97     97     Parse *p = v->pParse;
           98  +
           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.  */
          103  +#ifdef SQLITE_TEST_REALLOC_STRESS
          104  +  int nNew = (p->nOpAlloc>=512 ? p->nOpAlloc*2 : p->nOpAlloc+nOp);
          105  +#else
    98    106     int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op)));
          107  +  UNUSED_PARAMETER(nOp);
          108  +#endif
          109  +
          110  +  assert( nNew>=(p->nOpAlloc+nOp) );
    99    111     pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
   100    112     if( pNew ){
   101    113       p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
   102    114       v->aOp = pNew;
   103    115     }
   104    116     return (pNew ? SQLITE_OK : SQLITE_NOMEM);
   105    117   }
................................................................................
   135    147     int i;
   136    148     VdbeOp *pOp;
   137    149   
   138    150     i = p->nOp;
   139    151     assert( p->magic==VDBE_MAGIC_INIT );
   140    152     assert( op>0 && op<0xff );
   141    153     if( p->pParse->nOpAlloc<=i ){
   142         -    if( growOpArray(p) ){
          154  +    if( growOpArray(p, 1) ){
   143    155         return 1;
   144    156       }
   145    157     }
   146    158     p->nOp++;
   147    159     pOp = &p->aOp[i];
   148    160     pOp->opcode = (u8)op;
   149    161     pOp->p5 = 0;
................................................................................
   537    549   /*
   538    550   ** Add a whole list of operations to the operation stack.  Return the
   539    551   ** address of the first operation added.
   540    552   */
   541    553   int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp, int iLineno){
   542    554     int addr;
   543    555     assert( p->magic==VDBE_MAGIC_INIT );
   544         -  if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p) ){
          556  +  if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p, nOp) ){
   545    557       return 0;
   546    558     }
   547    559     addr = p->nOp;
   548    560     if( ALWAYS(nOp>0) ){
   549    561       int i;
   550    562       VdbeOpList const *pIn = aOp;
   551    563       for(i=0; i<nOp; i++, pIn++){
................................................................................
   722    734     pVdbe->pProgram = p;
   723    735   }
   724    736   
   725    737   /*
   726    738   ** Change the opcode at addr into OP_Noop
   727    739   */
   728    740   void sqlite3VdbeChangeToNoop(Vdbe *p, int addr){
   729         -  if( p->aOp ){
          741  +  if( addr<p->nOp ){
   730    742       VdbeOp *pOp = &p->aOp[addr];
   731    743       sqlite3 *db = p->db;
   732    744       freeP4(db, pOp->p4type, pOp->p4.p);
   733    745       memset(pOp, 0, sizeof(pOp[0]));
   734    746       pOp->opcode = OP_Noop;
   735    747       if( addr==p->nOp-1 ) p->nOp--;
   736    748     }

Changes to test/incrblob_err.test.

    10     10   #***********************************************************************
    11     11   #
    12     12   # $Id: incrblob_err.test,v 1.14 2008/07/18 17:16:27 drh Exp $
    13     13   #
    14     14   
    15     15   set testdir [file dirname $argv0]
    16     16   source $testdir/tester.tcl
           17  +set ::testprefix incrblob_err
    17     18   
    18     19   ifcapable {!incrblob  || !memdebug || !tclvar} {
    19     20     finish_test
    20     21     return
    21     22   }
    22     23   
    23     24   source $testdir/malloc_common.tcl

Changes to test/malloc.test.

    16     16   # to see what happens in the library if a malloc were to really fail
    17     17   # due to an out-of-memory situation.
    18     18   #
    19     19   # $Id: malloc.test,v 1.81 2009/06/24 13:13:45 drh Exp $
    20     20   
    21     21   set testdir [file dirname $argv0]
    22     22   source $testdir/tester.tcl
           23  +set ::testprefix malloc
    23     24   
    24     25   
    25     26   # Only run these tests if memory debugging is turned on.
    26     27   #
    27     28   source $testdir/malloc_common.tcl
    28     29   if {!$MEMDEBUG} {
    29     30      puts "Skipping malloc tests: not compiled with -DSQLITE_MEMDEBUG..."

Changes to test/malloc_common.tcl.

   405    405   #
   406    406   proc do_malloc_test {tn args} {
   407    407     array unset ::mallocopts 
   408    408     array set ::mallocopts $args
   409    409   
   410    410     if {[string is integer $tn]} {
   411    411       set tn malloc-$tn
          412  +    catch { set tn $::testprefix-$tn }
   412    413     }
   413    414     if {[info exists ::mallocopts(-start)]} {
   414    415       set start $::mallocopts(-start)
   415    416     } else {
   416    417       set start 0
   417    418     }
   418    419     if {[info exists ::mallocopts(-end)]} {