/ Check-in [bc10a753]
Login

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

Overview
Comment:Minor changes needed to restore full branch test coverage.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | experimental-pcache
Files: files | file ages | folders
SHA1: bc10a753579b65ba4604867204b7b3d8383f3ac7
User & Date: drh 2011-11-09 16:12:24
Context
2011-11-09
17:01
When compiling with MSVC, use the _msize function. check-in: 797a1479 user: mistachkin tags: experimental-pcache
16:12
Minor changes needed to restore full branch test coverage. check-in: bc10a753 user: drh tags: experimental-pcache
14:23
A negative value N for the cache_size pragma adjusts the number of cache pages to use approximately N kibibytes of memory. check-in: b3faa680 user: drh tags: experimental-pcache
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

  2894   2894         const char *zWord = va_arg(ap, const char*);
  2895   2895         int n = sqlite3Strlen30(zWord);
  2896   2896         rc = (sqlite3KeywordCode((u8*)zWord, n)!=TK_ID) ? SQLITE_N_KEYWORD : 0;
  2897   2897         break;
  2898   2898       }
  2899   2899   #endif 
  2900   2900   
  2901         -    /* sqlite3_test_control(SQLITE_TESTCTRL_PGHDRSZ)
  2902         -    **
  2903         -    ** Return the size of a pcache header in bytes.
  2904         -    */
  2905         -    case SQLITE_TESTCTRL_PGHDRSZ: {
  2906         -      rc = sizeof(PgHdr);
  2907         -      break;
  2908         -    }
  2909         -
  2910   2901       /* sqlite3_test_control(SQLITE_TESTCTRL_SCRATCHMALLOC, sz, &pNew, pFree);
  2911   2902       **
  2912   2903       ** Pass pFree into sqlite3ScratchFree(). 
  2913   2904       ** If sz>0 then allocate a scratch buffer into pNew.  
  2914   2905       */
  2915   2906       case SQLITE_TESTCTRL_SCRATCHMALLOC: {
  2916   2907         void *pFree, **ppNew;

Changes to src/pcache1.c.

   571    571     **      use separate caches (mode-1)
   572    572     */
   573    573   #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) || SQLITE_THREADSAFE==0
   574    574     const int separateCache = 0;
   575    575   #else
   576    576     int separateCache = sqlite3GlobalConfig.bCoreMutex>0;
   577    577   #endif
          578  +
          579  +  assert( (szPage & (szPage-1))==0 && szPage>=512 && szPage<=65536 );
          580  +  assert( szExtra < 300 );
   578    581   
   579    582     sz = sizeof(PCache1) + sizeof(PGroup)*separateCache;
   580    583     pCache = (PCache1 *)sqlite3_malloc(sz);
   581    584     if( pCache ){
   582    585       memset(pCache, 0, sz);
   583    586       if( separateCache ){
   584    587         pGroup = (PGroup*)&pCache[1];
................................................................................
   744    747   
   745    748     /* Step 4. Try to recycle a page. */
   746    749     if( pCache->bPurgeable && pGroup->pLruTail && (
   747    750            (pCache->nPage+1>=pCache->nMax)
   748    751         || pGroup->nCurrentPage>=pGroup->nMaxPage
   749    752         || pcache1UnderMemoryPressure(pCache)
   750    753     )){
   751         -    PCache1 *pOtherCache;
          754  +    PCache1 *pOther;
   752    755       pPage = pGroup->pLruTail;
   753    756       pcache1RemoveFromHash(pPage);
   754    757       pcache1PinPage(pPage);
   755         -    if( (pOtherCache = pPage->pCache)->szPage!=pCache->szPage 
   756         -     || pOtherCache->szExtra!=pCache->szExtra 
   757         -    ){
          758  +    pOther = pPage->pCache;
          759  +
          760  +    /* We want to verify that szPage and szExtra are the same for pOther
          761  +    ** and pCache.  Assert that we can verify this by comparing sums. */
          762  +    assert( (pCache->szPage & (pCache->szPage-1))==0 && pCache->szPage>=512 );
          763  +    assert( pCache->szExtra<512 );
          764  +    assert( (pOther->szPage & (pOther->szPage-1))==0 && pOther->szPage>=512 );
          765  +    assert( pOther->szExtra<512 );
          766  +
          767  +    if( pOther->szPage+pOther->szExtra != pCache->szPage+pCache->szExtra ){
   758    768         pcache1FreePage(pPage);
   759    769         pPage = 0;
   760    770       }else{
   761         -      pGroup->nCurrentPage -= (pOtherCache->bPurgeable - pCache->bPurgeable);
          771  +      pGroup->nCurrentPage -= (pOther->bPurgeable - pCache->bPurgeable);
   762    772       }
   763    773     }
   764    774   
   765    775     /* Step 5. If a usable page buffer has still not been found, 
   766    776     ** attempt to allocate a new one. 
   767    777     */
   768    778     if( !pPage ){

Changes to src/pragma.c.

   342    342   
   343    343     assert( pId2 );
   344    344     zDb = pId2->n>0 ? pDb->zName : 0;
   345    345     if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
   346    346       goto pragma_out;
   347    347     }
   348    348    
   349         -#ifndef SQLITE_OMIT_PAGER_PRAGMAS
          349  +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
   350    350     /*
   351    351     **  PRAGMA [database.]default_cache_size
   352    352     **  PRAGMA [database.]default_cache_size=N
   353    353     **
   354    354     ** The first form reports the current persistent setting for the
   355    355     ** page cache size.  The value returned is the maximum number of
   356    356     ** pages in the page cache.  The second form sets both the current
................................................................................
   391    391         sqlite3VdbeAddOp2(v, OP_Integer, size, 1);
   392    392         sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1);
   393    393         assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
   394    394         pDb->pSchema->cache_size = size;
   395    395         sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
   396    396       }
   397    397     }else
          398  +#endif /* !SQLITE_OMIT_PAGER_PRAGMAS && !SQLITE_OMIT_DEPRECATED */
   398    399   
          400  +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   399    401     /*
   400    402     **  PRAGMA [database.]page_size
   401    403     **  PRAGMA [database.]page_size=N
   402    404     **
   403    405     ** The first form reports the current setting for the
   404    406     ** database page size in bytes.  The second form sets the
   405    407     ** database page size value.  The value can only be set if
................................................................................
   412    414         int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
   413    415         returnSingleInt(pParse, "page_size", size);
   414    416       }else{
   415    417         /* Malloc may fail when setting the page-size, as there is an internal
   416    418         ** buffer that the pager module resizes using sqlite3_realloc().
   417    419         */
   418    420         db->nextPagesize = sqlite3Atoi(zRight);
   419         -      if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
          421  +      if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){
   420    422           db->mallocFailed = 1;
   421    423         }
   422    424       }
   423    425     }else
   424    426   
   425    427     /*
   426    428     **  PRAGMA [database.]secure_delete
................................................................................
   452    454     **  PRAGMA [database.]max_page_count=N
   453    455     **
   454    456     ** The first form reports the current setting for the
   455    457     ** maximum number of pages in the database file.  The 
   456    458     ** second form attempts to change this setting.  Both
   457    459     ** forms return the current setting.
   458    460     **
          461  +  ** The absolute value of N is used.  This is undocumented and might
          462  +  ** change.  The only purpose is to provide an easy way to test
          463  +  ** the sqlite3AbsInt32() function.
          464  +  **
   459    465     **  PRAGMA [database.]page_count
   460    466     **
   461    467     ** Return the number of pages in the specified database.
   462    468     */
   463    469     if( sqlite3StrICmp(zLeft,"page_count")==0
   464    470      || sqlite3StrICmp(zLeft,"max_page_count")==0
   465    471     ){
................................................................................
   466    472       int iReg;
   467    473       if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   468    474       sqlite3CodeVerifySchema(pParse, iDb);
   469    475       iReg = ++pParse->nMem;
   470    476       if( sqlite3Tolower(zLeft[0])=='p' ){
   471    477         sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
   472    478       }else{
   473         -      sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg, sqlite3Atoi(zRight));
          479  +      sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg, 
          480  +                        sqlite3AbsInt32(sqlite3Atoi(zRight)));
   474    481       }
   475    482       sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
   476    483       sqlite3VdbeSetNumCols(v, 1);
   477    484       sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
   478    485     }else
   479    486   
   480    487     /*

Changes to src/prepare.c.

   274    274       }
   275    275     }else{
   276    276       DbSetProperty(db, iDb, DB_Empty);
   277    277     }
   278    278     pDb->pSchema->enc = ENC(db);
   279    279   
   280    280     if( pDb->pSchema->cache_size==0 ){
          281  +#ifndef SQLITE_OMIT_DEPRECATED
   281    282       size = sqlite3AbsInt32(meta[BTREE_DEFAULT_CACHE_SIZE-1]);
   282    283       if( size==0 ){ size = SQLITE_DEFAULT_CACHE_SIZE; }
   283    284       pDb->pSchema->cache_size = size;
          285  +#else
          286  +    pDb->pSchema->cache_size = SQLITE_DEFAULT_CACHE_SIZE;
          287  +#endif
   284    288       sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
   285    289     }
   286    290   
   287    291     /*
   288    292     ** file_format==1    Version 3.0.0.
   289    293     ** file_format==2    Version 3.1.3.  // ALTER TABLE ADD COLUMN
   290    294     ** file_format==3    Version 3.1.4.  // ditto but with non-NULL defaults

Changes to src/shell.c.

  2216   2216         { "benign_malloc_hooks",   SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS    },
  2217   2217         { "pending_byte",          SQLITE_TESTCTRL_PENDING_BYTE           },
  2218   2218         { "assert",                SQLITE_TESTCTRL_ASSERT                 },
  2219   2219         { "always",                SQLITE_TESTCTRL_ALWAYS                 },
  2220   2220         { "reserve",               SQLITE_TESTCTRL_RESERVE                },
  2221   2221         { "optimizations",         SQLITE_TESTCTRL_OPTIMIZATIONS          },
  2222   2222         { "iskeyword",             SQLITE_TESTCTRL_ISKEYWORD              },
  2223         -      { "pghdrsz",               SQLITE_TESTCTRL_PGHDRSZ                },
  2224   2223         { "scratchmalloc",         SQLITE_TESTCTRL_SCRATCHMALLOC          },
  2225   2224       };
  2226   2225       int testctrl = -1;
  2227   2226       int rc = 0;
  2228   2227       int i, n;
  2229   2228       open_db(p);
  2230   2229   
................................................................................
  2261   2260             }
  2262   2261             break;
  2263   2262   
  2264   2263           /* sqlite3_test_control(int) */
  2265   2264           case SQLITE_TESTCTRL_PRNG_SAVE:           
  2266   2265           case SQLITE_TESTCTRL_PRNG_RESTORE:        
  2267   2266           case SQLITE_TESTCTRL_PRNG_RESET:
  2268         -        case SQLITE_TESTCTRL_PGHDRSZ:             
  2269   2267             if( nArg==2 ){
  2270   2268               rc = sqlite3_test_control(testctrl);
  2271   2269               printf("%d (0x%08x)\n", rc, rc);
  2272   2270             } else {
  2273   2271               fprintf(stderr,"Error: testctrl %s takes no options\n", azArg[1]);
  2274   2272             }
  2275   2273             break;

