SQLite4
Check-in [1e83e737e4]
Not logged in

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

Overview
Comment:Factor out methods of sqlite4_env into a separate env.c source file. Add in the sqlite4_mm object. Remove deprecated interfaces.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1e83e737e42b8074603af9eef931dc653db81cb8
User & Date: drh 2013-02-23 17:39:05
Context
2013-02-23
18:36
Fix a bug in the makefile that prevents the building of the amalgamation. check-in: 9e3d29f603 user: drh tags: trunk
17:39
Factor out methods of sqlite4_env into a separate env.c source file. Add in the sqlite4_mm object. Remove deprecated interfaces. check-in: 1e83e737e4 user: drh tags: trunk
16:32
Remove the sqlite4_last_insert_rowid() and related infrastructure, since in SQLite4 we no longer have a rowid. Other cleanup of the sqlite4.h file. check-in: c92e61312f user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to main.mk.

    66     66   
    67     67   TCPPX = g++ -Wall -g -I. -I$(TOP)/src $(OPTS)
    68     68   
    69     69   
    70     70   LIBOBJ+= vdbe.o parse.o \
    71     71            alter.o analyze.o attach.o auth.o \
    72     72            build.o \
    73         -         callback.o complete.o ctime.o date.o delete.o expr.o fault.o fkey.o \
    74         -	 fts5.o fts5func.o \
           73  +         callback.o complete.o ctime.o date.o delete.o env.o expr.o \
           74  +         fault.o fkey.o fts5.o fts5func.o \
    75     75            func.o global.o hash.o \
    76     76            icu.o insert.o kv.o kvlsm.o kvmem.o legacy.o \
    77     77            lsm_ckpt.o lsm_file.o lsm_log.o lsm_main.o lsm_mem.o lsm_mutex.o \
    78     78            lsm_shared.o lsm_str.o lsm_sorted.o lsm_tree.o \
    79     79            lsm_unix.o lsm_varint.o \
    80         -         main.o malloc.o math.o mem0.o mem1.o mem2.o mem3.o mem5.o \
           80  +         main.o malloc.o math.o mem.o mem0.o mem1.o mem2.o mem3.o mem5.o \
    81     81            mutex.o mutex_noop.o mutex_unix.o mutex_w32.o \
    82     82            opcodes.o os.o \
    83     83            pragma.o prepare.o printf.o \
    84     84            random.o resolve.o rowset.o rtree.o select.o status.o \
    85     85            tokenize.o trigger.o \
    86     86            update.o util.o varint.o \
    87     87            vdbeapi.o vdbeaux.o vdbecodec.o vdbecursor.o \
................................................................................
    97     97     $(TOP)/src/auth.c \
    98     98     $(TOP)/src/build.c \
    99     99     $(TOP)/src/callback.c \
   100    100     $(TOP)/src/complete.c \
   101    101     $(TOP)/src/ctime.c \
   102    102     $(TOP)/src/date.c \
   103    103     $(TOP)/src/delete.c \
          104  +  $(TOP)/src/env.c \
   104    105     $(TOP)/src/expr.c \
   105    106     $(TOP)/src/fault.c \
   106    107     $(TOP)/src/fkey.c \
   107    108     $(TOP)/src/fts5.c \
   108    109     $(TOP)/src/fts5func.c \
   109    110     $(TOP)/src/func.c \
   110    111     $(TOP)/src/global.c \
................................................................................
   130    131     $(TOP)/src/lsm_sorted.c \
   131    132     $(TOP)/src/lsm_tree.c \
   132    133     $(TOP)/src/lsm_unix.c \
   133    134     $(TOP)/src/lsm_varint.c \
   134    135     $(TOP)/src/main.c \
   135    136     $(TOP)/src/malloc.c \
   136    137     $(TOP)/src/math.c \
          138  +  $(TOP)/src/mem.o \
   137    139     $(TOP)/src/mem0.c \
   138    140     $(TOP)/src/mem1.c \
   139    141     $(TOP)/src/mem2.c \
   140    142     $(TOP)/src/mem3.c \
   141    143     $(TOP)/src/mem5.c \
   142    144     $(TOP)/src/mutex.c \
   143    145     $(TOP)/src/mutex.h \

