/ Check-in [bd41d394]
Login

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

Overview
Comment:Faster implementation of the sqlite3ApiExit() routine.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: bd41d394d48516eb7d8ddc46abdcb427aa80173e
User & Date: drh 2014-08-23 20:25:53
Context
2014-08-23
23:15
Faster implementation of pcache1Fetch() check-in: 0371cc3b user: drh tags: trunk
20:25
Faster implementation of the sqlite3ApiExit() routine. check-in: bd41d394 user: drh tags: trunk
19:42
Another memory allocator performance optimization. check-in: 6da6f46d user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/malloc.c.

   757    757     va_start(ap, zFormat);
   758    758     z = sqlite3VMPrintf(db, zFormat, ap);
   759    759     va_end(ap);
   760    760     sqlite3DbFree(db, *pz);
   761    761     *pz = z;
   762    762   }
   763    763   
          764  +/*
          765  +** Take actions at the end of an API call to indicate an OOM error
          766  +*/
          767  +static SQLITE_NOINLINE int apiOomError(sqlite3 *db){
          768  +  db->mallocFailed = 0;
          769  +  sqlite3Error(db, SQLITE_NOMEM);
          770  +  return SQLITE_NOMEM;
          771  +}
   764    772   
   765    773   /*
   766    774   ** This function must be called before exiting any API function (i.e. 
   767    775   ** returning control to the user) that has called sqlite3_malloc or
   768    776   ** sqlite3_realloc.
   769    777   **
   770    778   ** The returned value is normally a copy of the second argument to this
................................................................................
   777    785   */
   778    786   int sqlite3ApiExit(sqlite3* db, int rc){
   779    787     /* If the db handle is not NULL, then we must hold the connection handle
   780    788     ** mutex here. Otherwise the read (and possible write) of db->mallocFailed 
   781    789     ** is unsafe, as is the call to sqlite3Error().
   782    790     */
   783    791     assert( !db || sqlite3_mutex_held(db->mutex) );
   784         -  if( db && (db->mallocFailed || rc==SQLITE_IOERR_NOMEM) ){
   785         -    sqlite3Error(db, SQLITE_NOMEM);
   786         -    db->mallocFailed = 0;
   787         -    rc = SQLITE_NOMEM;
          792  +  if( db==0 ) return rc & 0xff;
          793  +  if( db->mallocFailed || rc==SQLITE_IOERR_NOMEM ){
          794  +    return apiOomError(db);
   788    795     }
   789         -  return rc & (db ? db->errMask : 0xff);
          796  +  return rc & db->errMask;
   790    797   }