The amalgamation now compiles cleanly on GCC with options
-pedantic-errors -Wno-long-long. (CVS 5991)

FossilOrigin-Name: 73c7302c5f76a2f61ecd75f8bda69bb500d3119c
diff --git a/src/global.c b/src/global.c
index e051683..757b75a 100644
--- a/src/global.c
+++ b/src/global.c
@@ -12,7 +12,7 @@
 **
 ** This file contains definitions of global variables and contants.
 **
-** $Id: global.c,v 1.8 2008/09/04 17:17:39 danielk1977 Exp $
+** $Id: global.c,v 1.9 2008/12/08 18:19:18 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -73,7 +73,26 @@
    0x7ffffffe,                /* mxStrlen */
    100,                       /* szLookaside */
    500,                       /* nLookaside */
-   /* Other fields all default to zero */
+   {0,0,0,0,0,0,0,0},         /* m */
+   {0,0,0,0,0,0,0,0,0},       /* mutex */
+   {0,0,0,0,0,0,0,0,0,0,0},   /* pcache */
+   (void*)0,                  /* pHeap */
+   0,                         /* nHeap */
+   0, 0,                      /* mnHeap, mxHeap */
+   (void*)0,                  /* pScratch */
+   0,                         /* szScratch */
+   0,                         /* nScratch */
+   (void*)0,                  /* pPage */
+   0,                         /* szPage */
+   0,                         /* nPage */
+   0,                         /* mxParserStack */
+   0,                         /* sharedCacheEnabled */
+   /* All the rest need to always be zero */
+   0,                         /* isInit */
+   0,                         /* inProgress */
+   0,                         /* isMallocInit */
+   0,                         /* pInitMutex */
+   0,                         /* nRefInitMutex */
 };
 
 
diff --git a/src/loadext.c b/src/loadext.c
index 517eed0..c59cd9c 100644
--- a/src/loadext.c
+++ b/src/loadext.c
@@ -12,7 +12,7 @@
 ** This file contains code used to dynamically load extensions into
 ** the SQLite library.
 **
-** $Id: loadext.c,v 1.56 2008/10/12 00:27:53 shane Exp $
+** $Id: loadext.c,v 1.57 2008/12/08 18:19:18 drh Exp $
 */
 
 #ifndef SQLITE_CORE
@@ -482,10 +482,10 @@
 ** This list is shared across threads.  The SQLITE_MUTEX_STATIC_MASTER
 ** mutex must be held while accessing this list.
 */