Added src/env.c.

            1  +/*
            2  +** 2013 January 7
            3  +**
            4  +** The author disclaims copyright to this source code.  In place of
            5  +** a legal notice, here is a blessing:
            6  +**
            7  +**    May you do good and not evil.
            8  +**    May you find forgiveness for yourself and forgive others.
            9  +**    May you share freely, never taking more than you give.
           10  +**
           11  +*************************************************************************
           12  +** 
           13  +** This file contains code used to help implement the sqlite4_env object.
           14  +*/
           15  +#include "sqliteInt.h"
           16  +
           17  +/*
           18  +** Initialize SQLite.  
           19  +**
           20  +** This routine must be called to initialize the run-time environment
           21  +** As long as you do not compile with SQLITE4_OMIT_AUTOINIT
           22  +** this routine will be called automatically by key routines such as
           23  +** sqlite4_open().  
           24  +**
           25  +** This routine is a no-op except on its very first call for a given
           26  +** sqlite4_env object, or for the first call after a call to sqlite4_shutdown.
           27  +**
           28  +** This routine is not threadsafe.  It should be called from a single
           29  +** thread to initialized the library in a multi-threaded system.  Other
           30  +** threads should avoid using the sqlite4_env object until after it has
           31  +** completely initialized.
           32  +*/
           33  +int sqlite4_initialize(sqlite4_env *pEnv){
           34  +  MUTEX_LOGIC( sqlite4_mutex *pMaster; )       /* The main static mutex */
           35  +  int rc;                                      /* Result code */
           36  +
           37  +  if( pEnv==0 ) pEnv = &sqlite4DefaultEnv;
           38  +
           39  +  /* If SQLite is already completely initialized, then this call
           40  +  ** to sqlite4_initialize() should be a no-op.  But the initialization
           41  +  ** must be complete.  So isInit must not be set until the very end
           42  +  ** of this routine.
           43  +  */
           44  +  if( pEnv->isInit ) return SQLITE4_OK;
           45  +
           46  +  /* Initialize the mutex subsystem
           47  +  */
           48  +  rc = sqlite4MutexInit(pEnv);
           49  +  if( rc ){
           50  +    sqlite4MallocEnd(pEnv);
           51  +    return rc;
           52  +  }
           53  +
           54  +  /* Initialize the memory allocation subsystem
           55  +  */
           56  +  rc = sqlite4MallocInit(pEnv);
           57  +  if( rc ) return rc;
           58  +
           59  +  /* Create required mutexes
           60  +  */
           61  +  if( pEnv->bCoreMutex ){
           62  +    pEnv->pMemMutex = sqlite4MutexAlloc(pEnv, SQLITE4_MUTEX_FAST);
           63  +    pEnv->pPrngMutex = sqlite4MutexAlloc(pEnv, SQLITE4_MUTEX_FAST);
           64  +    pEnv->pFactoryMutex = sqlite4MutexAlloc(pEnv, SQLITE4_MUTEX_FAST);
           65  +    if( pEnv->pMemMutex==0
           66  +     || pEnv->pPrngMutex==0
           67  +     || pEnv->pFactoryMutex==0
           68  +    ){
           69  +      rc = SQLITE4_NOMEM;
           70  +    }
           71  +  }else{
           72  +    pEnv->pMemMutex = 0;
           73  +    pEnv->pPrngMutex = 0;
           74  +  }
           75  +  pEnv->isInit = 1;
           76  +
           77  +  sqlite4OsInit(pEnv);
           78  +
           79  +  /* Register global functions */
           80  +  if( rc==SQLITE4_OK ){
           81  +    sqlite4RegisterGlobalFunctions(pEnv);
           82  +  }
           83  +
           84  +  /* The following is just a sanity check to make sure SQLite has
           85  +  ** been compiled correctly.  It is important to run this code, but
           86  +  ** we don't want to run it too often and soak up CPU cycles for no
           87  +  ** reason.  So we run it once during initialization.
           88  +  */
           89  +#ifndef NDEBUG
           90  +#ifndef SQLITE4_OMIT_FLOATING_POINT
           91  +  /* This section of code's only "output" is via assert() statements. */
           92  +  if ( rc==SQLITE4_OK ){
           93  +    u64 x = (((u64)1)<<63)-1;
           94  +    double y;
           95  +    assert(sizeof(x)==8);
           96  +    assert(sizeof(x)==sizeof(y));
           97  +    memcpy(&y, &x, 8);
           98  +    assert( sqlite4IsNaN(y) );
           99  +  }
          100  +#endif
          101  +#endif
          102  +
          103  +  return rc;
          104  +}
          105  +
          106  +/*
          107  +** Undo the effects of sqlite4_initialize().  Must not be called while
          108  +** there are outstanding database connections or memory allocations or
          109  +** while any part of SQLite is otherwise in use in any thread.  This
          110  +** routine is not threadsafe.  But it is safe to invoke this routine
          111  +** on when SQLite is already shut down.  If SQLite is already shut down
          112  +** when this routine is invoked, then this routine is a harmless no-op.
          113  +*/
          114  +int sqlite4_shutdown(sqlite4_env *pEnv){
          115  +  if( pEnv==0 ) pEnv = &sqlite4DefaultEnv;
          116  +  if( pEnv->isInit ){
          117  +    KVFactory *pMkr;
          118  +    sqlite4_mutex_free(pEnv->pFactoryMutex);
          119  +    sqlite4_mutex_free(pEnv->pPrngMutex);
          120  +    sqlite4_mutex_free(pEnv->pMemMutex);
          121  +    pEnv->pMemMutex = 0;
          122  +    while( (pMkr = pEnv->pFactory)!=0 && pMkr->isPerm==0 ){
          123  +      KVFactory *pNext = pMkr->pNext;
          124  +      sqlite4_free(pEnv, pMkr);
          125  +      pMkr = pNext;
          126  +    }
          127  +    sqlite4MutexEnd(pEnv);
          128  +    sqlite4MallocEnd(pEnv);
          129  +    pEnv->isInit = 0;
          130  +  }
          131  +  return SQLITE4_OK;
          132  +}
          133  +
          134  +/*
          135  +** Return the size of an sqlite4_env object
          136  +*/
          137  +int sqlite4_env_size(void){ return sizeof(sqlite4_env); }
          138  +
          139  +/*
          140  +** This API allows applications to modify the configuration described by
          141  +** an sqlite4_env object.
          142  +*/
          143  +int sqlite4_env_config(sqlite4_env *pEnv, int op, ...){
          144  +  va_list ap;
          145  +  int rc = SQLITE4_OK;
          146  +
          147  +  if( pEnv==0 ) pEnv = sqlite4_env_default();
          148  +
          149  +  va_start(ap, op);
          150  +  switch( op ){
          151  +    /*
          152  +    ** sqlite4_env_config(pEnv, SQLITE4_ENVCONFIG_INIT, template);
          153  +    **
          154  +    ** Turn bulk memory into a new sqlite4_env object.  The template is
          155  +    ** a prior sqlite4_env that is used as a template in initializing the
          156  +    ** new sqlite4_env object.  The size of the bulk memory must be at
          157  +    ** least as many bytes as returned from sqlite4_env_size().
          158  +    */
          159  +    case SQLITE4_ENVCONFIG_INIT: {
          160  +      /* Disable all mutexing */
          161  +      sqlite4_env *pTemplate = va_arg(ap, sqlite4_env*);
          162  +      int n = pTemplate->nByte;
          163  +      if( n>sizeof(sqlite4_env) ) n = sizeof(sqlite4_env);
          164  +      memcpy(pEnv, pTemplate, n);
          165  +      pEnv->pFactory = &sqlite4BuiltinFactory;
          166  +      pEnv->isInit = 0;
          167  +      break;
          168  +    }
          169  +
          170  +    /* Mutex configuration options are only available in a threadsafe
          171  +    ** compile. 
          172  +    */
          173  +#if defined(SQLITE4_THREADSAFE) && SQLITE4_THREADSAFE>0
          174  +    /*
          175  +    ** sqlite4_env_config(pEnv, SQLITE4_ENVCONFIG_SINGLETHREAD);
          176  +    **
          177  +    ** Configure this environment for a single-threaded application.
          178  +    */
          179  +    case SQLITE4_ENVCONFIG_SINGLETHREAD: {
          180  +      /* Disable all mutexing */
          181  +      if( pEnv->isInit ){ rc = SQLITE4_MISUSE; break; }
          182  +      pEnv->bCoreMutex = 0;
          183  +      pEnv->bFullMutex = 0;
          184  +      break;
          185  +    }
          186  +
          187  +    /*
          188  +    ** sqlite4_env_config(pEnv, SQLITE4_ENVCONFIG_MULTITHREAD);
          189  +    **
          190  +    ** Configure this environment for a multi-threaded application where
          191  +    ** the same database connection is never used by more than a single
          192  +    ** thread at a time.
          193  +    */
          194  +    case SQLITE4_ENVCONFIG_MULTITHREAD: {
          195  +      /* Disable mutexing of database connections */
          196  +      /* Enable mutexing of core data structures */
          197  +      if( pEnv->isInit ){ rc = SQLITE4_MISUSE; break; }
          198  +      pEnv->bCoreMutex = 1;
          199  +      pEnv->bFullMutex = 0;
          200  +      break;
          201  +    }
          202  +
          203  +    /*
          204  +    ** sqlite4_env_config(pEnv, SQLITE4_ENVCONFIG_SERIALIZED);
          205  +    **
          206  +    ** Configure this environment for an unrestricted multi-threaded
          207  +    ** application where any thread can do whatever it wants with any
          208  +    ** database connection at any time.
          209  +    */
          210  +    case SQLITE4_ENVCONFIG_SERIALIZED: {
          211  +      /* Enable all mutexing */
          212  +      if( pEnv->isInit ){ rc = SQLITE4_MISUSE; break; }
          213  +      pEnv->bCoreMutex = 1;
          214  +      pEnv->bFullMutex = 1;
          215  +      break;
          216  +    }
          217  +
          218  +    /*
          219  +    ** sqlite4_env_config(pEnv, SQLITE4_ENVCONFIG_MUTEXT, sqlite4_mutex_methods*)
          220  +    **
          221  +    ** Configure this environment to use the mutex routines specified by the
          222  +    ** argument.
          223  +    */
          224  +    case SQLITE4_ENVCONFIG_MUTEX: {
          225  +      /* Specify an alternative mutex implementation */
          226  +      if( pEnv->isInit ){ rc = SQLITE4_MISUSE; break; }
          227  +      pEnv->mutex = *va_arg(ap, sqlite4_mutex_methods*);
          228  +      break;
          229  +    }
          230  +
          231  +    /*
          232  +    ** sqlite4_env_config(p, SQLITE4_ENVCONFIG_GETMUTEX, sqlite4_mutex_methods*)
          233  +    **
          234  +    ** Copy the mutex routines in use by this environment into the structure
          235  +    ** given in the argument.
          236  +    */
          237  +    case SQLITE4_ENVCONFIG_GETMUTEX: {
          238  +      /* Retrieve the current mutex implementation */
          239  +      *va_arg(ap, sqlite4_mutex_methods*) = pEnv->mutex;
          240  +      break;
          241  +    }
          242  +#endif
          243  +
          244  +
          245  +    /*
          246  +    ** sqlite4_env_config(p, SQLITE4_ENVCONFIG_MALLOC, sqlite4_mem_methods*)
          247  +    **
          248  +    ** Set the memory allocation routines to be used by this environment.
          249  +    */
          250  +    case SQLITE4_ENVCONFIG_MALLOC: {
          251  +      /* Specify an alternative malloc implementation */
          252  +      if( pEnv->isInit ) return SQLITE4_MISUSE;
          253  +      pEnv->m = *va_arg(ap, sqlite4_mem_methods*);
          254  +      break;
          255  +    }
          256  +
          257  +    /*
          258  +    ** sqlite4_env_config(p, SQLITE4_ENVCONFIG_GETMALLOC, sqlite4_mem_methods*)
          259  +    **
          260  +    ** Copy the memory allocation routines in use by this environment
          261  +    ** into the structure given in the argument.
          262  +    */
          263  +    case SQLITE4_ENVCONFIG_GETMALLOC: {
          264  +      /* Retrieve the current malloc() implementation */
          265  +      if( pEnv->m.xMalloc==0 ) sqlite4MemSetDefault(pEnv);
          266  +      *va_arg(ap, sqlite4_mem_methods*) = pEnv->m;
          267  +      break;
          268  +    }
          269  +
          270  +    /* sqlite4_env_config(p, SQLITE4_ENVCONFIG_MEMSTAT, int onoff);
          271  +    **
          272  +    ** Enable or disable collection of memory usage statistics according to
          273  +    ** the onoff parameter.  
          274  +    */
          275  +    case SQLITE4_ENVCONFIG_MEMSTATUS: {
          276  +      /* Enable or disable the malloc status collection */
          277  +      pEnv->bMemstat = va_arg(ap, int);
          278  +      break;
          279  +    }
          280  +
          281  +    /*
          282  +    ** sqlite4_env_config(p, SQLITE4_ENVCONFIG_LOOKASIDE, size, count);
          283  +    **
          284  +    ** Set the default lookaside memory settings for all subsequent
          285  +    ** database connections constructed in this environment.  The size
          286  +    ** parameter is the size of each lookaside memory buffer and the
          287  +    ** count parameter is the number of lookaside buffers.  Set both
          288  +    ** to zero to disable lookaside memory.
          289  +    */
          290  +    case SQLITE4_ENVCONFIG_LOOKASIDE: {
          291  +      pEnv->szLookaside = va_arg(ap, int);
          292  +      pEnv->nLookaside = va_arg(ap, int);
          293  +      break;
          294  +    }
          295  +    
          296  +    /*
          297  +    ** sqlite4_env_config(p, SQLITE4_ENVCONFIG_LOG, xOutput, pArg);
          298  +    **
          299  +    ** Set the log function that is called in response to sqlite4_log()
          300  +    ** calls.
          301  +    */
          302  +    case SQLITE4_ENVCONFIG_LOG: {
          303  +      /* MSVC is picky about pulling func ptrs from va lists.
          304  +      ** http://support.microsoft.com/kb/47961
          305  +      ** pEnv->xLog = va_arg(ap, void(*)(void*,int,const char*));
          306  +      */
          307  +      typedef void(*LOGFUNC_t)(void*,int,const char*);
          308  +      pEnv->xLog = va_arg(ap, LOGFUNC_t);
          309  +      pEnv->pLogArg = va_arg(ap, void*);
          310  +      break;
          311  +    }
          312  +
          313  +    /*
          314  +    ** sqlite4_env_config(pEnv, SQLITE4_ENVCONFIG_KVSTORE_PUSH, zName,xFactory);
          315  +    **
          316  +    ** Push a new KVStore factory onto the factory stack.  The new factory
          317  +    ** takes priority over prior factories.
          318  +    */
          319  +    case SQLITE4_ENVCONFIG_KVSTORE_PUSH: {
          320  +      const char *zName = va_arg(ap, const char*);
          321  +      int nName = sqlite4Strlen30(zName);
          322  +      KVFactory *pMkr = sqlite4_malloc(pEnv, sizeof(*pMkr)+nName+1);
          323  +      char *z;
          324  +      if( pMkr==0 ) return SQLITE4_NOMEM;
          325  +      z = (char*)&pMkr[1];
          326  +      memcpy(z, zName, nName+1);
          327  +      memset(pMkr, 0, sizeof(*pMkr));
          328  +      pMkr->zName = z;
          329  +      pMkr->xFactory = va_arg(ap, sqlite4_kvfactory);
          330  +      sqlite4_mutex_enter(pEnv->pFactoryMutex);
          331  +      pMkr->pNext = pEnv->pFactory;
          332  +      pEnv->pFactory = pMkr;
          333  +      sqlite4_mutex_leave(pEnv->pFactoryMutex);
          334  +      break;
          335  +    }
          336  +
          337  +    /*
          338  +    ** sqlite4_env_config(pEnv, SQLITE4_ENVCONFIG_KVSTORE_POP, zName, &pxFact);
          339  +    **
          340  +    ** Remove a KVStore factory from the stack.
          341  +    */
          342  +    /*
          343  +    ** sqlite4_env_config(pEnv, SQLITE4_ENVCONFIG_KVSTORE_GET, zName, &pxFact);
          344  +    **
          345  +    ** Get the current factory pointer with the given name but leave the
          346  +    ** factory on the stack.
          347  +    */
          348  +    case SQLITE4_ENVCONFIG_KVSTORE_POP:
          349  +    case SQLITE4_ENVCONFIG_KVSTORE_GET: {
          350  +      typedef int (**PxFact)(sqlite4_env*,KVStore**,const char*,unsigned);
          351  +      const char *zName = va_arg(ap, const char*);
          352  +      KVFactory *pMkr, **ppPrev;
          353  +      PxFact pxFact;
          354  +
          355  +      pxFact = va_arg(ap,PxFact);
          356  +      *pxFact = 0;
          357  +      sqlite4_mutex_enter(pEnv->pFactoryMutex);
          358  +      ppPrev = &pEnv->pFactory;
          359  +      pMkr = *ppPrev;
          360  +      while( pMkr && strcmp(zName, pMkr->zName)!=0 ){
          361  +        ppPrev = &pMkr->pNext;
          362  +        pMkr = *ppPrev;
          363  +      }
          364  +      if( pMkr ){
          365  +        *pxFact = pMkr->xFactory;
          366  +        if( op==SQLITE4_ENVCONFIG_KVSTORE_POP && pMkr->isPerm==0 ){
          367  +          *ppPrev = pMkr->pNext;
          368  +          sqlite4_free(pEnv, pMkr);
          369  +        }
          370  +      }
          371  +      sqlite4_mutex_leave(pEnv->pFactoryMutex);
          372  +      break;
          373  +    }
          374  +
          375  +
          376  +    default: {
          377  +      rc = SQLITE4_ERROR;
          378  +      break;
          379  +    }
          380  +  }
          381  +  va_end(ap);
          382  +  return rc;
          383  +}
          384  +
          385  +
          386  +/*
          387  +** Default factory objects
          388  +*/
          389  +static KVFactory memFactory = {
          390  +   0,
          391  +   "temp",
          392  +   sqlite4KVStoreOpenMem,
          393  +   1
          394  +};
          395  +KVFactory sqlite4BuiltinFactory = {
          396  +   &memFactory,
          397  +   "main",
          398  +   sqlite4KVStoreOpenLsm,
          399  +   1
          400  +};
          401  +
          402  +/*
          403  +** The following singleton contains the global configuration for
          404  +** the SQLite library.
          405  +*/
          406  +struct sqlite4_env sqlite4DefaultEnv = {
          407  +   sizeof(sqlite4_env),       /* nByte */
          408  +   1,                         /* iVersion */
          409  +   SQLITE4_DEFAULT_MEMSTATUS, /* bMemstat */
          410  +   1,                         /* bCoreMutex */
          411  +   SQLITE4_THREADSAFE==1,     /* bFullMutex */
          412  +   0x7ffffffe,                /* mxStrlen */
          413  +   128,                       /* szLookaside */
          414  +   500,                       /* nLookaside */
          415  +   &sqlite4MMSystem,          /* pMM */
          416  +   {0,0,0,0,0,0,0,0,0},       /* m */
          417  +   {0,0,0,0,0,0,0,0,0,0},     /* mutex */
          418  +   (void*)0,                  /* pHeap */
          419  +   0,                         /* nHeap */
          420  +   0, 0,                      /* mnHeap, mxHeap */
          421  +   0,                         /* mxParserStack */
          422  +   &sqlite4BuiltinFactory,    /* pFactory */
          423  +   sqlite4OsRandomness,       /* xRandomness */
          424  +   sqlite4OsCurrentTime,      /* xCurrentTime */
          425  +   /* All the rest should always be initialized to zero */
          426  +   0,                         /* isInit */
          427  +   0,                         /* pFactoryMutex */
          428  +   0,                         /* pPrngMutex */
          429  +   0, 0,                      /* prngX, prngY */
          430  +   0,                         /* xLog */
          431  +   0,                         /* pLogArg */
          432  +   0,                         /* bLocaltimeFault */
          433  +   0,                         /* pMemMutex */
          434  +   {0,0,0,0},                 /* nowValue[] */
          435  +   {0,0,0,0},                 /* mxValue[] */
          436  +   {0,}                       /* hashGlobalFunc */
          437  +};
          438  +
          439  +/*
          440  +** Return the default environment
          441  +*/
          442  +sqlite4_env *sqlite4_env_default(void){ return &sqlite4DefaultEnv; }

