/ Check-in [ca3e41b0]
Login

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

Overview
Comment:Use 64-bit arithmetic in the xRead() method of asyncRead. Fix for [94c04eaadb].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ca3e41b0574cfd8d971c2be2114e58273a531970
User & Date: dan 2009-10-19 07:50:26
Context
2009-10-19
15:52
When generating WHERE clause terms internally for NATURAL and USING joins, identify the table by its position in the FROM list, not by its name or alias. Fix for [b73fb0bd64]. check-in: 6fe63711 user: dan tags: trunk
07:50
Use 64-bit arithmetic in the xRead() method of asyncRead. Fix for [94c04eaadb]. check-in: ca3e41b0 user: dan tags: trunk
2009-10-17
14:19
Fix a problem in the icu.test script. check-in: 8a21fdaf user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/async/sqlite3async.c.

   664    664     void *zOut, 
   665    665     int iAmt, 
   666    666     sqlite3_int64 iOffset
   667    667   ){
   668    668     AsyncFileData *p = ((AsyncFile *)pFile)->pData;
   669    669     int rc = SQLITE_OK;
   670    670     sqlite3_int64 filesize;
   671         -  int nRead;
   672    671     sqlite3_file *pBase = p->pBaseRead;
          672  +  sqlite3_int64 iAmt64 = (sqlite3_int64)iAmt;
   673    673   
   674    674     /* Grab the write queue mutex for the duration of the call */
   675    675     async_mutex_enter(ASYNC_MUTEX_QUEUE);
   676    676   
   677    677     /* If an I/O error has previously occurred in this virtual file 
   678    678     ** system, then all subsequent operations fail.
   679    679     */
   680    680     if( async.ioError!=SQLITE_OK ){
   681    681       rc = async.ioError;
   682    682       goto asyncread_out;
   683    683     }
   684    684   
   685    685     if( pBase->pMethods ){
          686  +    sqlite3_int64 nRead;
   686    687       rc = pBase->pMethods->xFileSize(pBase, &filesize);
   687    688       if( rc!=SQLITE_OK ){
   688    689         goto asyncread_out;
   689    690       }
   690         -    nRead = (int)MIN(filesize - iOffset, iAmt);
          691  +    nRead = MIN(filesize - iOffset, iAmt64);
   691    692       if( nRead>0 ){
   692    693         rc = pBase->pMethods->xRead(pBase, zOut, nRead, iOffset);
   693    694         ASYNC_TRACE(("READ %s %d bytes at %d\n", p->zName, nRead, iOffset));
   694    695       }
   695    696     }
   696    697   
   697    698     if( rc==SQLITE_OK ){
................................................................................
   699    700       char *zName = p->zName;
   700    701   
   701    702       for(pWrite=async.pQueueFirst; pWrite; pWrite = pWrite->pNext){
   702    703         if( pWrite->op==ASYNC_WRITE && (
   703    704           (pWrite->pFileData==p) ||
   704    705           (zName && pWrite->pFileData->zName==zName)
   705    706         )){
          707  +        sqlite3_int64 nCopy;
          708  +        sqlite3_int64 nByte64 = (sqlite3_int64)pWrite->nByte;
          709  +
          710  +        /* Set variable iBeginIn to the offset in buffer pWrite->zBuf[] from
          711  +        ** which data should be copied. Set iBeginOut to the offset within
          712  +        ** the output buffer to which data should be copied. If either of
          713  +        ** these offsets is a negative number, set them to 0.
          714  +        */
   706    715           sqlite3_int64 iBeginOut = (pWrite->iOffset-iOffset);
   707    716           sqlite3_int64 iBeginIn = -iBeginOut;
   708         -        int nCopy;
   709         -
   710    717           if( iBeginIn<0 ) iBeginIn = 0;
   711    718           if( iBeginOut<0 ) iBeginOut = 0;
   712         -        nCopy = (int)MIN(pWrite->nByte-iBeginIn, iAmt-iBeginOut);
   713    719   
          720  +        nCopy = MIN(nByte64-iBeginIn, iAmt64-iBeginOut);
   714    721           if( nCopy>0 ){
   715    722             memcpy(&((char *)zOut)[iBeginOut], &pWrite->zBuf[iBeginIn], nCopy);
   716    723             ASYNC_TRACE(("OVERREAD %d bytes at %d\n", nCopy, iBeginOut+iOffset));
   717    724           }
   718    725         }
   719    726       }
   720    727     }

Added test/tkt-94c04eaadb.test.

            1  +# 2009 October 19
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.
           12  +#
           13  +
           14  +set testdir [file dirname $argv0]
           15  +source $testdir/tester.tcl
           16  +
           17  +if {[info commands sqlite3async_initialize] eq ""} {
           18  +  # The async logic is not built into this system
           19  +  finish_test
           20  +  return
           21  +}
           22  +
           23  +# Create a database.
           24  +do_test tkt-94c94-1.1 {
           25  +  execsql { CREATE TABLE t1(a, b) }
           26  +} {}
           27  +
           28  +# Grow the file to larger than 4096MB (2^32 bytes)
           29  +db close
           30  +if {[catch {fake_big_file 4096 [pwd]/test.db} msg]} {
           31  +  puts "**** Unable to create a file larger than 4096 MB. *****"
           32  +  finish_test
           33  +  return
           34  +}
           35  +
           36  +# Switch to async mode.
           37  +sqlite3async_initialize "" 1
           38  +sqlite3 db test.db
           39  +sqlite3 db2 test.db
           40  +
           41  +# Read from and write to the db just past the 4096MB mark.
           42  +#
           43  +do_test tkt-94c94-2.1 {
           44  +  execsql { CREATE TABLE t2(x, y) } db
           45  +} {}
           46  +do_test tkt-94c94-2.2 {
           47  +breakpoint
           48  +  execsql { INSERT INTO t2 VALUES(1, 2) } db2
           49  +} {}
           50  +do_test tkt-94c94-2.3 {
           51  +  execsql { SELECT * FROM t2 } db
           52  +} {1 2}
           53  +do_test tkt-94c94-2.4 {
           54  +  sqlite3async_control halt idle
           55  +  sqlite3async_start
           56  +  sqlite3async_wait
           57  +} {}
           58  +do_test tkt-94c94-2.5 {
           59  +  execsql { SELECT * FROM t2 } db
           60  +} {1 2}
           61  +do_test tkt-94c94-2.6 {
           62  +  sqlite3async_start
           63  +  sqlite3async_wait
           64  +} {}
           65  +
           66  +db close
           67  +db2 close
           68  +sqlite3async_start
           69  +sqlite3async_wait
           70  +sqlite3async_shutdown
           71  +
           72  +finish_test