-typedef struct sqlite3ExtType sqlite3ExtType;
-static SQLITE_WSD struct sqlite3ExtType {
-  int nExt;        /* Number of entries in aExt[] */          
-  void **aExt;     /* Pointers to the extension init functions */
+typedef struct sqlite3AutoExtList sqlite3AutoExtList;
+static SQLITE_WSD struct sqlite3AutoExtList {
+  int nExt;              /* Number of entries in aExt[] */          
+  void (**aExt)(void);   /* Pointers to the extension init functions */
 } sqlite3Autoext = { 0, 0 };
 
 /* The "wsdAutoext" macro will resolve to the autoextension
@@ -496,7 +496,7 @@
 */
 #ifdef SQLITE_OMIT_WSD
 # define wsdAutoextInit \
-  sqlite3ExtType *x = &GLOBAL(sqlite3ExtType,sqlite3Autoext)
+  sqlite3AutoExtList *x = &GLOBAL(sqlite3AutoExtList,sqlite3Autoext)
 # define wsdAutoext x[0]
 #else
 # define wsdAutoextInit
@@ -508,7 +508,7 @@
 ** Register a statically linked extension that is automatically
 ** loaded by every new database connection.
 */
-int sqlite3_auto_extension(void *xInit){
+int sqlite3_auto_extension(void (*xInit)(void)){
   int rc = SQLITE_OK;
 #ifndef SQLITE_OMIT_AUTOINIT
   rc = sqlite3_initialize();
@@ -528,7 +528,7 @@
     }
     if( i==wsdAutoext.nExt ){
       int nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
-      void **aNew;
+      void (**aNew)(void);
       aNew = sqlite3_realloc(wsdAutoext.aExt, nByte);
       if( aNew==0 ){
         rc = SQLITE_NOMEM;
diff --git a/src/mutex_unix.c b/src/mutex_unix.c
index f0e0879..36b0682 100644
--- a/src/mutex_unix.c
+++ b/src/mutex_unix.c
@@ -11,7 +11,7 @@
 *************************************************************************
 ** This file contains the C functions that implement mutexes for pthreads
 **
-** $Id: mutex_unix.c,v 1.15 2008/11/17 19:18:55 danielk1977 Exp $
+** $Id: mutex_unix.c,v 1.16 2008/12/08 18:19:18 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -316,6 +316,9 @@
 #ifdef SQLITE_DEBUG
     pthreadMutexHeld,
     pthreadMutexNotheld
+#else
+    0,
+    0
 #endif
   };
 
diff --git a/src/mutex_w32.c b/src/mutex_w32.c
index 0d93811..320c448 100644
--- a/src/mutex_w32.c
+++ b/src/mutex_w32.c
@@ -11,7 +11,7 @@
 *************************************************************************
 ** This file contains the C functions that implement mutexes for win32
 **
-** $Id: mutex_w32.c,v 1.12 2008/11/10 20:01:41 shane Exp $
+** $Id: mutex_w32.c,v 1.13 2008/12/08 18:19:18 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -243,6 +243,9 @@
 #ifdef SQLITE_DEBUG
     winMutexHeld,
     winMutexNotheld
+#else
+    0,
+    0
 #endif
   };
 
diff --git a/src/os.c b/src/os.c
index 006f620..c353388 100644
--- a/src/os.c
+++ b/src/os.c
@@ -13,7 +13,7 @@
 ** This file contains OS interface code that is common to all
 ** architectures.
 **
-** $Id: os.c,v 1.124 2008/10/07 15:25:48 drh Exp $
+** $Id: os.c,v 1.125 2008/12/08 18:19:18 drh Exp $
 */
 #define _SQLITE_OS_C_ 1
 #include "sqliteInt.h"
@@ -142,8 +142,8 @@
 void sqlite3OsDlError(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
   pVfs->xDlError(pVfs, nByte, zBufOut);
 }
-void *sqlite3OsDlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol){
-  return pVfs->xDlSym(pVfs, pHandle, zSymbol);
+void (*sqlite3OsDlSym(sqlite3_vfs *pVfs, void *pHdle, const char *zSym))(void){
+  return pVfs->xDlSym(pVfs, pHdle, zSym);
 }
 void sqlite3OsDlClose(sqlite3_vfs *pVfs, void *pHandle){
   pVfs->xDlClose(pVfs, pHandle);
diff --git a/src/os.h b/src/os.h
index 92f1599..284d96d 100644
--- a/src/os.h
+++ b/src/os.h
@@ -17,7 +17,7 @@
 ** This header file is #include-ed by sqliteInt.h and thus ends up
 ** being included by every source file.
 **
-** $Id: os.h,v 1.105 2008/06/26 10:41:19 danielk1977 Exp $
+** $Id: os.h,v 1.106 2008/12/08 18:19:18 drh Exp $
 */
 #ifndef _SQLITE_OS_H_
 #define _SQLITE_OS_H_
@@ -258,7 +258,7 @@
 #ifndef SQLITE_OMIT_LOAD_EXTENSION
 void *sqlite3OsDlOpen(sqlite3_vfs *, const char *);
 void sqlite3OsDlError(sqlite3_vfs *, int, char *);
-void *sqlite3OsDlSym(sqlite3_vfs *, void *, const char *);
+void (*sqlite3OsDlSym(sqlite3_vfs *, void *, const char *))(void);
 void sqlite3OsDlClose(sqlite3_vfs *, void *);
 #endif /* SQLITE_OMIT_LOAD_EXTENSION */
 int sqlite3OsRandomness(sqlite3_vfs *, int, char *);
diff --git a/src/os_unix.c b/src/os_unix.c
index 3497257..0e4975d 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -43,7 +43,7 @@
 **   *  Definitions of sqlite3_vfs objects for all locking methods
 **      plus implementations of sqlite3_os_init() and sqlite3_os_end().
 **
-** $Id: os_unix.c,v 1.229 2008/12/04 12:34:16 drh Exp $
+** $Id: os_unix.c,v 1.230 2008/12/08 18:19:18 drh Exp $
 */
 #include "sqliteInt.h"
 #if SQLITE_OS_UNIX              /* This file is used on unix only */
@@ -2217,9 +2217,6 @@
   pb.offset = offset;
   pb.length = length; 
   pb.fd = pFile->h;
-  //SimulateIOErrorBenign(1);
-  //SimulateIOError( pb.fd=(-1) )
-  //SimulateIOErrorBenign(0);
   
   OSTRACE6("AFPSETLOCK [%s] for %d%s in range %llx:%llx\n", 
     (setLockFlag?"ON":"OFF"), pFile->h, (pb.fd==-1?"[testval-1]":""),
@@ -3013,6 +3010,18 @@
 ** looks at the filesystem type and tries to guess the best locking
 ** strategy from that.
 **
+** For finder-funtion F, two objects are created:
+**
+**    (1) The real finder-function named "FImpt()".
+**
+**    (2) A constant pointer to this functio named just "F".
+**
+**
+** A pointer to the F pointer is used as the pAppData value for VFS
+** objects.  We have to do this instead of letting pAppData point
+** directly at the finder-function since C90 rules prevent a void*
+** from be cast into a function pointer.
+**
 **
 ** Each instance of this macro generates two objects:
 **
@@ -3038,10 +3047,12 @@
    unixSectorSize,             /* xSectorSize */                             \
    unixDeviceCharacteristics   /* xDeviceCapabilities */                     \
 };                                                                           \
-static const sqlite3_io_methods *FINDER(const char *z, int h){               \
+static const sqlite3_io_methods *FINDER##Impl(const char *z, int h){         \
   UNUSED_PARAMETER(z); UNUSED_PARAMETER(h);                                  \
   return &METHOD;                                                            \
-}
+}                                                                            \
+static const sqlite3_io_methods *(*const FINDER)(const char*,int)            \
+    = FINDER##Impl;
 
 /*
 ** Here are all of the sqlite3_io_methods objects for each of the
@@ -3055,7 +3066,7 @@
   unixLock,                 /* xLock method */
   unixUnlock,               /* xUnlock method */
   unixCheckReservedLock     /* xCheckReservedLock method */
-);
+)
 IOMETHODS(
   nolockIoFinder,           /* Finder function name */
   nolockIoMethods,          /* sqlite3_io_methods object name */
@@ -3063,7 +3074,7 @@
   nolockLock,               /* xLock method */
   nolockUnlock,             /* xUnlock method */
   nolockCheckReservedLock   /* xCheckReservedLock method */
-);
+)
 IOMETHODS(
   dotlockIoFinder,          /* Finder function name */
   dotlockIoMethods,         /* sqlite3_io_methods object name */
@@ -3071,7 +3082,7 @@
   dotlockLock,              /* xLock method */
   dotlockUnlock,            /* xUnlock method */
   dotlockCheckReservedLock  /* xCheckReservedLock method */
-);
+)
 
 #if SQLITE_ENABLE_LOCKING_STYLE
 IOMETHODS(
@@ -3081,7 +3092,7 @@
   flockLock,                /* xLock method */
   flockUnlock,              /* xUnlock method */
   flockCheckReservedLock    /* xCheckReservedLock method */
-);
+)
 #endif
 
 #if OS_VXWORKS
