extensions/sqlite/sqlite-source/util.c
changeset 1645 27307df4d711
parent 1203 633c25ce6405
     1.1 --- a/extensions/sqlite/sqlite-source/util.c	Sun Oct 28 05:06:12 2007 +0000
     1.2 +++ b/extensions/sqlite/sqlite-source/util.c	Sun Oct 28 05:48:06 2007 +0000
     1.3 @@ -17,7 +17,6 @@
     1.4  ** $Id$
     1.5  */
     1.6  #include "sqliteInt.h"
     1.7 -#include "os.h"
     1.8  #include <stdarg.h>
     1.9  #include <ctype.h>
    1.10  
    1.11 @@ -44,15 +43,15 @@
    1.12  ** to NULL.
    1.13  */
    1.14  void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){
    1.15 -  if( db && (db->pErr || (db->pErr = sqlite3ValueNew())!=0) ){
    1.16 +  if( db && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){
    1.17      db->errCode = err_code;
    1.18      if( zFormat ){
    1.19        char *z;
    1.20        va_list ap;
    1.21        va_start(ap, zFormat);
    1.22 -      z = sqlite3VMPrintf(zFormat, ap);
    1.23 +      z = sqlite3VMPrintf(db, zFormat, ap);
    1.24        va_end(ap);
    1.25 -      sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, sqlite3FreeX);
    1.26 +      sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, sqlite3_free);
    1.27      }else{
    1.28        sqlite3ValueSetStr(db->pErr, 0, 0, SQLITE_UTF8, SQLITE_STATIC);
    1.29      }
    1.30 @@ -79,9 +78,9 @@
    1.31  void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
    1.32    va_list ap;
    1.33    pParse->nErr++;
    1.34 -  sqliteFree(pParse->zErrMsg);
    1.35 +  sqlite3_free(pParse->zErrMsg);
    1.36    va_start(ap, zFormat);
    1.37 -  pParse->zErrMsg = sqlite3VMPrintf(zFormat, ap);
    1.38 +  pParse->zErrMsg = sqlite3VMPrintf(pParse->db, zFormat, ap);
    1.39    va_end(ap);
    1.40    if( pParse->rc==SQLITE_OK ){
    1.41      pParse->rc = SQLITE_ERROR;
    1.42 @@ -92,7 +91,7 @@
    1.43  ** Clear the error message in pParse, if any
    1.44  */
    1.45  void sqlite3ErrorClear(Parse *pParse){
    1.46 -  sqliteFree(pParse->zErrMsg);
    1.47 +  sqlite3_free(pParse->zErrMsg);
    1.48    pParse->zErrMsg = 0;
    1.49    pParse->nErr = 0;
    1.50  }
    1.51 @@ -421,10 +420,16 @@
    1.52      zNum++;
    1.53    }
    1.54    while( zNum[0]=='0' ) zNum++;
    1.55 -  for(i=0; i<10 && (c = zNum[i] - '0')>=0 && c<=9; i++){
    1.56 +  for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
    1.57      v = v*10 + c;
    1.58    }
    1.59 -  if( i>9 ){
    1.60 +
    1.61 +  /* The longest decimal representation of a 32 bit integer is 10 digits:
    1.62 +  **
    1.63 +  **             1234567890
    1.64 +  **     2^31 -> 2147483648
    1.65 +  */
    1.66 +  if( i>10 ){
    1.67      return 0;
    1.68    }
    1.69    if( v-neg>2147483647 ){
    1.70 @@ -631,13 +636,13 @@
    1.71  ** binary value has been obtained from malloc and must be freed by
    1.72  ** the calling routine.
    1.73  */
    1.74 -void *sqlite3HexToBlob(const char *z){
    1.75 +void *sqlite3HexToBlob(sqlite3 *db, const char *z){
    1.76    char *zBlob;
    1.77    int i;
    1.78    int n = strlen(z);
    1.79    if( n%2 ) return 0;
    1.80  
    1.81 -  zBlob = (char *)sqliteMalloc(n/2);
    1.82 +  zBlob = (char *)sqlite3DbMallocRaw(db, n/2);
    1.83    if( zBlob ){
    1.84      for(i=0; i<n; i+=2){
    1.85        zBlob[i/2] = (hexToInt(z[i])<<4) | hexToInt(z[i+1]);
    1.86 @@ -699,34 +704,3 @@
    1.87      return 1;
    1.88    }
    1.89  }
    1.90 -
    1.91 -/*
    1.92 -** Return a pointer to the ThreadData associated with the calling thread.
    1.93 -*/
    1.94 -ThreadData *sqlite3ThreadData(){
    1.95 -  ThreadData *p = (ThreadData*)sqlite3OsThreadSpecificData(1);
    1.96 -  if( !p ){
    1.97 -    sqlite3FailedMalloc();
    1.98 -  }
    1.99 -  return p;
   1.100 -}
   1.101 -
   1.102 -/*
   1.103 -** Return a pointer to the ThreadData associated with the calling thread.
   1.104 -** If no ThreadData has been allocated to this thread yet, return a pointer
   1.105 -** to a substitute ThreadData structure that is all zeros. 
   1.106 -*/
   1.107 -const ThreadData *sqlite3ThreadDataReadOnly(){
   1.108 -  static const ThreadData zeroData = {0};  /* Initializer to silence warnings
   1.109 -                                           ** from broken compilers */
   1.110 -  const ThreadData *pTd = sqlite3OsThreadSpecificData(0);
   1.111 -  return pTd ? pTd : &zeroData;
   1.112 -}
   1.113 -
   1.114 -/*
   1.115 -** Check to see if the ThreadData for this thread is all zero.  If it
   1.116 -** is, then deallocate it. 
   1.117 -*/
   1.118 -void sqlite3ReleaseThreadData(){
   1.119 -  sqlite3OsThreadSpecificData(-1);
   1.120 -}