Changes to src/func.c.

  1265   1265   */
  1266   1266   static void countStep(sqlite4_context *context, int argc, sqlite4_value **argv){
  1267   1267     CountCtx *p;
  1268   1268     p = sqlite4_aggregate_context(context, sizeof(*p));
  1269   1269     if( (argc==0 || SQLITE4_NULL!=sqlite4_value_type(argv[0])) && p ){
  1270   1270       p->n++;
  1271   1271     }
  1272         -
  1273         -#ifndef SQLITE4_OMIT_DEPRECATED
  1274         -  /* The sqlite4_aggregate_count() function is deprecated.  But just to make
  1275         -  ** sure it still operates correctly, verify that its count agrees with our 
  1276         -  ** internal count when using count(*) and when the total count can be
  1277         -  ** expressed as a 32-bit integer. */
  1278         -  assert( argc==1 || p==0 || p->n>0x7fffffff
  1279         -          || p->n==sqlite4_aggregate_count(context) );
  1280         -#endif
  1281   1272   }   
  1282   1273   static void countFinalize(sqlite4_context *context){
  1283   1274     CountCtx *p;
  1284   1275     p = sqlite4_aggregate_context(context, 0);
  1285   1276     sqlite4_result_int64(context, p ? p->n : 0);
  1286   1277   }
  1287   1278   