@@ -3092,7 +3103,7 @@
   semLock,                  /* xLock method */
   semUnlock,                /* xUnlock method */
   semCheckReservedLock      /* xCheckReservedLock method */
-);
+)
 #endif
 
 #if defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE
@@ -3103,7 +3114,7 @@
   afpLock,                  /* xLock method */
   afpUnlock,                /* xUnlock method */
   afpCheckReservedLock      /* xCheckReservedLock method */
-);
+)
 #endif
 
 /*
@@ -3127,7 +3138,7 @@
   proxyLock,                /* xLock method */
   proxyUnlock,              /* xUnlock method */
   proxyCheckReservedLock    /* xCheckReservedLock method */
-);
+)
 #endif
 
 
@@ -3139,7 +3150,7 @@
 **
 ** This is for MacOSX only.
 */
-static const sqlite3_io_methods *autolockIoFinder(
+static const sqlite3_io_methods *autolockIoFinderImpl(
   const char *filePath,    /* name of the database file */
   int fd                   /* file descriptor open on the database file */
 ){
@@ -3192,6 +3203,9 @@
     return &dotlockIoMethods;
   }
 }
+static const sqlite3_io_methods (*const autolockIoFinder)(const char*,int)
+        = autolockIoFinderImpl;
+
 #endif /* defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE */
 
 /*
@@ -3250,7 +3264,7 @@
   if( noLock ){
     pLockingStyle = &nolockIoMethods;
   }else{
-    pLockingStyle = (*(finder_type)pVfs->pAppData)(zFilename, h);
+    pLockingStyle = (**(finder_type*)pVfs->pAppData)(zFilename, h);
 #if SQLITE_ENABLE_LOCKING_STYLE
     /* Cache zFilename in the locking context (AFP and dotlock override) for
     ** proxyLock activation is possible (remote proxy is based on db name)
@@ -3764,9 +3778,28 @@
   }
   unixLeaveMutex();
 }
-static void *unixDlSym(sqlite3_vfs *NotUsed, void *pHandle, const char*zSymbol){
+static void (*unixDlSym(sqlite3_vfs *NotUsed, void *p, const char*zSym))(void){
+  /* 
+  ** GCC with -pedantic-errors says that C90 does not allow a void* to be
+  ** cast into a pointer to a function.  And yet the library dlsym() routine
+  ** returns a void* which is really a pointer to a function.  So how do we
+  ** use dlsym() with -pedantic-errors?
+  **
+  ** Variable x below is defined to be a pointer to a function taking
+  ** parameters void* and const char* and returning a pointer to a function.
+  ** We initialize x by assigning it a pointer to the dlsym() function.
+  ** (That assignment requires a cast.)  Then we call the function that
+  ** x points to.  
+  **
+  ** This work-around is unlikely to work correctly on any system where
+  ** you really cannot cast a function pointer into void*.  But then, on the
+  ** other hand, dlsym() will not work on such a system either, so we have
+  ** not really lost anything.
+  */
+  void (*(*x)(void*,const char*))(void);
   UNUSED_PARAMETER(NotUsed);
