/ Check-in [0a2c7f74]
Login

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

Overview
Comment:Changes to setupLookaside() in main.c to better handle lookaside buffer configurations of zero-size. Ticket #3616. (CVS 6218)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:0a2c7f740397c5c6373434c75d73c2714f14dd32
User & Date: shane 2009-01-30 06:11:55
Context
2009-01-30
16:09
Made code to remove unused parameter warning part of the conditional. Ticket #3610. (CVS 6219) check-in: c5dca114 user: shane tags: trunk
06:11
Changes to setupLookaside() in main.c to better handle lookaside buffer configurations of zero-size. Ticket #3616. (CVS 6218) check-in: 0a2c7f74 user: shane tags: trunk
05:59
Implemented the SQLITE_LAST_ERRNO op in the xFileControl() method of os_win.c. Ticket #3615. (CVS 6217) check-in: 9ea871f3 user: shane tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/main.c.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
382
383
384
385
386
387
388
389










390



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409

410
411
412
413
414
415
416
417

418
419
420

421
422
423
424
425
426
427
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.522 2009/01/20 16:53:41 danielk1977 Exp $
*/
#include "sqliteInt.h"

#ifdef SQLITE_ENABLE_FTS3
# include "fts3.h"
#endif
#ifdef SQLITE_ENABLE_RTREE
................................................................................
** the lookaside memory.
*/
static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
  void *pStart;
  if( db->lookaside.nOut ){
    return SQLITE_BUSY;
  }
  if( sz<0 ) sz = 0;










  if( cnt<0 ) cnt = 0;



  if( pBuf==0 ){
    sz = (sz + 7)&~7;
    sqlite3BeginBenignMalloc();
    pStart = sqlite3Malloc( sz*cnt );
    sqlite3EndBenignMalloc();
  }else{
    sz = sz&~7;
    pStart = pBuf;
  }
  if( db->lookaside.bMalloced ){
    sqlite3_free(db->lookaside.pStart);
  }
  db->lookaside.pStart = pStart;
  db->lookaside.pFree = 0;
  db->lookaside.sz = (u16)sz;
  db->lookaside.bMalloced = pBuf==0 ?1:0;
  if( pStart ){
    int i;
    LookasideSlot *p;

    p = (LookasideSlot*)pStart;
    for(i=cnt-1; i>=0; i--){
      p->pNext = db->lookaside.pFree;
      db->lookaside.pFree = p;
      p = (LookasideSlot*)&((u8*)p)[sz];
    }
    db->lookaside.pEnd = p;
    db->lookaside.bEnabled = 1;

  }else{
    db->lookaside.pEnd = 0;
    db->lookaside.bEnabled = 0;

  }
  return SQLITE_OK;
}

/*
** Return the mutex associated with a database connection.
*/







|







 







|
>
>
>
>
>
>
>
>
>
>

>
>
>
|








<
<
<



<



>








>



>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412



413
414
415

416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.523 2009/01/30 06:11:55 shane Exp $
*/
#include "sqliteInt.h"

#ifdef SQLITE_ENABLE_FTS3
# include "fts3.h"
#endif
#ifdef SQLITE_ENABLE_RTREE
................................................................................
** the lookaside memory.
*/
static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
  void *pStart;
  if( db->lookaside.nOut ){
    return SQLITE_BUSY;
  }
  /* Free any existing lookaside buffer for this handle before
  ** allocating a new one so we don't have to have space for 
  ** both at the same time.
  */
  if( db->lookaside.bMalloced ){
    sqlite3_free(db->lookaside.pStart);
  }
  /* The size of a lookaside slot needs to be larger than a pointer
  ** to be useful.
  */
  if( sz<=sizeof(LookasideSlot*) ) sz = 0;
  if( cnt<0 ) cnt = 0;
  if( sz==0 || cnt==0 ){
    sz = 0;
    pStart = 0;
  }else if( pBuf==0 ){
    sz = (sz + 7)&~7;
    sqlite3BeginBenignMalloc();
    pStart = sqlite3Malloc( sz*cnt );
    sqlite3EndBenignMalloc();
  }else{
    sz = sz&~7;
    pStart = pBuf;
  }



  db->lookaside.pStart = pStart;
  db->lookaside.pFree = 0;
  db->lookaside.sz = (u16)sz;

  if( pStart ){
    int i;
    LookasideSlot *p;
    assert( sz > sizeof(LookasideSlot*) );
    p = (LookasideSlot*)pStart;
    for(i=cnt-1; i>=0; i--){
      p->pNext = db->lookaside.pFree;
      db->lookaside.pFree = p;
      p = (LookasideSlot*)&((u8*)p)[sz];
    }
    db->lookaside.pEnd = p;
    db->lookaside.bEnabled = 1;
    db->lookaside.bMalloced = pBuf==0 ?1:0;
  }else{
    db->lookaside.pEnd = 0;
    db->lookaside.bEnabled = 0;
    db->lookaside.bMalloced = 0;
  }
  return SQLITE_OK;
}

/*
** Return the mutex associated with a database connection.
*/