Changes to src/global.c.

   125    125     0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,  /* e0..e7    ........ */
   126    126     0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,  /* e8..ef    ........ */
   127    127     0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,  /* f0..f7    ........ */
   128    128     0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40   /* f8..ff    ........ */
   129    129   };
   130    130   #endif
   131    131   
   132         -/*
   133         -** Default factory objects
   134         -*/
   135         -static KVFactory memFactory = {
   136         -   0,
   137         -   "temp",
   138         -   sqlite4KVStoreOpenMem,
   139         -   1
   140         -};
   141         -KVFactory sqlite4BuiltinFactory = {
   142         -   &memFactory,
   143         -   "main",
   144         -   sqlite4KVStoreOpenLsm,
   145         -   1
   146         -};
   147         -
   148         -/*
   149         -** The following singleton contains the global configuration for
   150         -** the SQLite library.
   151         -*/
   152         -struct sqlite4_env sqlite4DefaultEnv = {
   153         -   sizeof(sqlite4_env),       /* nByte */
   154         -   1,                         /* iVersion */
   155         -   SQLITE4_DEFAULT_MEMSTATUS, /* bMemstat */
   156         -   1,                         /* bCoreMutex */
   157         -   SQLITE4_THREADSAFE==1,     /* bFullMutex */
   158         -   0x7ffffffe,                /* mxStrlen */
   159         -   128,                       /* szLookaside */
   160         -   500,                       /* nLookaside */
   161         -   {0,0,0,0,0,0,0,0,0},       /* m */
   162         -   {0,0,0,0,0,0,0,0,0,0},     /* mutex */
   163         -   (void*)0,                  /* pHeap */
   164         -   0,                         /* nHeap */
   165         -   0, 0,                      /* mnHeap, mxHeap */
   166         -   0,                         /* mxParserStack */
   167         -   &sqlite4BuiltinFactory,    /* pFactory */
   168         -   sqlite4OsRandomness,       /* xRandomness */
   169         -   sqlite4OsCurrentTime,      /* xCurrentTime */
   170         -   /* All the rest should always be initialized to zero */
   171         -   0,                         /* isInit */
   172         -   0,                         /* pFactoryMutex */
   173         -   0,                         /* pPrngMutex */
   174         -   0, 0,                      /* prngX, prngY */
   175         -   0,                         /* xLog */
   176         -   0,                         /* pLogArg */
   177         -   0,                         /* bLocaltimeFault */
   178         -   0,                         /* pMemMutex */
   179         -   {0,0,0,0},                 /* nowValue[] */
   180         -   {0,0,0,0},                 /* mxValue[] */
   181         -   {0,}                       /* hashGlobalFunc */
   182         -};
   183         -
   184         -/*
   185         -** Return the default environment
   186         -*/
   187         -sqlite4_env *sqlite4_env_default(void){ return &sqlite4DefaultEnv; }
   188         -
   189    132   
   190    133   /*
   191    134   ** Constant tokens for values 0 and 1.
   192    135   */
   193    136   const Token sqlite4IntTokens[] = {
   194    137      { "0", 1 },
   195    138      { "1", 1 }

Changes to src/main.c.

    60     60   ** SQLITE4_ENABLE_IOTRACE is enabled, then messages describing
    61     61   ** I/O active are written using this function.  These messages
    62     62   ** are intended for debugging activity only.
    63     63   */
    64     64   void (*sqlite4IoTrace)(const char*, ...) = 0;
    65     65   #endif
    66     66   
    67         -/*
    68         -** Initialize SQLite.  
    69         -**
    70         -** This routine must be called to initialize the run-time environment
    71         -** As long as you do not compile with SQLITE4_OMIT_AUTOINIT
    72         -** this routine will be called automatically by key routines such as
    73         -** sqlite4_open().  
    74         -**
    75         -** This routine is a no-op except on its very first call for a given
    76         -** sqlite4_env object, or for the first call after a call to sqlite4_shutdown.
    77         -**
    78         -** This routine is not threadsafe.  It should be called from a single
    79         -** thread to initialized the library in a multi-threaded system.  Other
    80         -** threads should avoid using the sqlite4_env object until after it has
    81         -** completely initialized.
    82         -*/
    83         -int sqlite4_initialize(sqlite4_env *pEnv){
    84         -  MUTEX_LOGIC( sqlite4_mutex *pMaster; )       /* The main static mutex */
    85         -  int rc;                                      /* Result code */
    86         -
    87         -  if( pEnv==0 ) pEnv = &sqlite4DefaultEnv;
    88         -
    89         -  /* If SQLite is already completely initialized, then this call
    90         -  ** to sqlite4_initialize() should be a no-op.  But the initialization
    91         -  ** must be complete.  So isInit must not be set until the very end
    92         -  ** of this routine.
    93         -  */
    94         -  if( pEnv->isInit ) return SQLITE4_OK;
    95         -
    96         -  /* Initialize the mutex subsystem
    97         -  */
    98         -  rc = sqlite4MutexInit(pEnv);
    99         -  if( rc ){
   100         -    sqlite4MallocEnd(pEnv);
   101         -    return rc;
   102         -  }
   103         -
   104         -  /* Initialize the memory allocation subsystem
   105         -  */
   106         -  rc = sqlite4MallocInit(pEnv);
   107         -  if( rc ) return rc;
   108         -
   109         -  /* Create required mutexes
   110         -  */
   111         -  if( pEnv->bCoreMutex ){
   112         -    pEnv->pMemMutex = sqlite4MutexAlloc(pEnv, SQLITE4_MUTEX_FAST);
   113         -    pEnv->pPrngMutex = sqlite4MutexAlloc(pEnv, SQLITE4_MUTEX_FAST);
   114         -    pEnv->pFactoryMutex = sqlite4MutexAlloc(pEnv, SQLITE4_MUTEX_FAST);
   115         -    if( pEnv->pMemMutex==0
   116         -     || pEnv->pPrngMutex==0
   117         -     || pEnv->pFactoryMutex==0
   118         -    ){
   119         -      rc = SQLITE4_NOMEM;
   120         -    }
   121         -  }else{
   122         -    pEnv->pMemMutex = 0;
   123         -    pEnv->pPrngMutex = 0;
   124         -  }
   125         -  pEnv->isInit = 1;
   126         -
   127         -  sqlite4OsInit(pEnv);
   128         -
   129         -  /* Register global functions */
   130         -  if( rc==SQLITE4_OK ){
   131         -    sqlite4RegisterGlobalFunctions(pEnv);
   132         -  }
   133         -
   134         -  /* The following is just a sanity check to make sure SQLite has
   135         -  ** been compiled correctly.  It is important to run this code, but
   136         -  ** we don't want to run it too often and soak up CPU cycles for no
   137         -  ** reason.  So we run it once during initialization.
   138         -  */
   139         -#ifndef NDEBUG
   140         -#ifndef SQLITE4_OMIT_FLOATING_POINT
   141         -  /* This section of code's only "output" is via assert() statements. */
   142         -  if ( rc==SQLITE4_OK ){
   143         -    u64 x = (((u64)1)<<63)-1;
   144         -    double y;
   145         -    assert(sizeof(x)==8);
   146         -    assert(sizeof(x)==sizeof(y));
   147         -    memcpy(&y, &x, 8);
   148         -    assert( sqlite4IsNaN(y) );
   149         -  }
   150         -#endif
   151         -#endif
   152         -
   153         -  return rc;
   154         -}
   155         -
   156         -/*
   157         -** Undo the effects of sqlite4_initialize().  Must not be called while
   158         -** there are outstanding database connections or memory allocations or
   159         -** while any part of SQLite is otherwise in use in any thread.  This
   160         -** routine is not threadsafe.  But it is safe to invoke this routine
   161         -** on when SQLite is already shut down.  If SQLite is already shut down
   162         -** when this routine is invoked, then this routine is a harmless no-op.
   163         -*/
   164         -int sqlite4_shutdown(sqlite4_env *pEnv){
   165         -  if( pEnv==0 ) pEnv = &sqlite4DefaultEnv;
   166         -  if( pEnv->isInit ){
   167         -    KVFactory *pMkr;
   168         -    sqlite4_mutex_free(pEnv->pFactoryMutex);
   169         -    sqlite4_mutex_free(pEnv->pPrngMutex);
   170         -    sqlite4_mutex_free(pEnv->pMemMutex);
   171         -    pEnv->pMemMutex = 0;
   172         -    while( (pMkr = pEnv->pFactory)!=0 && pMkr->isPerm==0 ){
   173         -      KVFactory *pNext = pMkr->pNext;
   174         -      sqlite4_free(pEnv, pMkr);
   175         -      pMkr = pNext;
   176         -    }
   177         -    sqlite4MutexEnd(pEnv);
   178         -    sqlite4MallocEnd(pEnv);
   179         -    pEnv->isInit = 0;
   180         -  }
   181         -  return SQLITE4_OK;
   182         -}
   183         -
   184         -/*
   185         -** Return the size of an sqlite4_env object
   186         -*/
   187         -int sqlite4_env_size(void){ return sizeof(sqlite4_env); }
   188         -
   189         -/*
   190         -** This API allows applications to modify the configuration described by
   191         -** an sqlite4_env object.
   192         -*/
   193         -int sqlite4_env_config(sqlite4_env *pEnv, int op, ...){
   194         -  va_list ap;
   195         -  int rc = SQLITE4_OK;
   196         -
   197         -  if( pEnv==0 ) pEnv = sqlite4_env_default();
   198         -
   199         -  va_start(ap, op);
   200         -  switch( op ){
   201         -    /*
   202         -    ** sqlite4_env_config(pEnv, SQLITE4_ENVCONFIG_INIT, template);
   203         -    **
   204         -    ** Turn bulk memory into a new sqlite4_env object.  The template is
   205         -    ** a prior sqlite4_env that is used as a template in initializing the
   206         -    ** new sqlite4_env object.  The size of the bulk memory must be at
   207         -    ** least as many bytes as returned from sqlite4_env_size().
   208         -    */
   209         -    case SQLITE4_ENVCONFIG_INIT: {
   210         -      /* Disable all mutexing */
   211         -      sqlite4_env *pTemplate = va_arg(ap, sqlite4_env*);
   212         -      int n = pTemplate->nByte;
   213         -      if( n>sizeof(sqlite4_env) ) n = sizeof(sqlite4_env);
   214         -      memcpy(pEnv, pTemplate, n);
   215         -      pEnv->pFactory = &sqlite4BuiltinFactory;
   216         -      pEnv->isInit = 0;
   217         -      break;
   218         -    }
   219         -
   220         -    /* Mutex configuration options are only available in a threadsafe
   221         -    ** compile. 
   222         -    */
   223         -#if defined(SQLITE4_THREADSAFE) && SQLITE4_THREADSAFE>0
   224         -    /*
   225         -    ** sqlite4_env_config(pEnv, SQLITE4_ENVCONFIG_SINGLETHREAD);
   226         -    **
   227         -    ** Configure this environment for a single-threaded application.
   228         -    */
   229         -    case SQLITE4_ENVCONFIG_SINGLETHREAD: {
   230         -      /* Disable all mutexing */
   231         -      if( pEnv->isInit ){ rc = SQLITE4_MISUSE; break; }
   232         -      pEnv->bCoreMutex = 0;
   233         -      pEnv->bFullMutex = 0;
   234         -      break;
   235         -    }
   236         -
   237         -    /*
   238         -    ** sqlite4_env_config(pEnv, SQLITE4_ENVCONFIG_MULTITHREAD);
   239         -    **
   240         -    ** Configure this environment for a multi-threaded application where
   241         -    ** the same database connection is never used by more than a single
   242         -    ** thread at a time.
   243         -    */
   244         -    case SQLITE4_ENVCONFIG_MULTITHREAD: {
   245         -      /* Disable mutexing of database connections */
   246         -      /* Enable mutexing of core data structures */
   247         -      if( pEnv->isInit ){ rc = SQLITE4_MISUSE; break; }
   248         -      pEnv->bCoreMutex = 1;
   249         -      pEnv->bFullMutex = 0;
   250         -      break;
   251         -    }
   252         -
   253         -    /*
   254         -    ** sqlite4_env_config(pEnv, SQLITE4_ENVCONFIG_MULTITHREAD);
   255         -    **
   256         -    ** Configure this environment for an unrestricted multi-threaded
   257         -    ** application where any thread can do whatever it wants with any
   258         -    ** database connection at any time.
   259         -    */
   260         -    case SQLITE4_ENVCONFIG_SERIALIZED: {
   261         -      /* Enable all mutexing */
   262         -      if( pEnv->isInit ){ rc = SQLITE4_MISUSE; break; }
   263         -      pEnv->bCoreMutex = 1;
   264         -      pEnv->bFullMutex = 1;
   265         -      break;
   266         -    }
   267         -
   268         -    /*
   269         -    ** sqlite4_env_config(pEnv, SQLITE4_ENVCONFIG_MUTEXT, sqlite4_mutex_methods*)
   270         -    **
   271         -    ** Configure this environment to use the mutex routines specified by the
   272         -    ** argument.
   273         -    */
   274         -    case SQLITE4_ENVCONFIG_MUTEX: {
   275         -      /* Specify an alternative mutex implementation */
   276         -      if( pEnv->isInit ){ rc = SQLITE4_MISUSE; break; }
   277         -      pEnv->mutex = *va_arg(ap, sqlite4_mutex_methods*);
   278         -      break;
   279         -    }
   280         -
   281         -    /*
   282         -    ** sqlite4_env_config(p, SQLITE4_ENVCONFIG_GETMUTEX, sqlite4_mutex_methods*)
   283         -    **
   284         -    ** Copy the mutex routines in use by this environment into the structure
   285         -    ** given in the argument.
   286         -    */
   287         -    case SQLITE4_ENVCONFIG_GETMUTEX: {
   288         -      /* Retrieve the current mutex implementation */
   289         -      *va_arg(ap, sqlite4_mutex_methods*) = pEnv->mutex;
   290         -      break;
   291         -    }
   292         -#endif
   293         -
   294         -
   295         -    /*
   296         -    ** sqlite4_env_config(p, SQLITE4_ENVCONFIG_MALLOC, sqlite4_mem_methods*)
   297         -    **
   298         -    ** Set the memory allocation routines to be used by this environment.
   299         -    */
   300         -    case SQLITE4_ENVCONFIG_MALLOC: {
   301         -      /* Specify an alternative malloc implementation */
   302         -      if( pEnv->isInit ) return SQLITE4_MISUSE;
   303         -      pEnv->m = *va_arg(ap, sqlite4_mem_methods*);
   304         -      break;
   305         -    }
   306         -
   307         -    /*
   308         -    ** sqlite4_env_config(p, SQLITE4_ENVCONFIG_GETMALLOC, sqlite4_mem_methods*)
   309         -    **
   310         -    ** Copy the memory allocation routines in use by this environment
   311         -    ** into the structure given in the argument.
   312         -    */
   313         -    case SQLITE4_ENVCONFIG_GETMALLOC: {
   314         -      /* Retrieve the current malloc() implementation */
   315         -      if( pEnv->m.xMalloc==0 ) sqlite4MemSetDefault(pEnv);
   316         -      *va_arg(ap, sqlite4_mem_methods*) = pEnv->m;
   317         -      break;
   318         -    }
   319         -
   320         -    /* sqlite4_env_config(p, SQLITE4_ENVCONFIG_MEMSTAT, int onoff);
   321         -    **
   322         -    ** Enable or disable collection of memory usage statistics according to
   323         -    ** the onoff parameter.  
   324         -    */
   325         -    case SQLITE4_ENVCONFIG_MEMSTATUS: {
   326         -      /* Enable or disable the malloc status collection */
   327         -      pEnv->bMemstat = va_arg(ap, int);
   328         -      break;
   329         -    }
   330         -
   331         -    /*
   332         -    ** sqlite4_env_config(p, SQLITE4_ENVCONFIG_LOOKASIDE, size, count);
   333         -    **
   334         -    ** Set the default lookaside memory settings for all subsequent
   335         -    ** database connections constructed in this environment.  The size
   336         -    ** parameter is the size of each lookaside memory buffer and the
   337         -    ** count parameter is the number of lookaside buffers.  Set both
   338         -    ** to zero to disable lookaside memory.
   339         -    */
   340         -    case SQLITE4_ENVCONFIG_LOOKASIDE: {
   341         -      pEnv->szLookaside = va_arg(ap, int);
   342         -      pEnv->nLookaside = va_arg(ap, int);
   343         -      break;
   344         -    }
   345         -    
   346         -    /*
   347         -    ** sqlite4_env_config(p, SQLITE4_ENVCONFIG_LOG, xOutput, pArg);
   348         -    **
   349         -    ** Set the log function that is called in response to sqlite4_log()
   350         -    ** calls.
   351         -    */
   352         -    case SQLITE4_ENVCONFIG_LOG: {
   353         -      /* MSVC is picky about pulling func ptrs from va lists.
   354         -      ** http://support.microsoft.com/kb/47961
   355         -      ** pEnv->xLog = va_arg(ap, void(*)(void*,int,const char*));
   356         -      */
   357         -      typedef void(*LOGFUNC_t)(void*,int,const char*);
   358         -      pEnv->xLog = va_arg(ap, LOGFUNC_t);
   359         -      pEnv->pLogArg = va_arg(ap, void*);
   360         -      break;
   361         -    }
   362         -
   363         -    /*
   364         -    ** sqlite4_env_config(pEnv, SQLITE4_ENVCONFIG_KVSTORE_PUSH, zName,xFactory);
   365         -    **
   366         -    ** Push a new KVStore factory onto the factory stack.  The new factory
   367         -    ** takes priority over prior factories.
   368         -    */
   369         -    case SQLITE4_ENVCONFIG_KVSTORE_PUSH: {
   370         -      const char *zName = va_arg(ap, const char*);
   371         -      int nName = sqlite4Strlen30(zName);
   372         -      KVFactory *pMkr = sqlite4_malloc(pEnv, sizeof(*pMkr)+nName+1);
   373         -      char *z;
   374         -      if( pMkr==0 ) return SQLITE4_NOMEM;
   375         -      z = (char*)&pMkr[1];
   376         -      memcpy(z, zName, nName+1);
   377         -      memset(pMkr, 0, sizeof(*pMkr));
   378         -      pMkr->zName = z;
   379         -      pMkr->xFactory = va_arg(ap, sqlite4_kvfactory);
   380         -      sqlite4_mutex_enter(pEnv->pFactoryMutex);
   381         -      pMkr->pNext = pEnv->pFactory;
   382         -      pEnv->pFactory = pMkr;
   383         -      sqlite4_mutex_leave(pEnv->pFactoryMutex);
   384         -      break;
   385         -    }
   386         -
   387         -    /*
   388         -    ** sqlite4_env_config(pEnv, SQLITE4_ENVCONFIG_KVSTORE_POP, zName, &pxFact);
   389         -    **
   390         -    ** Remove a KVStore factory from the stack.
   391         -    */
   392         -    /*
   393         -    ** sqlite4_env_config(pEnv, SQLITE4_ENVCONFIG_KVSTORE_GET, zName, &pxFact);
   394         -    **
   395         -    ** Get the current factory pointer with the given name but leave the
   396         -    ** factory on the stack.
   397         -    */
   398         -    case SQLITE4_ENVCONFIG_KVSTORE_POP:
   399         -    case SQLITE4_ENVCONFIG_KVSTORE_GET: {
   400         -      typedef int (**PxFact)(sqlite4_env*,KVStore**,const char*,unsigned);
   401         -      const char *zName = va_arg(ap, const char*);
   402         -      KVFactory *pMkr, **ppPrev;
   403         -      PxFact pxFact;
   404         -
   405         -      pxFact = va_arg(ap,PxFact);
   406         -      *pxFact = 0;
   407         -      sqlite4_mutex_enter(pEnv->pFactoryMutex);
   408         -      ppPrev = &pEnv->pFactory;
   409         -      pMkr = *ppPrev;
   410         -      while( pMkr && strcmp(zName, pMkr->zName)!=0 ){
   411         -        ppPrev = &pMkr->pNext;
   412         -        pMkr = *ppPrev;
   413         -      }
   414         -      if( pMkr ){
   415         -        *pxFact = pMkr->xFactory;
   416         -        if( op==SQLITE4_ENVCONFIG_KVSTORE_POP && pMkr->isPerm==0 ){
   417         -          *ppPrev = pMkr->pNext;
   418         -          sqlite4_free(pEnv, pMkr);
   419         -        }
   420         -      }
   421         -      sqlite4_mutex_leave(pEnv->pFactoryMutex);
   422         -      break;
   423         -    }
   424         -
   425         -
   426         -    default: {
   427         -      rc = SQLITE4_ERROR;
   428         -      break;
   429         -    }
   430         -  }
   431         -  va_end(ap);
   432         -  return rc;
   433         -}
   434         -
   435     67   /*
   436     68   ** Set up the lookaside buffers for a database connection.
   437     69   ** Return SQLITE4_OK on success.  
   438     70   ** If lookaside is already active, return SQLITE4_BUSY.
   439     71   **
   440     72   ** The sz parameter is the number of bytes in each lookaside slot.
   441     73   ** The cnt parameter is the number of slots.  If pStart is NULL the
................................................................................
  1915   1547     db->xCollNeeded16 = xCollNeeded16;
  1916   1548     db->pCollNeededArg = pCollNeededArg;
  1917   1549     sqlite4_mutex_leave(db->mutex);
  1918   1550     return SQLITE4_OK;
  1919   1551   }
  1920   1552   #endif /* SQLITE4_OMIT_UTF16 */
  1921   1553   
  1922         -#ifndef SQLITE4_OMIT_DEPRECATED
  1923         -/*
  1924         -** This function is now an anachronism. It used to be used to recover from a
  1925         -** malloc() failure, but SQLite now does this automatically.
  1926         -*/
  1927         -int sqlite4_global_recover(void){
  1928         -  return SQLITE4_OK;
  1929         -}
  1930         -#endif
  1931         -
  1932   1554   /*
  1933   1555   ** Test to see whether or not the database connection is in autocommit
  1934   1556   ** mode.  Return TRUE if it is and FALSE if not.  Autocommit mode is on
  1935   1557   ** by default.  Autocommit is disabled by a BEGIN statement and reenabled
  1936   1558   ** by the next COMMIT or ROLLBACK.
  1937         -**
  1938         -******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
  1939   1559   */
  1940   1560   int sqlite4_get_autocommit(sqlite4 *db){
  1941   1561     return (db->pSavepoint==0);
  1942   1562   }
  1943   1563   
  1944   1564   /*
  1945   1565   ** The following routines are subtitutes for constants SQLITE4_CORRUPT,

Changes to src/mem.c.

    10     10   **
    11     11   *************************************************************************
    12     12   **
    13     13   ** This file contains the implementation of the "sqlite4_mm" memory
    14     14   ** allocator object.
    15     15   */
    16     16   #include "sqlite4.h"
    17         -#include "mem.h"
    18     17   #include <stdlib.h>
    19     18   
    20     19   /*************************************************************************
    21     20   ** The SQLITE4_MM_SYSTEM memory allocator.  This allocator uses the
    22     21   ** malloc/realloc/free from the system library.  It also tries to use
    23     22   ** the memory allocation sizer from the system library if such a routine
    24     23   ** exists.  If there is no msize in the system library, then each allocation
................................................................................
    96     95   #endif
    97     96   
    98     97   #endif /* __APPLE__ or not __APPLE__ */
    99     98   
   100     99   /*
   101    100   ** Implementations of core routines
   102    101   */
   103         -static void *mmSysMalloc(sqlite4_mm *pMM, sqlite4_int64 iSize){
          102  +static void *mmSysMalloc(sqlite4_mm *pMM, sqlite4_size_t iSize){
   104    103   #ifdef SQLITE4_MALLOCSIZE
   105    104     return SQLITE4_MALLOC(iSize);
   106    105   #else
   107    106     unsigned char *pRes = SQLITE4_MALLOC(iSize+8);
   108    107     if( pRes ){
   109         -    *(sqlite4_int64*)pRes = iSize;
          108  +    *(sqlite4_size_t*)pRes = iSize;
   110    109       pRes += 8;
   111    110     }
   112    111     return pRes;
   113    112   #endif
   114    113   }
   115         -static void *mmSysRealloc(sqlite4_mm *pMM, void *pOld, sqlite4_int64 iSz){
          114  +static void *mmSysRealloc(sqlite4_mm *pMM, void *pOld, sqlite4_size_t iSz){
   116    115   #ifdef SQLITE4_MALLOCSIZE
   117    116     return SQLITE4_REALLOC(pOld, iSz);
   118    117   #else
   119    118     unsigned char *pRes;
   120    119     if( pOld==0 ) return mmSysMalloc(pMM, iSz);
   121    120     pRes = (unsigned char*)pOld;
   122    121     pRes -= 8;
   123    122     pRes = SQLITE4_REALLOC(pRes, iSz+8);
   124    123     if( pRes ){
   125         -    *(sqlite4_int64*)pRes = iSz;
          124  +    *(sqlite4_size_t*)pRes = iSz;
   126    125       pRes += 8;
   127    126     }
   128    127     return pRes;
   129    128   #endif 
   130    129   }
   131    130   static void mmSysFree(sqlite4_mm *pNotUsed, void *pOld){
   132    131   #ifdef SQLITE4_MALLOCSIZE
................................................................................
   135    134     unsigned char *pRes;
   136    135     if( pOld==0 ) return;
   137    136     pRes = (unsigned char *)pOld;
   138    137     pRes -= 8;
   139    138     SQLITE4_FREE(pRes);
   140    139   #endif
   141    140   }
   142         -static sqlite4_int64 mmSysMsize(sqlite4_mm *pNotUsed, void *pOld){
          141  +static sqlite4_size_t mmSysMsize(sqlite4_mm *pNotUsed, void *pOld){
   143    142   #ifdef SQLITE4_MALLOCSIZE
   144    143     return SQLITE4_MALLOCSIZE(pOld);
   145    144   #else
   146    145     unsigned char *pX;
   147    146     if( pOld==0 ) return 0;
   148    147     pX = (unsigned char *)pOld;
   149    148     pX -= 8;
   150         -  return *(sqlite4_int64*)pX;
          149  +  return *(sqlite4_size_t*)pX;
   151    150   #endif
   152    151   }
   153    152   
   154    153   static const sqlite4_mm_methods mmSysMethods = {
   155    154     /* iVersion */    1,
   156    155     /* xMalloc  */    mmSysMalloc,
   157    156     /* xRealloc */    mmSysRealloc,
   158    157     /* xFree    */    mmSysFree,
   159    158     /* xMsize   */    mmSysMsize,
   160    159     /* xMember  */    0,
   161    160     /* xBenign  */    0,
          161  +  /* xStat    */    0,
   162    162     /* xFinal   */    0
   163    163   };
   164         -static sqlite4_mm mmSystem =  {
          164  +sqlite4_mm sqlite4MMSystem =  {
   165    165     /* pMethods */    &mmSysMethods
   166    166   };
   167    167   
          168  +/* The system memory allocator is the default. */
          169  +sqlite4_mm *sqlite4_mm_default(void){ return &sqlite4MMSystem; }
          170  +
   168    171   /*************************************************************************
   169    172   ** The SQLITE4_MM_OVERFLOW memory allocator.
   170    173   **
   171    174   ** This memory allocator has two child memory allocators, A and B.  Always
   172    175   ** try to fulfill the request using A first, then overflow to B if the request
   173    176   ** on A fails.  The A allocator must support the xMember method.
   174    177   */
................................................................................
   175    178   struct mmOvfl {
   176    179     sqlite4_mm base;    /* Base class - must be first */
   177    180     int (*xMemberOfA)(sqlite4_mm*, const void*);
   178    181     sqlite4_mm *pA;     /* Primary memory allocator */
   179    182     sqlite4_mm *pB;     /* Backup memory allocator in case pA fails */
   180    183   };
   181    184   
   182         -static void *mmOvflMalloc(sqlite4_mm *pMM, sqlite4_int64 iSz){
          185  +static void *mmOvflMalloc(sqlite4_mm *pMM, sqlite4_size_t iSz){
   183    186     const struct mmOvfl *pOvfl = (const struct mmOvfl*)pMM;
   184    187     void *pRes;
   185    188     pRes = pOvfl->pA->pMethods->xMalloc(pOvfl->pA, iSz);
   186    189     if( pRes==0 ){
   187    190       pRes = pOvfl->pB->pMethods->xMalloc(pOvfl->pB, iSz);
   188    191     }
   189    192     return pRes;
   190    193   }
   191         -static void *mmOvflRealloc(sqlite4_mm *pMM, void *pOld, sqlite4_int64 iSz){
          194  +static void *mmOvflRealloc(sqlite4_mm *pMM, void *pOld, sqlite4_size_t iSz){
   192    195     const struct mmOvfl *pOvfl;
   193    196     void *pRes;
   194    197     if( pOld==0 ) return mmOvflMalloc(pMM, iSz);
   195    198     pOvfl = (const struct mmOvfl*)pMM;
   196    199     if( pOvfl->xMemberOfA(pOvfl->pA, pOld) ){
   197    200       pRes = pOvfl->pA->pMethods->xRealloc(pOvfl->pA, pOld, iSz);
   198    201     }else{
................................................................................
   206    209     pOvfl = (const struct mmOvfl*)pMM;
   207    210     if( pOvfl->xMemberOfA(pOvfl->pA, pOld) ){
   208    211       pOvfl->pA->pMethods->xFree(pOvfl->pA, pOld);
   209    212     }else{
   210    213       pOvfl->pB->pMethods->xFree(pOvfl->pB, pOld);
   211    214     }
   212    215   }
   213         -static sqlite4_int64 mmOvflMsize(sqlite4_mm *pMM, void *pOld){
          216  +static sqlite4_size_t mmOvflMsize(sqlite4_mm *pMM, void *pOld){
   214    217     const struct mmOvfl *pOvfl;
   215         -  sqlite4_int64 iSz;
          218  +  sqlite4_size_t iSz;
   216    219     if( pOld==0 ) return 0;
   217    220     pOvfl = (const struct mmOvfl*)pMM;
   218    221     if( pOvfl->xMemberOfA(pOvfl->pA, pOld) ){
   219    222       iSz = sqlite4_mm_msize(pOvfl->pA, pOld);
   220    223     }else{
   221    224       iSz = sqlite4_mm_msize(pOvfl->pB, pOld);
   222    225     }
................................................................................
   251    254     /* iVersion */    1,
   252    255     /* xMalloc  */    mmOvflMalloc,
   253    256     /* xRealloc */    mmOvflRealloc,
   254    257     /* xFree    */    mmOvflFree,
   255    258     /* xMsize   */    mmOvflMsize,
   256    259     /* xMember  */    mmOvflMember,
   257    260     /* xBenign  */    mmOvflBenign,
          261  +  /* xStat    */    0,
   258    262     /* xFinal   */    mmOvflFinal
   259    263   };
   260    264   static sqlite4_mm *mmOvflNew(sqlite4_mm *pA, sqlite4_mm *pB){
   261    265     struct mmOvfl *pOvfl;
   262    266     if( pA->pMethods->xMember==0 ) return 0;
   263    267     pOvfl = sqlite4_mm_malloc(pA, sizeof(*pOvfl));
   264    268     if( pOvfl==0 ){
................................................................................
   293    297   };
   294    298   
   295    299   /* A free block in the buffer */
   296    300   struct mmOneszBlock {
   297    301     struct mmOneszBlock *pNext;  /* Next on the freelist */
   298    302   };
   299    303   
   300         -static void *mmOneszMalloc(sqlite4_mm *pMM, sqlite4_int64 iSz){
          304  +static void *mmOneszMalloc(sqlite4_mm *pMM, sqlite4_size_t iSz){
   301    305     struct mmOnesz *pOnesz = (struct mmOnesz*)pMM;
   302    306     void *pRes;
   303    307     if( iSz>pOnesz->sz ) return 0;
   304    308     if( pOnesz->pFree==0 ) return 0;
   305    309     pRes = pOnesz->pFree;
   306    310     pOnesz->pFree = pOnesz->pFree->pNext;
   307    311     return pRes;
................................................................................
   310    314     struct mmOnesz *pOnesz = (struct mmOnesz*)pMM;
   311    315     if( pOld ){
   312    316       struct mmOneszBlock *pBlock = (struct mmOneszBlock*)pOld;
   313    317       pBlock->pNext = pOnesz->pFree;
   314    318       pOnesz->pFree = pBlock;
   315    319     }
   316    320   }
   317         -static void *mmOneszRealloc(sqlite4_mm *pMM, void *pOld, sqlite4_int64 iSz){
          321  +static void *mmOneszRealloc(sqlite4_mm *pMM, void *pOld, sqlite4_size_t iSz){
   318    322     struct mmOnesz *pOnesz = (struct mmOnesz*)pMM;
   319    323     if( pOld==0 ) return mmOneszMalloc(pMM, iSz);
   320    324     if( iSz<=0 ){
   321    325       mmOneszFree(pMM, pOld);
   322    326       return 0;
   323    327     }
   324    328     if( iSz>pOnesz->sz ) return 0;
   325    329     return pOld;
   326    330   }
   327         -static sqlite4_int64 mmOneszMsize(sqlite4_mm *pMM, void *pOld){
          331  +static sqlite4_size_t mmOneszMsize(sqlite4_mm *pMM, void *pOld){
   328    332     struct mmOnesz *pOnesz = (struct mmOnesz*)pMM;
   329    333     return pOld ? pOnesz->sz : 0;  
   330    334   }
   331    335   static int mmOneszMember(sqlite4_mm *pMM, const void *pOld){
   332    336     struct mmOnesz *pOnesz = (struct mmOnesz*)pMM;
   333    337     return pOld && pOld>=pOnesz->pSpace && pOld<=pOnesz->pLast;
   334    338   }
................................................................................
   336    340     /* iVersion */    1,
   337    341     /* xMalloc  */    mmOneszMalloc,
   338    342     /* xRealloc */    mmOneszRealloc,
   339    343     /* xFree    */    mmOneszFree,
   340    344     /* xMsize   */    mmOneszMsize,
   341    345     /* xMember  */    mmOneszMember,
   342    346     /* xBenign  */    0,
          347  +  /* xStat    */    0,
   343    348     /* xFinal   */    0
   344    349   };
   345    350   static sqlite4_mm *mmOneszNew(void *pSpace, int sz, int cnt){
   346    351     struct mmOnesz *pOnesz;
   347    352     unsigned char *pMem;
   348    353     if( sz<sizeof(*pOnesz) ) return 0;
   349    354     if( cnt<2 ) return 0;
................................................................................
   364    369     }
   365    370     return &pOnesz->base;
   366    371   }
   367    372   
   368    373   /*************************************************************************
   369    374   ** Main interfaces.
   370    375   */
   371         -void *sqlite4_mm_malloc(sqlite4_mm *pMM, sqlite4_int64 iSize){
   372         -  if( pMM==0 ) pMM = &mmSystem;
          376  +void *sqlite4_mm_malloc(sqlite4_mm *pMM, sqlite4_size_t iSize){
          377  +  if( pMM==0 ) pMM = &sqlite4MMSystem;
   373    378     return pMM->pMethods->xMalloc(pMM,iSize);
   374    379   }
   375         -void *sqlite4_mm_realloc(sqlite4_mm *pMM, void *pOld, sqlite4_int64 iSize){
   376         -  if( pMM==0 ) pMM = &mmSystem;
          380  +void *sqlite4_mm_realloc(sqlite4_mm *pMM, void *pOld, sqlite4_size_t iSize){
          381  +  if( pMM==0 ) pMM = &sqlite4MMSystem;
   377    382     return pMM->pMethods->xRealloc(pMM,pOld,iSize);
   378    383   }
   379    384   void sqlite4_mm_free(sqlite4_mm *pMM, void *pOld){
   380         -  if( pMM==0 ) pMM = &mmSystem;
          385  +  if( pMM==0 ) pMM = &sqlite4MMSystem;
   381    386     pMM->pMethods->xFree(pMM,pOld);
   382    387   }
   383         -sqlite4_int64 sqlite4_mm_msize(sqlite4_mm *pMM, void *pOld){
   384         -  if( pMM==0 ) pMM = &mmSystem;
          388  +sqlite4_size_t sqlite4_mm_msize(sqlite4_mm *pMM, void *pOld){
          389  +  if( pMM==0 ) pMM = &sqlite4MMSystem;
   385    390     return pMM->pMethods->xMsize(pMM,pOld);
   386    391   }
   387    392   int sqlite4_mm_member(sqlite4_mm *pMM, const void *pOld){
   388    393     return (pMM && pMM->pMethods->xMember!=0) ?
   389    394               pMM->pMethods->xMember(pMM,pOld) : -1;
   390    395   }
   391         -void sqlite4_mm_benign_failure(sqlite4_mm *pMM, int bEnable){
          396  +void sqlite4_mm_benign_failures(sqlite4_mm *pMM, int bEnable){
   392    397     if( pMM && pMM->pMethods->xBenign ){
   393    398       pMM->pMethods->xBenign(pMM, bEnable);
   394    399     }
          400  +}
          401  +sqlite4_int64 sqlite4_mm_stat(sqlite4_mm *pMM, int eStatType, unsigned flags){
          402  +  if( pMM==0 ) return -1;
          403  +  if( pMM->pMethods->xStat==0 ) return -1;
          404  +  return pMM->pMethods->xStat(pMM, eStatType, flags);
   395    405   }
   396    406   void sqlite4_mm_destroy(sqlite4_mm *pMM){
   397    407     if( pMM && pMM->pMethods->xFinal ) pMM->pMethods->xFinal(pMM);
   398    408   }
   399    409   
   400    410   /*
   401    411   ** Create a new memory allocation object.  eType determines the type of
................................................................................
   404    414   sqlite4_mm *sqlite4_mm_new(sqlite4_mm_type eType, ...){
   405    415     va_list ap;
   406    416     sqlite4_mm *pMM;
   407    417   
   408    418     va_start(ap, eType);
   409    419     switch( eType ){
   410    420       case SQLITE4_MM_SYSTEM: {
   411         -      pMM = &mmSystem;
          421  +      pMM = &sqlite4MMSystem;
   412    422         break;
   413    423       }
   414    424       case SQLITE4_MM_OVERFLOW: {
   415    425         sqlite4_mm *pA = va_arg(ap, sqlite4_mm*);
   416    426         sqlite4_mm *pB = va_arg(ap, sqlite4_mm*);
   417    427         pMM = mmOvflNew(pA, pB);
   418    428         break;

Changes to src/sqlite.h.in.

    45     45   */
    46     46   #ifdef SQLITE4_VERSION
    47     47   # undef SQLITE4_VERSION
    48     48   #endif
    49     49   #ifdef SQLITE4_VERSION_NUMBER
    50     50   # undef SQLITE4_VERSION_NUMBER
    51     51   #endif
           52  +
           53  +/*
           54  +** CAPIREF: 64-Bit Integer Types
           55  +** KEYWORDS: sqlite4_int64 sqlite4_uint64
           56  +**
           57  +** Because there is no cross-platform way to specify 64-bit integer types
           58  +** SQLite includes typedefs for 64-bit signed and unsigned integers.
           59  +**
           60  +** ^The sqlite4_int64 and sqlite_int64 types can store integer values
           61  +** between -9223372036854775808 and +9223372036854775807 inclusive.  ^The
           62  +** sqlite4_uint64 and sqlite_uint64 types can store integer values 
           63  +** between 0 and +18446744073709551615 inclusive.
           64  +*/
           65  +#ifdef SQLITE4_INT64_TYPE
           66  +  typedef SQLITE4_INT64_TYPE sqlite4_int64_t;
           67  +  typedef unsigned SQLITE4_INT64_TYPE sqlite4_uint64_t;
           68  +#elif defined(_MSC_VER) || defined(__BORLANDC__)
           69  +  typedef __int64 sqlite4_int64_t;
           70  +  typedef unsigned __int64 sqlite4_uint64_t;
           71  +#else
           72  +  typedef long long int sqlite4_int64_t;
           73  +  typedef unsigned long long int sqlite4_uint64_t;
           74  +#endif
           75  +typedef sqlite4_int64_t sqlite4_int64;
           76  +typedef sqlite4_uint64_t sqlite4_uint64;
           77  +
           78  +/*
           79  +** CAPIREF: String length type
           80  +**
           81  +** A type for measuring the length of the string.  Like size_t but
           82  +** does not require &lt;stddef.h&gt;
           83  +*/
           84  +typedef int sqlite4_size_t;
           85  +
           86  +/*
           87  +** Available memory allocator object subtypes:
           88  +*/
           89  +typedef enum {
           90  +  SQLITE4_MM_SYSTEM = 1,     /* Use the system malloc() */
           91  +  SQLITE4_MM_ONESIZE = 2,    /* All allocations map to a fixed size */
           92  +  SQLITE4_MM_OVERFLOW = 3,   /* Two allocators. Use A first; failover to B */
           93  +  SQLITE4_MM_COMPACT = 4,    /* Like memsys3 from SQLite3 */
           94  +  SQLITE4_MM_ROBSON = 5,     /* Like memsys5 from SQLite3 */
           95  +  SQLITE4_MM_LINEAR = 6,     /* Allocate from a fixed buffer w/o free */
           96  +  SQLITE4_MM_BESPOKE = 7,    /* Caller-defined implementation */
           97  +  SQLITE4_MM_DEBUG,          /* Debugging memory allocator */
           98  +  SQLITE4_MM_STATS           /* Keep memory statistics */
           99  +} sqlite4_mm_type;
          100  +
          101  +/*
          102  +** Base class for the memory allocator object.
          103  +**
          104  +** Implementations may extend this with additional
          105  +** fields specific to its own needs.  This needs to be public so that
          106  +** applications can supply their on customized memory allocators.
          107  +*/
          108  +typedef struct sqlite4_mm sqlite4_mm;
          109  +typedef struct sqlite4_mm_methods sqlite4_mm_methods;
          110  +struct sqlite4_mm {
          111  +  const struct sqlite4_mm_methods *pMethods;
          112  +};
          113  +struct sqlite4_mm_methods {
          114  +  int iVersion;
          115  +  void *(*xMalloc)(sqlite4_mm*, sqlite4_size_t);
          116  +  void *(*xRealloc)(sqlite4_mm*, void*, sqlite4_size_t);
          117  +  void (*xFree)(sqlite4_mm*, void*);
          118  +  sqlite4_size_t (*xMsize)(sqlite4_mm*, void*);
          119  +  int (*xMember)(sqlite4_mm*, const void*);
          120  +  void (*xBenign)(sqlite4_mm*, int);
          121  +  sqlite4_int64 (*xStat)(sqlite4_mm*, unsigned eType, unsigned bFlags);
          122  +  void (*xFinal)(sqlite4_mm*);
          123  +};
          124  +
          125  +/*
          126  +** Return a pointer to the default memory allocator, which is basically
          127  +** a wrapper around system malloc()/realloc()/free().
          128  +*/
          129  +sqlite4_mm *sqlite4_mm_default(void);
          130  +
          131  +
          132  +/*
          133  +** Allocate a new memory manager.  Return NULL if unable.
          134  +*/
          135  +sqlite4_mm *sqlite4_mm_new(sqlite4_mm_type, ...);
          136  +
          137  +/*
          138  +** Free the sqlite4_mm object.
          139  +**
          140  +** All outstanding memory for the allocator must be freed prior to
          141  +** invoking this interface, or else the behavior is undefined.
          142  +*/
          143  +void sqlite4_mm_destroy(sqlite4_mm*);
          144  +
          145  +/*
          146  +** Core memory allocation routines:
          147  +*/
          148  +void *sqlite4_mm_malloc(sqlite4_mm*, sqlite4_size_t);
          149  +void *sqlite4_mm_realloc(sqlite4_mm*, void*, sqlite4_size_t);
          150  +void sqlite4_mm_free(sqlite4_mm*, void*);
          151  +
          152  +/*
          153  +** Return the size of a memory allocation.
          154  +**
          155  +** All memory allocators in SQLite4 must be able to report their size.
          156  +** When using system malloc() on system that lack the malloc_usable_size()
          157  +** routine or its equivalent, then the sqlite4_mm object allocates 8 extra
          158  +** bytes for each memory allocation and stores the allocation size in those
          159  +** initial 8 bytes.
          160  +*/
          161  +sqlite4_size_t sqlite4_mm_msize(sqlite4_mm*, void*);
          162  +
          163  +/*
          164  +** Check to see if pOld is a memory allocation from pMM.  If it is, return
          165  +** 1.  If not, return 0.  If we cannot determine an answer, return -1.
          166  +**
          167  +** If pOld is not a valid memory allocation or is a memory allocation that
          168  +** has previously been freed, then the result of this routine is undefined.
          169  +*/
          170  +int sqlite4_mm_member(sqlite4_mm *pMM, const void *pOld);
          171  +
          172  +/*
          173  +** Return statistics or status information about a memory allocator.
          174  +** Not all memory allocators provide all stat values.  Some memory
          175  +** allocators provides no states at all.  If a particular stat for
          176  +** a memory allocator is unavailable, then -1 is returned.
          177  +*/
          178  +sqlite4_int64 sqlite4_mm_stat(sqlite4_mm *pMM, int eType, unsigned flags);
          179  +
          180  +/*
          181  +** Enable or disable benign failure mode.  Benign failure mode can be
          182  +** nested.  In benign failure mode, OOM errors do not necessarily propagate
          183  +** back out to the application but can be dealt with internally.  Memory
          184  +** allocations that occur in benign failure mode are considered "optional".
          185  +*/
          186  +void sqlite4_mm_benign_failures(sqlite4_mm*, int bEnable);
          187  +
    52    188   
    53    189   /*
    54    190   ** CAPIREF: Run-time Environment Object
    55    191   **
    56    192   ** An instance of the following object defines the run-time environment 
    57    193   ** for an SQLite4 database connection.  This object defines the interface
    58    194   ** to appropriate mutex routines, memory allocation routines, a
................................................................................
   225    361   ** is its destructor.  There are many other interfaces (such as
   226    362   ** [sqlite4_prepare], [sqlite4_create_function()], and
   227    363   ** [sqlite4_busy_timeout()] to name but three) that are methods on an
   228    364   ** sqlite4 object.
   229    365   */
   230    366   typedef struct sqlite4 sqlite4;
   231    367   
   232         -/*
   233         -** CAPIREF: 64-Bit Integer Types
   234         -** KEYWORDS: sqlite4_int64 sqlite4_uint64
   235         -**
   236         -** Because there is no cross-platform way to specify 64-bit integer types
   237         -** SQLite includes typedefs for 64-bit signed and unsigned integers.
   238         -**
   239         -** ^The sqlite4_int64 and sqlite_int64 types can store integer values
   240         -** between -9223372036854775808 and +9223372036854775807 inclusive.  ^The
   241         -** sqlite4_uint64 and sqlite_uint64 types can store integer values 
   242         -** between 0 and +18446744073709551615 inclusive.
   243         -*/
   244         -#ifdef SQLITE4_INT64_TYPE
   245         -  typedef SQLITE4_INT64_TYPE sqlite4_int64_t;
   246         -  typedef unsigned SQLITE4_INT64_TYPE sqlite4_uint64_t;
   247         -#elif defined(_MSC_VER) || defined(__BORLANDC__)
   248         -  typedef __int64 sqlite4_int64_t;
   249         -  typedef unsigned __int64 sqlite4_uint64_t;
   250         -#else
   251         -  typedef long long int sqlite4_int64_t;
   252         -  typedef unsigned long long int sqlite4_uint64_t;
   253         -#endif
   254         -typedef sqlite4_int64_t sqlite4_int64;
   255         -typedef sqlite4_uint64_t sqlite4_uint64;
   256         -
   257         -/*
   258         -** CAPIREF: String length type
   259         -**
   260         -** A type for measuring the length of the string.  Like size_t but
   261         -** does not require &lt;stddef.h&gt;
   262         -*/
   263         -typedef int sqlite4_size_t;
   264         -
   265    368   /*
   266    369   ** If compiling for a processor that lacks floating point support,
   267    370   ** substitute integer for floating-point.
   268    371   */
   269    372   #ifdef SQLITE4_OMIT_FLOATING_POINT
   270    373   # define double sqlite4_int64
   271    374   #endif

Changes to src/sqliteInt.h.

  2405   2405     int iVersion;                     /* Version number of this structure */
  2406   2406     int bMemstat;                     /* True to enable memory status */
  2407   2407     int bCoreMutex;                   /* True to enable core mutexing */
  2408   2408     int bFullMutex;                   /* True to enable full mutexing */
  2409   2409     int mxStrlen;                     /* Maximum string length */
  2410   2410     int szLookaside;                  /* Default lookaside buffer size */
  2411   2411     int nLookaside;                   /* Default lookaside buffer count */
         2412  +  sqlite4_mm *pMM;                  /* Memory allocator for this environment */
  2412   2413     sqlite4_mem_methods m;            /* Low-level memory allocation interface */
  2413   2414     sqlite4_mutex_methods mutex;      /* Low-level mutex interface */
  2414   2415     void *pHeap;                      /* Heap storage space */
  2415   2416     int nHeap;                        /* Size of pHeap[] */
  2416   2417     int mnReq, mxReq;                 /* Min and max heap requests sizes */
  2417   2418     int mxParserStack;                /* maximum depth of the parser stack */
  2418   2419     KVFactory *pFactory;              /* List of factories */
................................................................................
  2480   2481   */
  2481   2482   #define SQLITE4_SKIP_UTF8(zIn) {                        \
  2482   2483     if( (*(zIn++))>=0xc0 ){                              \
  2483   2484       while( (*zIn & 0xc0)==0x80 ){ zIn++; }             \
  2484   2485     }                                                    \
  2485   2486   }
  2486   2487   
         2488  +/*
         2489  +** Default memory allocator
         2490  +*/
         2491  +extern sqlite4_mm sqlite4MMSystem;
         2492  +
  2487   2493   /*
  2488   2494   ** The SQLITE4_*_BKPT macros are substitutes for the error codes with
  2489   2495   ** the same name but without the _BKPT suffix.  These macros invoke
  2490   2496   ** routines that report the line-number on which the error originated
  2491   2497   ** using sqlite4_log().  The routines also provide a convenient place
  2492   2498   ** to set a debugger breakpoint.
  2493   2499   */

Changes to src/vdbeapi.c.

    12     12   **
    13     13   ** This file contains code use to implement APIs that are part of the
    14     14   ** VDBE.
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   #include "vdbeInt.h"
    18     18   
    19         -#ifndef SQLITE4_OMIT_DEPRECATED
    20         -/*
    21         -** Return TRUE (non-zero) of the statement supplied as an argument needs
    22         -** to be recompiled.  A statement needs to be recompiled whenever the
    23         -** execution environment changes in a way that would alter the program
    24         -** that sqlite4_prepare() generates.  For example, if new functions or
    25         -** collating sequences are registered or if an authorizer function is
    26         -** added or changed.
    27         -*/
    28         -int sqlite4_expired(sqlite4_stmt *pStmt){
    29         -  Vdbe *p = (Vdbe*)pStmt;
    30         -  return p==0 || p->expired;
    31         -}
    32         -#endif
    33         -
    34     19   /*
    35     20   ** Check on a Vdbe to make sure it has not been finalized.  Log
    36     21   ** an error and return true if it has been finalized (or is otherwise
    37     22   ** invalid).  Return false if it is ok.
    38     23   */
    39     24   static int vdbeSafety(Vdbe *p){
    40     25     if( p->db==0 ){
................................................................................
   625    610   
   626    611   failed:
   627    612     if( xDelete ){
   628    613       xDelete(pDeleteArg, pAux);
   629    614     }
   630    615   }
   631    616   
   632         -#ifndef SQLITE4_OMIT_DEPRECATED
   633         -/*
   634         -** Return the number of times the Step function of a aggregate has been 
   635         -** called.
   636         -**
   637         -** This function is deprecated.  Do not use it for new code.  It is
   638         -** provide only to avoid breaking legacy code.  New aggregate function
   639         -** implementations should keep their own counts within their aggregate
   640         -** context.
   641         -*/
   642         -int sqlite4_aggregate_count(sqlite4_context *p){
   643         -  assert( p && p->pMem && p->pFunc && p->pFunc->xStep );
   644         -  return p->pMem->n;
   645         -}
   646         -#endif
   647         -
   648    617   /*
   649    618   ** Return the number of columns in the result set for the statement pStmt.
   650    619   */
   651    620   int sqlite4_column_count(sqlite4_stmt *pStmt){
   652    621     Vdbe *pVm = (Vdbe *)pStmt;
   653    622     return pVm ? pVm->nResColumn : 0;
   654    623   }
................................................................................
  1193   1162     for(i=0; i<pFrom->nVar; i++){
  1194   1163       sqlite4VdbeMemMove(&pTo->aVar[i], &pFrom->aVar[i]);
  1195   1164     }
  1196   1165     sqlite4_mutex_leave(pTo->db->mutex);
  1197   1166     return SQLITE4_OK;
  1198   1167   }
  1199   1168   
  1200         -#ifndef SQLITE4_OMIT_DEPRECATED
  1201         -/*
  1202         -** Deprecated external interface.  Internal/core SQLite code
  1203         -** should call sqlite4TransferBindings.
  1204         -**
  1205         -** Is is misuse to call this routine with statements from different
  1206         -** database connections.  But as this is a deprecated interface, we
  1207         -** will not bother to check for that condition.
  1208         -**
  1209         -** If the two statements contain a different number of bindings, then
  1210         -** an SQLITE4_ERROR is returned.  Nothing else can go wrong, so otherwise
  1211         -** SQLITE4_OK is returned.
  1212         -*/
  1213         -int sqlite4_transfer_bindings(sqlite4_stmt *pFromStmt, sqlite4_stmt *pToStmt){
  1214         -  Vdbe *pFrom = (Vdbe*)pFromStmt;
  1215         -  Vdbe *pTo = (Vdbe*)pToStmt;
  1216         -  if( pFrom->nVar!=pTo->nVar ){
  1217         -    return SQLITE4_ERROR;
  1218         -  }
  1219         -  if( pTo->expmask ){
  1220         -    pTo->expired = 1;
  1221         -  }
  1222         -  if( pFrom->expmask ){
  1223         -    pFrom->expired = 1;
  1224         -  }
  1225         -  return sqlite4TransferBindings(pFromStmt, pToStmt);
  1226         -}
  1227         -#endif
  1228         -
  1229   1169   /*
  1230   1170   ** Return the sqlite4* database handle to which the prepared statement given
  1231   1171   ** in the argument belongs.  This is the same database handle that was
  1232   1172   ** the first argument to the sqlite4_prepare() that was used to create
  1233   1173   ** the statement in the first place.
  1234   1174   */
  1235   1175   sqlite4 *sqlite4_db_handle(sqlite4_stmt *pStmt){

Deleted test/bindxfer.test.

     1         -# 2005 April 21
     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.  The
    12         -# focus of this script testing the sqlite_transfer_bindings() API.
    13         -#
    14         -# $Id: bindxfer.test,v 1.9 2009/04/17 11:56:28 drh Exp $
    15         -#
    16         -
    17         -set testdir [file dirname $argv0]
    18         -source $testdir/tester.tcl
    19         -
    20         -proc sqlite_step {stmt VALS COLS} {
    21         -  upvar #0 $VALS vals
    22         -  upvar #0 $COLS cols
    23         -  set vals [list]
    24         -  set cols [list]
    25         -
    26         -  set rc [sqlite4_step $stmt]
    27         -  for {set i 0} {$i < [sqlite4_column_count $stmt]} {incr i} {
    28         -    lappend cols [sqlite4_column_name $stmt $i]
    29         -  }
    30         -  for {set i 0} {$i < [sqlite4_data_count $stmt]} {incr i} {
    31         -    lappend vals [sqlite4_column_text $stmt $i]
    32         -  }
    33         -
    34         -  return $rc
    35         -}
    36         -
    37         -do_test bindxfer-1.1 {
    38         -  set DB [sqlite4_connection_pointer db]
    39         -  execsql {CREATE TABLE t1(a,b,c);}
    40         -  set VM1 [sqlite4_prepare $DB {SELECT ?, ?, ?} -1 TAIL]
    41         -  set TAIL
    42         -} {}
    43         -do_test bindxfer-1.2 {
    44         -  sqlite4_bind_parameter_count $VM1
    45         -} 3
    46         -do_test bindxfer-1.3 {
    47         -  set VM2 [sqlite4_prepare $DB {SELECT ?, ?, ?} -1 TAIL]
    48         -  set TAIL
    49         -} {}
    50         -do_test bindxfer-1.4 {
    51         -  sqlite4_bind_parameter_count $VM2
    52         -} 3
    53         -ifcapable deprecated {
    54         -  do_test bindxfer-1.5 {
    55         -    sqlite_bind $VM1 1 one normal
    56         -    set sqlite_static_bind_value two
    57         -    sqlite_bind $VM1 2 {} static
    58         -    sqlite_bind $VM1 3 {} null
    59         -    sqlite4_transfer_bindings $VM1 $VM2
    60         -    sqlite_step $VM1 VALUES COLNAMES
    61         -  } SQLITE4_ROW
    62         -  do_test bindxfer-1.6 {
    63         -    set VALUES
    64         -  } {{} {} {}}
    65         -  do_test bindxfer-1.7 {
    66         -    sqlite_step $VM2 VALUES COLNAMES
    67         -  } SQLITE4_ROW
    68         -  do_test bindxfer-1.8 {
    69         -    set VALUES
    70         -  } {one two {}}
    71         -}
    72         -catch {sqlite4_finalize $VM1}
    73         -catch {sqlite4_finalize $VM2}
    74         -
    75         -
    76         -finish_test

Changes to test/enc4.test.

    50     50     do_test enc4-$i.1 {
    51     51       db eval {PRAGMA encoding}
    52     52     } $enc
    53     53   
    54     54     set j 1
    55     55     foreach init $inits {
    56     56   
    57         -    do_test enc4-$i.$j.2 {
    58         -      set S [sqlite4_prepare db "SELECT $init+?" -1 dummy]
    59         -      sqlite4_expired $S
    60         -    } {0}
    61         -      
           57  +    set S [sqlite4_prepare db "SELECT $init+?" -1 dummy]
    62     58       set k 1
    63     59       foreach val $vals {
    64     60         for {set x 1} {$x<16} {incr x} {
    65     61           set part [expr $init + [string range $val 0 [expr $x-1]]]
    66     62   
    67     63           do_realnum_test enc4-$i.$j.$k.3.$x {
    68     64             sqlite4_reset $S

Changes to test/permutations.test.

   145    145     aggerror.test
   146    146     attach.test
   147    147     autoindex1.test
   148    148     badutf.test
   149    149     between.test
   150    150     bigrow.test
   151    151     bind.test
   152         -  bindxfer.test
   153    152   
   154    153     boundary1.test boundary4.test
   155    154     cast.test
   156    155     coalesce.test 
   157    156     collate1.test collate2.test collate3.test collate4.test collate5.test
   158    157     collate6.test collate7.test collate8.test collate9.test collateA.test
   159    158     conflict.test 

Changes to test/test_main.c.

  1008   1008         sqlite4_result_error(context, "x_count totals to 42", -1);
  1009   1009       }else{
  1010   1010         sqlite4_result_int(context, p ? p->n : 0);
  1011   1011       }
  1012   1012     }
  1013   1013   }
  1014   1014   
  1015         -#ifndef SQLITE4_OMIT_DEPRECATED
  1016         -static void legacyCountStep(
  1017         -  sqlite4_context *context,
  1018         -  int argc,
  1019         -  sqlite4_value **argv
  1020         -){
  1021         -  /* no-op */
  1022         -}
  1023         -
  1024         -static void legacyCountFinalize(sqlite4_context *context){
  1025         -  sqlite4_result_int(context, sqlite4_aggregate_count(context));
  1026         -}
  1027         -#endif
  1028         -
  1029   1015   /*
  1030   1016   ** Usage:  sqlite4_create_aggregate DB
  1031   1017   **
  1032   1018   ** Call the sqlite4_create_function API on the given database in order
  1033   1019   ** to create a function named "x_count".  This function is similar
  1034   1020   ** to the built-in count() function, with a few special quirks
  1035   1021   ** for testing the sqlite4_result_error() APIs.
................................................................................
  1061   1047     if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
  1062   1048     rc = sqlite4_create_function(db, "x_count", 0, SQLITE4_UTF8, 0, 0,
  1063   1049         t1CountStep,t1CountFinalize);
  1064   1050     if( rc==SQLITE4_OK ){
  1065   1051       rc = sqlite4_create_function(db, "x_count", 1, SQLITE4_UTF8, 0, 0,
  1066   1052           t1CountStep,t1CountFinalize);
  1067   1053     }
  1068         -#ifndef SQLITE4_OMIT_DEPRECATED
  1069         -  if( rc==SQLITE4_OK ){
  1070         -    rc = sqlite4_create_function(db, "legacy_count", 0, SQLITE4_ANY, 0, 0,
  1071         -        legacyCountStep, legacyCountFinalize
  1072         -    );
  1073         -  }
  1074         -#endif
  1075   1054     if( sqlite4TestErrCode(interp, db, rc) ) return TCL_ERROR;
  1076   1055     Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0);
  1077   1056     return TCL_OK;
  1078   1057   }
  1079   1058   
  1080   1059   
  1081   1060   /*
................................................................................
  1959   1938     }
  1960   1939     Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
  1961   1940   /*
  1962   1941     if( rc ){
  1963   1942       return TCL_ERROR;
  1964   1943     }
  1965   1944   */
  1966         -  return TCL_OK;
  1967         -}
  1968         -
  1969         -/*
  1970         -** Usage:  sqlite4_expired STMT 
  1971         -**
  1972         -** Return TRUE if a recompilation of the statement is recommended.
  1973         -*/
  1974         -static int test_expired(
  1975         -  void * clientData,
  1976         -  Tcl_Interp *interp,
  1977         -  int objc,
  1978         -  Tcl_Obj *CONST objv[]
  1979         -){
  1980         -#ifndef SQLITE4_OMIT_DEPRECATED
  1981         -  sqlite4_stmt *pStmt;
  1982         -  if( objc!=2 ){
  1983         -    Tcl_AppendResult(interp, "wrong # args: should be \"",
  1984         -        Tcl_GetStringFromObj(objv[0], 0), " <STMT>", 0);
  1985         -    return TCL_ERROR;
  1986         -  }
  1987         -  if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
  1988         -  Tcl_SetObjResult(interp, Tcl_NewBooleanObj(sqlite4_expired(pStmt)));
  1989         -#endif
  1990         -  return TCL_OK;
  1991         -}
  1992         -
  1993         -/*
  1994         -** Usage:  sqlite4_transfer_bindings FROMSTMT TOSTMT
  1995         -**
  1996         -** Transfer all bindings from FROMSTMT over to TOSTMT
  1997         -*/
  1998         -static int test_transfer_bind(
  1999         -  void * clientData,
  2000         -  Tcl_Interp *interp,
  2001         -  int objc,
  2002         -  Tcl_Obj *CONST objv[]
  2003         -){
  2004         -#ifndef SQLITE4_OMIT_DEPRECATED
  2005         -  sqlite4_stmt *pStmt1, *pStmt2;
  2006         -  if( objc!=3 ){
  2007         -    Tcl_AppendResult(interp, "wrong # args: should be \"",
  2008         -        Tcl_GetStringFromObj(objv[0], 0), " FROM-STMT TO-STMT", 0);
  2009         -    return TCL_ERROR;
  2010         -  }
  2011         -  if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt1)) return TCL_ERROR;
  2012         -  if( getStmtPointer(interp, Tcl_GetString(objv[2]), &pStmt2)) return TCL_ERROR;
  2013         -  Tcl_SetObjResult(interp, 
  2014         -     Tcl_NewIntObj(sqlite4_transfer_bindings(pStmt1,pStmt2)));
  2015         -#endif
  2016   1945     return TCL_OK;
  2017   1946   }
  2018   1947   
  2019   1948   /*
  2020   1949   ** Usage:  sqlite4_changes DB
  2021   1950   **
  2022   1951   ** Return the number of changes made to the database by the last SQL
................................................................................
  3488   3417     zRet = xFunc(pStmt, col);
  3489   3418     if( zRet ){
  3490   3419       Tcl_SetResult(interp, (char *)zRet, 0);
  3491   3420     }
  3492   3421     return TCL_OK;
  3493   3422   }
  3494   3423   
  3495         -static int test_global_recover(
  3496         -  void * clientData,
  3497         -  Tcl_Interp *interp,
  3498         -  int objc,
  3499         -  Tcl_Obj *CONST objv[]
  3500         -){
  3501         -#ifndef SQLITE4_OMIT_DEPRECATED
  3502         -  int rc;
  3503         -  if( objc!=1 ){
  3504         -    Tcl_WrongNumArgs(interp, 1, objv, "");
  3505         -    return TCL_ERROR;
  3506         -  }
  3507         -  rc = sqlite4_global_recover();
  3508         -  Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
  3509         -#endif
  3510         -  return TCL_OK;
  3511         -}
  3512         -
  3513   3424   /*
  3514   3425   ** Usage: sqlite4_column_text STMT column
  3515   3426   **
  3516   3427   ** Usage: sqlite4_column_decltype STMT column
  3517   3428   **
  3518   3429   ** Usage: sqlite4_column_name STMT column
  3519   3430   */
................................................................................
  4578   4489        { "sqlite4_open_v2",               test_open_v2       ,0 },
  4579   4490   
  4580   4491        { "sqlite4_prepare",               test_prepare       ,0 },
  4581   4492        { "sqlite4_prepare_tkt3134",       test_prepare_tkt3134, 0},
  4582   4493        { "sqlite4_finalize",              test_finalize      ,0 },
  4583   4494        { "sqlite4_stmt_status",           test_stmt_status   ,0 },
  4584   4495        { "sqlite4_reset",                 test_reset         ,0 },
  4585         -     { "sqlite4_expired",               test_expired       ,0 },
  4586         -     { "sqlite4_transfer_bindings",     test_transfer_bind ,0 },
  4587   4496        { "sqlite4_changes",               test_changes       ,0 },
  4588   4497        { "sqlite4_step",                  test_step          ,0 },
  4589   4498        { "sqlite4_sql",                   test_sql           ,0 },
  4590   4499        { "sqlite4_next_stmt",             test_next_stmt     ,0 },
  4591   4500        { "sqlite4_stmt_readonly",         test_stmt_readonly ,0 },
  4592   4501        { "sqlite4_stmt_busy",             test_stmt_busy     ,0 },
  4593   4502        { "uses_stmt_journal",             uses_stmt_journal ,0 },
................................................................................
  4634   4543   {"sqlite4_column_database_name16",
  4635   4544     test_stmt_utf16, sqlite4_column_database_name16},
  4636   4545   {"sqlite4_column_table_name16", test_stmt_utf16, (void*)sqlite4_column_table_name16},
  4637   4546   {"sqlite4_column_origin_name16", test_stmt_utf16, (void*)sqlite4_column_origin_name16},
  4638   4547   #endif
  4639   4548   #endif
  4640   4549        { "sqlite4_create_collation",   test_create_collation, 0 },
  4641         -     { "sqlite4_global_recover",     test_global_recover, 0   },
  4642   4550        { "working_64bit_int",          working_64bit_int,   0   },
  4643   4551        { "sqlite4_create_function_v2", test_create_function_v2, 0 },
  4644   4552   
  4645   4553        /* Functions from os.h */
  4646   4554   #ifndef SQLITE4_OMIT_UTF16
  4647   4555        { "add_test_collate",        test_collate, 0            },
  4648   4556        { "add_test_collate_needed", test_collate_needed, 0     },