-  return dlsym(pHandle, zSymbol);
+  x = (void(*(*)(void*,const char*))(void))dlsym;
+  return (*x)(p, zSym);
 }
 static void unixDlClose(sqlite3_vfs *NotUsed, void *pHandle){
   UNUSED_PARAMETER(NotUsed);
@@ -4283,7 +4316,7 @@
   }
   memset(pNew, 0, sizeof(unixFile));
 
-  dummyVfs.pAppData = (void*)autolockIoFinder;  
+  dummyVfs.pAppData = (void*)&autolockIoFinder;
   rc = fillInUnixFile(&dummyVfs, fd, dirfd, (sqlite3_file*)pNew, path, 0, 0);
   if( rc==SQLITE_OK ){
     *ppFile = pNew;
@@ -4322,7 +4355,7 @@
     rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, SHARED_LOCK);
     if( rc==SQLITE_OK ){
       int pError = 0;
-      memset(testValue, 0, CONCHLEN); // conch is fixed size
+      memset(testValue, 0, CONCHLEN); /* conch is fixed size */
       rc = proxyGetHostID(testValue, &pError);
       if( (rc&0xff)==SQLITE_IOERR ){
         pFile->lastErrno = pError;
@@ -4423,12 +4456,13 @@
       if( fd>=0 ){
         pFile->h = fd;
       }else{
-        rc=SQLITE_CANTOPEN; // SQLITE_BUSY? proxyTakeConch called during locking
+        rc=SQLITE_CANTOPEN; /* SQLITE_BUSY? proxyTakeConch called
+                               during locking */
       }
     }
     if( rc==SQLITE_OK && !pCtx->lockProxy ){
       char *path = tLockPath ? tLockPath : pCtx->lockProxyPath;
-      // ACS: Need to make a copy of path sometimes
+      /* ACS: Need to make a copy of path sometimes */
       rc = proxyCreateUnixFile(path, &pCtx->lockProxy);
     }
     if( rc==SQLITE_OK ){
@@ -4849,8 +4883,13 @@
 int sqlite3_os_init(void){ 
   /* 
   ** The following macro defines an initializer for an sqlite3_vfs object.
-  ** The name of the VFS is NAME.  The pAppData is a pointer to a "finder"
-  ** function.  The FINDER parameter to this macro is the name of the
+  ** The name of the VFS is NAME.  The pAppData is a pointer to a pointer
+  ** to the "finder" function.  (pAppData is a pointer to a pointer because
+  ** silly C90 rules prohibit a void* from being cast to a function pointer
+  ** and so we have to go through the intermediate pointer to avoid problems
+  ** when compiling with -pedantic-errors on GCC.)
+  **
+  ** The FINDER parameter to this macro is the name of the pointer to the
   ** finder-function.  The finder-function returns a pointer to the
   ** sqlite_io_methods object that implements the desired locking
   ** behaviors.  See the division above that contains the IOMETHODS
@@ -4868,7 +4907,7 @@
     MAX_PATHNAME,         /* mxPathname */                  \
     0,                    /* pNext */                       \
     VFSNAME,              /* zName */                       \
-    (void*)FINDER,        /* pAppData */                    \
+    (void*)&FINDER,       /* pAppData */                    \
     unixOpen,             /* xOpen */                       \
     unixDelete,           /* xDelete */                     \
     unixAccess,           /* xAccess */                     \
diff --git a/src/os_win.c b/src/os_win.c
index 833c24c..7f32b43 100644
--- a/src/os_win.c
+++ b/src/os_win.c
@@ -12,7 +12,7 @@
 **
 ** This file contains code that is specific to windows.
 **
-** $Id: os_win.c,v 1.140 2008/11/19 21:35:47 shane Exp $
+** $Id: os_win.c,v 1.141 2008/12/08 18:19:18 drh Exp $
 */
 #include "sqliteInt.h"
 #if SQLITE_OS_WIN               /* This file is used for windows only */
@@ -1527,14 +1527,14 @@
 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
   getLastErrorMsg(nBuf, zBufOut);
 }
-void *winDlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol){
+void (*winDlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol))(void){
 #if SQLITE_OS_WINCE
   /* The GetProcAddressA() routine is only available on wince. */
-  return GetProcAddressA((HANDLE)pHandle, zSymbol);
+  return (void(*)(void))GetProcAddressA((HANDLE)pHandle, zSymbol);
 #else
   /* All other windows platforms expect GetProcAddress() to take
   ** an Ansi string regardless of the _UNICODE setting */
-  return GetProcAddress((HANDLE)pHandle, zSymbol);
+  return (void(*)(void))GetProcAddress((HANDLE)pHandle, zSymbol);
 #endif
 }
 void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
diff --git a/src/random.c b/src/random.c
index 7fe42a5..eb3ec19 100644
--- a/src/random.c
+++ b/src/random.c
@@ -15,7 +15,7 @@
 ** Random numbers are used by some of the database backends in order
 ** to generate random integer keys for tables or random filenames.
 **
-** $Id: random.c,v 1.27 2008/10/07 15:25:48 drh Exp $
+** $Id: random.c,v 1.28 2008/12/08 18:19:18 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -27,7 +27,7 @@
   unsigned char isInit;          /* True if initialized */
   unsigned char i, j;            /* State variables */
   unsigned char s[256];          /* State variables */
-} sqlite3Prng = { 0, };
+} sqlite3Prng;
 
 /*
 ** Get a single 8-bit random value from the RC4 PRNG.  The Mutex
@@ -126,7 +126,7 @@
 ** The sqlite3_test_control() interface calls these routines to
 ** control the PRNG.
 */