Changes to src/sqlite.h.in.

  5626   5626   #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS     10
  5627   5627   #define SQLITE_TESTCTRL_PENDING_BYTE            11
  5628   5628   #define SQLITE_TESTCTRL_ASSERT                  12
  5629   5629   #define SQLITE_TESTCTRL_ALWAYS                  13
  5630   5630   #define SQLITE_TESTCTRL_RESERVE                 14
  5631   5631   #define SQLITE_TESTCTRL_OPTIMIZATIONS           15
  5632   5632   #define SQLITE_TESTCTRL_ISKEYWORD               16
  5633         -#define SQLITE_TESTCTRL_PGHDRSZ                 17
  5634         -#define SQLITE_TESTCTRL_SCRATCHMALLOC           18
  5635         -#define SQLITE_TESTCTRL_LOCALTIME_FAULT         19
  5636         -#define SQLITE_TESTCTRL_LAST                    19
         5633  +#define SQLITE_TESTCTRL_SCRATCHMALLOC           17
         5634  +#define SQLITE_TESTCTRL_LOCALTIME_FAULT         18
         5635  +#define SQLITE_TESTCTRL_LAST                    18
  5637   5636   
  5638   5637   /*
  5639   5638   ** CAPI3REF: SQLite Runtime Status
  5640   5639   **
  5641   5640   ** ^This interface is used to retrieve runtime status information
  5642   5641   ** about the performance of SQLite, and optionally to reset various
  5643   5642   ** highwater marks.  ^The first argument is an integer code for