/ Check-in [75d91e3b]
Login

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

Overview
Comment:Previous commit of changes to the in-memory backend was not quite right. This check-in should square things away. (CVS 1170)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 75d91e3bca44787768b1970203878dd4b1e31e55
User & Date: drh 2004-01-12 00:38:18
Context
2004-01-12
00:39
On unix, embargo close() operations until all locks have cleared from the file. Ticket #561. (CVS 1171) check-in: 1ebe5fc7 user: drh tags: trunk
00:38
Previous commit of changes to the in-memory backend was not quite right. This check-in should square things away. (CVS 1170) check-in: 75d91e3b user: drh tags: trunk
00:21
Make sure the in-memory database can handle malloc failures. (CVS 1169) check-in: ba92af18 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/btree_rb.c.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12         -** $Id: btree_rb.c,v 1.19 2004/01/12 00:21:52 drh Exp $
           12  +** $Id: btree_rb.c,v 1.20 2004/01/12 00:38:18 drh Exp $
    13     13   **
    14     14   ** This file implements an in-core database using Red-Black balanced
    15     15   ** binary trees.
    16     16   ** 
    17     17   ** It was contributed to SQLite by anonymous on 2003-Feb-04 23:24:49 UTC.
    18     18   */
    19     19   #include "btree.h"
................................................................................
   761    761     if( checkReadLocks(pCur) ){
   762    762       return SQLITE_LOCKED; /* The table pCur points to has a read lock */
   763    763     }
   764    764   
   765    765     /* Take a copy of the input data now, in case we need it for the 
   766    766      * replace case */
   767    767     pData = sqliteMallocRaw(nData);
   768         -  if( pData==0 ) return SQLITE_NOMEM;
          768  +  if( sqlite_malloc_failed ) return SQLITE_NOMEM;
   769    769     memcpy(pData, pDataInput, nData);
   770    770   
   771    771     /* Move the cursor to a node near the key to be inserted. If the key already
   772    772      * exists in the table, then (match == 0). In this case we can just replace
   773    773      * the data associated with the entry, we don't need to manipulate the tree.
   774    774      * 
   775    775      * If there is no exact match, then the cursor points at what would be either
................................................................................
   781    781      */
   782    782     memRbtreeMoveto( pCur, pKey, nKey, &match);
   783    783     if( match ){
   784    784       BtRbNode *pNode = sqliteMalloc(sizeof(BtRbNode));
   785    785       if( pNode==0 ) return SQLITE_NOMEM;
   786    786       pNode->nKey = nKey;
   787    787       pNode->pKey = sqliteMallocRaw(nKey);
   788         -    if( pNode->pKey==0 ) return SQLITE_NOMEM;
          788  +    if( sqlite_malloc_failed ) return SQLITE_NOMEM;
   789    789       memcpy(pNode->pKey, pKey, nKey);
   790    790       pNode->nData = nData;
   791    791       pNode->pData = pData; 
   792    792       if( pCur->pNode ){
   793    793         switch( match ){
   794    794           case -1:
   795    795             assert( !pCur->pNode->pRight );
................................................................................
   818    818       if( pCur->pRbtree->eTransState != TRANS_ROLLBACK ){
   819    819         BtRollbackOp *pOp = sqliteMalloc( sizeof(BtRollbackOp) );
   820    820         if( pOp==0 ) return SQLITE_NOMEM;
   821    821         pOp->eOp = ROLLBACK_DELETE;
   822    822         pOp->iTab = pCur->iTree;
   823    823         pOp->nKey = pNode->nKey;
   824    824         pOp->pKey = sqliteMallocRaw( pOp->nKey );
   825         -      if( pOp->pKey==0 ) return SQLITE_NOMEM;
          825  +      if( sqlite_malloc_failed ) return SQLITE_NOMEM;
   826    826         memcpy( pOp->pKey, pNode->pKey, pOp->nKey );
   827    827         btreeLogRollbackOp(pCur->pRbtree, pOp);
   828    828       }
   829    829   
   830    830     }else{ 
   831    831       /* No need to insert a new node in the tree, as the key already exists.
   832    832        * Just clobber the current nodes data. */
................................................................................
   834    834       /* Set up a rollback-op in case we have to roll this operation back */
   835    835       if( pCur->pRbtree->eTransState != TRANS_ROLLBACK ){
   836    836         BtRollbackOp *pOp = sqliteMalloc( sizeof(BtRollbackOp) );
   837    837         if( pOp==0 ) return SQLITE_NOMEM;
   838    838         pOp->iTab = pCur->iTree;
   839    839         pOp->nKey = pCur->pNode->nKey;
   840    840         pOp->pKey = sqliteMallocRaw( pOp->nKey );
   841         -      if( pOp->pKey==0 ) return SQLITE_NOMEM;
          841  +      if( sqlite_malloc_failed ) return SQLITE_NOMEM;
   842    842         memcpy( pOp->pKey, pCur->pNode->pKey, pOp->nKey );
   843    843         pOp->nData = pCur->pNode->nData;
   844    844         pOp->pData = pCur->pNode->pData;
   845    845         pOp->eOp = ROLLBACK_INSERT;
   846    846         btreeLogRollbackOp(pCur->pRbtree, pOp);
   847    847       }else{
   848    848         sqliteFree( pCur->pNode->pData );