-static SQLITE_WSD struct sqlite3PrngType sqlite3SavedPrng = { 0, };
+static SQLITE_WSD struct sqlite3PrngType sqlite3SavedPrng;
 void sqlite3PrngSaveState(void){
   memcpy(
     &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng),
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index e98cf03..57ae442 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -30,7 +30,7 @@
 ** the version number) and changes its name to "sqlite3.h" as
 ** part of the build process.
 **
-** @(#) $Id: sqlite.h.in,v 1.416 2008/11/21 00:10:35 aswift Exp $
+** @(#) $Id: sqlite.h.in,v 1.417 2008/12/08 18:19:18 drh Exp $
 */
 #ifndef _SQLITE3_H_
 #define _SQLITE3_H_
@@ -874,7 +874,7 @@
   int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
   void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
   void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
-  void *(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol);
+  void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
   void (*xDlClose)(sqlite3_vfs*, void*);
   int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
   int (*xSleep)(sqlite3_vfs*, int microseconds);
@@ -5448,7 +5448,7 @@
 **
 ** {H12644} Automatic extensions apply across all threads.
 */
-int sqlite3_auto_extension(void *xEntryPoint);
+int sqlite3_auto_extension(void (*xEntryPoint)(void));
 
 /*
 ** CAPI3REF: Reset Automatic Extension Loading {H12660} <S20500>
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index adf0510..14a0793 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.803 2008/12/08 13:42:36 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.804 2008/12/08 18:19:18 drh Exp $
 */
 #ifndef _SQLITEINT_H_
 #define _SQLITEINT_H_
@@ -1994,13 +1994,15 @@
   void *pPage;                      /* Page cache memory */
   int szPage;                       /* Size of each page in pPage[] */
   int nPage;                        /* Number of pages in pPage[] */
+  int mxParserStack;                /* maximum depth of the parser stack */
+  int sharedCacheEnabled;           /* true if shared-cache mode enabled */
+  /* The above might be initialized to non-zero.  The following need to always
+  ** initially be zero, however. */
   int isInit;                       /* True after initialization has finished */
   int inProgress;                   /* True while initialization in progress */
   int isMallocInit;                 /* True after malloc is initialized */
   sqlite3_mutex *pInitMutex;        /* Mutex used by sqlite3_initialize() */
   int nRefInitMutex;                /* Number of users of pInitMutex */
-  int mxParserStack;                /* maximum depth of the parser stack */
-  int sharedCacheEnabled;           /* true if shared-cache mode enabled */
 };
 
 /*