]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
More strict aliasing fixes. The single source file library now runs
authordrh <drh@noemail.net>
Tue, 27 Mar 2007 13:36:37 +0000 (13:36 +0000)
committerdrh <drh@noemail.net>
Tue, 27 Mar 2007 13:36:37 +0000 (13:36 +0000)
successfully with -fstrict-alias. (CVS 3725)

FossilOrigin-Name: c8a8a189a82500aab501e9949f5b197c0b80b3a9

manifest
manifest.uuid
src/build.c
src/expr.c
src/pager.c
src/sqliteInt.h
src/util.c
src/vdbe.c
src/vdbeaux.c
src/where.c

index 16c502c9a9bc5044c1ded2905b19055abdaa1c5b..8c9bd7024b152bda92808fe035db146e430b6b55 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Get\sthe\s-DSQLITE_OMIT_XFER_OPT\soption\sworking.\s\sRun\sspeed\stests\son\sa\sfull\nregression.\s\sAdd\sthe\sscript\sfor\sgenerating\ssqlite3.c.\s(CVS\s3724)
-D 2007-03-27T12:04:06
+C More\sstrict\saliasing\sfixes.\s\sThe\ssingle\ssource\sfile\slibrary\snow\sruns\nsuccessfully\swith\s-fstrict-alias.\s(CVS\s3725)
+D 2007-03-27T13:36:37
 F Makefile.in 1fe3d0b46e40fd684e1e61f8e8056cefed16de9f
 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -60,13 +60,13 @@ F src/attach.c 9b5a9c50fb92883e3404353b225674142da826cd
 F src/auth.c 902f4722661c796b97f007d9606bd7529c02597f
 F src/btree.c 0659070eb438bae32cec8afebe6d8d390024d952
 F src/btree.h 066444ee25bd6e6accb997bfd2cf5ace14dbcd00
-F src/build.c fe2fcebc9232a7dec77d7602a41c0d3bc2e7fa5d
+F src/build.c d178bd7c8117f5f47694da9a0d5f336e85528180
 F src/callback.c 31d22b4919c7645cbcbb1591ce2453e8c677c558
 F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675
 F src/date.c 393c73fc027597e008dcd81454544659e978b05c
 F src/delete.c 151d08386bf9c9e7f92f6b9106c71efec2def184
 F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
-F src/expr.c 971dd206ec0fa82d9fd1abb587a40df226f98966
+F src/expr.c a8740c24af3f39f2d502be1a1c640c96435eaac0
 F src/func.c 94372fe3cf26b81d4dcdc15f98ff240c37c8c708
 F src/hash.c 449f3d6620193aa557f5d86cbc5cc6b87702b185
 F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564
@@ -86,7 +86,7 @@ F src/os_unix.c 1f32d15449caa02ada876a0e5b7b774d90e1be77
 F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
 F src/os_win.c 13708a58aa24a9960fa45ac4a681e34f881ae77c
 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
-F src/pager.c f40ac7af27f3494e5c82807d09a7e23d741aaf75
+F src/pager.c 7a60e7e1f8b5abe841282a3dc90823b73fefe8b8
 F src/pager.h 3c16500c25051536e43fb19e246e58fc7cb51d9f
 F src/parse.y bcfe366c1fd61cfc40e5344eb69a31997a821af0
 F src/pragma.c 9cb8b94e7d38ba35a86037bd517d07ba9870b4b2
@@ -98,7 +98,7 @@ F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
 F src/shell.c 3ae4654560e91220a95738a73d135d91d937cda1
 F src/sqlite.h.in 6b7383baf76070214f6381f603328ca9b22a7fae
 F src/sqlite3ext.h 832e13de075d920e2c76584e2b7af1054bb212df
-F src/sqliteInt.h 86ab83dddf32325d8f2afd92575d8e0168ecb8c2
+F src/sqliteInt.h 7a3d16cd517dfce73eeac10963275454d6421f82
 F src/table.c 6d0da66dde26ee75614ed8f584a1996467088d06
 F src/tclsqlite.c cd2b3b86ab07c0e0779f6c6e71e72c6c7dc1e704
 F src/test1.c 7c8f2786dbd55bab35c7529045a3d72f54c7f98b
@@ -120,17 +120,17 @@ F src/tokenize.c bb1732ef2b6fc2143f93ff28a45d3dcb04c1d396
 F src/trigger.c 8c55d31876013ed4e97ee7ce24478fbe00db49bb
 F src/update.c 876b3142b8db9ce6ddf8374a2ced65e576acabc7
 F src/utf.c 67ecb1032bc0b42c105e88d65ef9d9f626eb0e1f
-F src/util.c 729a528fc35e858d33e270676d6a61b3eff525d4
+F src/util.c 8e8180ee5597f2474c1da311ff3c464b6966c0f1
 F src/vacuum.c 327c6ffa38935163db7c1e256ff5f788e901b318
-F src/vdbe.c df2aa8cf692eeffd4027a2a8ec71aa0248a13e87
+F src/vdbe.c b452ec53e3b8d81b0f21af980ed8fd1547cb6f5a
 F src/vdbe.h 0025259af1939fb264a545816c69e4b5b8d52691
 F src/vdbeInt.h b2ca85ca8abfbba86e380b06c7673dc81c6784c3
 F src/vdbeapi.c 6cff63a5b3a52af04b2bef0f7e27ed7ea6f85183
-F src/vdbeaux.c b196911da933c66df287fd4b1498a2d2ef5daa93
+F src/vdbeaux.c b98177089a57f496a6a36edef038b9d5df2befdb
 F src/vdbefifo.c 3ca8049c561d5d67cbcb94dc909ae9bb68c0bf8f
 F src/vdbemem.c 58a8be2231b0b13e2e77098debe173e79d22f791
 F src/vtab.c 7fbda947e28cbe7adb3ba752a76ca9ef29936750
-F src/where.c 0825fabc1a185af1567dc82e63683cd9b47d9e22
+F src/where.c 0ef9acc43cc696b01a3f1019bc07c8d8e0849999
 F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/all.test 60267b055e82de4fb8b841eabb014bc2f836a4eb
@@ -442,7 +442,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 42c038518c4ba0ef827a5717d450f95165b3c729
-R 76a8b8a54e51e640933974bfc36cdc29
+P 1dd9d0775a8199047de30218af71a31c731fedb1
+R 788fdfcff1fda81d98ec4386ff9fe62b
 U drh
-Z d7b781387df7f99692c8bcb17adac3b2
+Z a721db4fcd13afdccda21f5563fa1a8b
index 4a8d7d487c544c5cbfecfa64aaee6dd73825af10..bf55336c86e15c1a8c04444ab8e5d6ca089c863b 100644 (file)
@@ -1 +1 @@
-1dd9d0775a8199047de30218af71a31c731fedb1
\ No newline at end of file
+c8a8a189a82500aab501e9949f5b197c0b80b3a9
\ No newline at end of file
index 0e14d7323317f5c5feb816ca78f143acefaaf33e..de3629be7cafdf08061db0318ee16c2e0e16fb77 100644 (file)
@@ -22,7 +22,7 @@
 **     COMMIT
 **     ROLLBACK
 **
-** $Id: build.c,v 1.416 2007/03/26 22:05:01 drh Exp $
+** $Id: build.c,v 1.417 2007/03/27 13:36:37 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -82,7 +82,7 @@ void sqlite3TableLock(
   }
 
   nBytes = sizeof(TableLock) * (pParse->nTableLock+1);
-  sqliteReallocOrFree(&pParse->aTableLock, nBytes);
+  pParse->aTableLock = sqliteReallocOrFree(pParse->aTableLock, nBytes);
   if( pParse->aTableLock ){
     p = &pParse->aTableLock[pParse->nTableLock++];
     p->iDb = iDb;
@@ -2783,45 +2783,46 @@ exit_drop_index:
 }
 
 /*
-** ppArray points into a structure where there is an array pointer
-** followed by two integers. The first integer is the
-** number of elements in the structure array.  The second integer
-** is the number of allocated slots in the array.
+** pArray is a pointer to an array of objects.  Each object in the
+** array is szEntry bytes in size.  This routine allocates a new
+** object on the end of the array.
 **
-** In other words, the structure looks something like this:
+** *pnEntry is the number of entries already in use.  *pnAlloc is
+** the previously allocated size of the array.  initSize is the
+** suggested initial array size allocation.
 **
-**        struct Example1 {
-**          struct subElem *aEntry;
-**          int nEntry;
-**          int nAlloc;
-**        }
+** The index of the new entry is returned in *pIdx.
 **
-** The pnEntry parameter points to the equivalent of Example1.nEntry.
-**
-** This routine allocates a new slot in the array, zeros it out,
-** and returns its index.  If malloc fails a negative number is returned.
-**
-** szEntry is the sizeof of a single array entry.  initSize is the 
-** number of array entries allocated on the initial allocation.
+** This routine returns a pointer to the array of objects.  This
+** might be the same as the pArray parameter or it might be a different
+** pointer if the array was resized.
 */
-int sqlite3ArrayAllocate(void *ppArray, int szEntry, int initSize){
-  char *p;
-  void **pp = (void**)ppArray;
-  int *an = (int*)&pp[1];
-  if( an[0]>=an[1] ){
+void *sqlite3ArrayAllocate(
+  void *pArray,     /* Array of objects.  Might be reallocated */
+  int szEntry,      /* Size of each object in the array */
+  int initSize,     /* Suggested initial allocation, in elements */
+  int *pnEntry,     /* Number of objects currently in use */
+  int *pnAlloc,     /* Current size of the allocation, in elements */
+  int *pIdx         /* Write the index of a new slot here */
+){
+  char *z;
+  if( *pnEntry >= *pnAlloc ){
     void *pNew;
     int newSize;
-    newSize = an[1]*2 + initSize;
-    pNew = sqliteRealloc(*pp, newSize*szEntry);
+    newSize = (*pnAlloc)*2 + initSize;
+    pNew = sqliteRealloc(pArray, newSize*szEntry);
     if( pNew==0 ){
-      return -1;
+      *pIdx = -1;
+      return pArray;
     }
-    an[1] = newSize;
-    *pp = pNew;
+    *pnAlloc = newSize;
+    pArray = pNew;
   }
-  p = *pp;
-  memset(&p[an[0]*szEntry], 0, szEntry);
-  return an[0]++;
+  z = (char*)pArray;
+  memset(&z[*pnEntry * szEntry], 0, szEntry);
+  *pIdx = *pnEntry;
+  ++*pnEntry;
+  return pArray;
 }
 
 /*
@@ -2837,7 +2838,14 @@ IdList *sqlite3IdListAppend(IdList *pList, Token *pToken){
     if( pList==0 ) return 0;
     pList->nAlloc = 0;
   }
-  i = sqlite3ArrayAllocate(&pList->a, sizeof(pList->a[0]), 5);
+  pList->a = sqlite3ArrayAllocate(
+      pList->a,
+      sizeof(pList->a[0]),
+      5,
+      &pList->nId,
+      &pList->nAlloc,
+      &i
+  );
   if( i<0 ){
     sqlite3IdListDelete(pList);
     return 0;
index a9ae1e819e98a349ef461a56f593246694563f66..934f988406377110476157b7baf3ce4d49d29375 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains routines used for analyzing expressions and
 ** for generating VDBE code that evaluates expressions in SQLite.
 **
-** $Id: expr.c,v 1.282 2007/03/26 22:05:01 drh Exp $
+** $Id: expr.c,v 1.283 2007/03/27 13:36:37 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -404,7 +404,7 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
       pExpr->iTable = ++pParse->nVar;
       if( pParse->nVarExpr>=pParse->nVarExprAlloc-1 ){
         pParse->nVarExprAlloc += pParse->nVarExprAlloc + 10;
-        sqliteReallocOrFree(&pParse->apVarExpr,
+        pParse->apVarExpr = sqliteReallocOrFree(pParse->apVarExpr,
                        pParse->nVarExprAlloc*sizeof(pParse->apVarExpr[0]) );
       }
       if( !sqlite3MallocFailed() ){
@@ -2237,10 +2237,14 @@ int sqlite3ExprCompare(Expr *pA, Expr *pB){
 */
 static int addAggInfoColumn(AggInfo *pInfo){
   int i;
-  i = sqlite3ArrayAllocate(&pInfo->aCol, sizeof(pInfo->aCol[0]), 3);
-  if( i<0 ){
-    return -1;
-  }
+  pInfo->aCol = sqlite3ArrayAllocate(
+       pInfo->aCol,
+       sizeof(pInfo->aCol[0]),
+       3,
+       &pInfo->nColumn,
+       &pInfo->nColumnAlloc,
+       &i
+  );
   return i;
 }    
 
@@ -2250,10 +2254,14 @@ static int addAggInfoColumn(AggInfo *pInfo){
 */
 static int addAggInfoFunc(AggInfo *pInfo){
   int i;
-  i = sqlite3ArrayAllocate(&pInfo->aFunc, sizeof(pInfo->aFunc[0]), 2);
-  if( i<0 ){
-    return -1;
-  }
+  pInfo->aFunc = sqlite3ArrayAllocate(
+       pInfo->aFunc,
+       sizeof(pInfo->aFunc[0]),
+       3,
+       &pInfo->nFunc,
+       &pInfo->nFuncAlloc,
+       &i
+  );
   return i;
 }    
 
index cf4249c8fe96c8042ba1cf7dab4d02736e760ba8..10817125fd2265c635b4c75c8106fa12c3b6a218 100644 (file)
@@ -18,7 +18,7 @@
 ** file simultaneously, or one process from reading the database while
 ** another is writing.
 **
-** @(#) $Id: pager.c,v 1.300 2007/03/26 22:05:02 drh Exp $
+** @(#) $Id: pager.c,v 1.301 2007/03/27 13:36:37 drh Exp $
 */
 #ifndef SQLITE_OMIT_DISKIO
 #include "sqliteInt.h"
@@ -1828,7 +1828,7 @@ int sqlite3PagerSetPagesize(Pager *pPager, int pageSize){
   if( !pPager->memDb && pPager->nRef==0 ){
     pager_reset(pPager);
     pPager->pageSize = pageSize;
-    sqlite3ReallocOrFree(&pPager->pTmpSpace, pageSize);
+    pPager->pTmpSpace = sqlite3ReallocOrFree(pPager->pTmpSpace, pageSize);
   }
   return pPager->pageSize;
 }
index 7b8e71d39e75601f154851a188e1c872dc4dd17f..fcf6c2d590810010d85cdfbc1a3136181ee11d8c 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.544 2007/03/26 22:05:02 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.545 2007/03/27 13:36:37 drh Exp $
 */
 #ifndef _SQLITEINT_H_
 #define _SQLITEINT_H_
@@ -1567,7 +1567,7 @@ void *sqlite3Realloc(void*,int);
 char *sqlite3StrDup(const char*);
 char *sqlite3StrNDup(const char*, int);
 # define sqlite3CheckMemory(a,b)
-void sqlite3ReallocOrFree(void*,int);
+void *sqlite3ReallocOrFree(void*,int);
 void sqlite3FreeX(void*);
 void *sqlite3MallocX(int);
 int sqlite3AllocSize(void *);
@@ -1624,7 +1624,7 @@ void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int);
 void sqlite3DropTable(Parse*, SrcList*, int, int);
 void sqlite3DeleteTable(sqlite3*, Table*);
 void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
-int sqlite3ArrayAllocate(void*,int,int);
+void *sqlite3ArrayAllocate(void*,int,int,int*,int*,int*);
 IdList *sqlite3IdListAppend(IdList*, Token*);
 int sqlite3IdListIndex(IdList*,const char*);
 SrcList *sqlite3SrcListAppend(SrcList*, Token*, Token*);
index bb08c097c1f2a0e65f2b424fedb1b07947cf8fb8..c46c2df81c6da8dd21906c6cee327c209a85ec27 100644 (file)
@@ -14,7 +14,7 @@
 ** This file contains functions for allocating memory, comparing
 ** strings, and stuff like that.
 **
-** $Id: util.c,v 1.196 2007/03/26 22:05:02 drh Exp $
+** $Id: util.c,v 1.197 2007/03/27 13:36:37 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -661,13 +661,13 @@ void *sqlite3Malloc(int n, int doMemManage){
   }
   return p;
 }
-void sqlite3ReallocOrFree(void *pp, int n){
-  char **x = (char**)pp;
-  void *p = sqlite3Realloc(*x, n);
-  if( !p ){
-    sqlite3FreeX(*x);
+void *sqlite3ReallocOrFree(void *p, int n){
+  void *pNew;
+  pNew = sqlite3Realloc(p, n);
+  if( !pNew ){
+    sqlite3FreeX(p);
   }
-  *x = p;
+  return pNew;
 }
 
 /*
index 2f90af6151fa4a7ab84ab40bc63ed1956238bf68..f38ac964c55d767738ea118a5f179702180f4c13 100644 (file)
@@ -43,7 +43,7 @@
 ** in this file for details.  If in doubt, do not deviate from existing
 ** commenting and indentation practices when changing or adding code.
 **
-** $Id: vdbe.c,v 1.592 2007/03/26 22:05:02 drh Exp $
+** $Id: vdbe.c,v 1.593 2007/03/27 13:36:37 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -4236,7 +4236,8 @@ case OP_ContextPush: {        /* no-push */
   /* FIX ME: This should be allocated as part of the vdbe at compile-time */
   if( i>=p->contextStackDepth ){
     p->contextStackDepth = i+1;
-    sqliteReallocOrFree(&p->contextStack, sizeof(Context)*(i+1));
+    p->contextStack = sqliteReallocOrFree(p->contextStack,
+                                          sizeof(Context)*(i+1));
     if( p->contextStack==0 ) goto no_mem;
   }
   pContext = &p->contextStack[i];
index 559d362cdb705b87d2533632e15c37e82cf62f4b..45bf4a1a5f99c6f2afaf37fc6bfb29f89bacc6df 100644 (file)
@@ -195,7 +195,8 @@ int sqlite3VdbeMakeLabel(Vdbe *p){
   assert( p->magic==VDBE_MAGIC_INIT );
   if( i>=p->nLabelAlloc ){
     p->nLabelAlloc = p->nLabelAlloc*2 + 10;
-    sqliteReallocOrFree(&p->aLabel, p->nLabelAlloc*sizeof(p->aLabel[0]));
+    p->aLabel = sqliteReallocOrFree(p->aLabel,
+                                    p->nLabelAlloc*sizeof(p->aLabel[0]));
   }
   if( p->aLabel ){
     p->aLabel[i] = -1;
index f457068e7c42c940fd6b07726384b66de51deab9..031053a77f9c75ac1893d6ca6d9173004df54b49 100644 (file)
@@ -16,7 +16,7 @@
 ** so is applicable.  Because this module is responsible for selecting
 ** indices, you might also think of this module as the "query optimizer".
 **
-** $Id: where.c,v 1.240 2007/03/26 22:05:02 drh Exp $
+** $Id: where.c,v 1.241 2007/03/27 13:36:37 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -1707,8 +1707,8 @@ static void codeEqualityTerm(
     sqlite3VdbeAddOp(v, OP_Rewind, iTab, 0);
     VdbeComment((v, "# %.*s", pX->span.n, pX->span.z));
     pLevel->nIn++;
-    sqliteReallocOrFree(&pLevel->aInLoop,
-                        sizeof(pLevel->aInLoop[0])*2*pLevel->nIn);
+    pLevel->aInLoop = sqliteReallocOrFree(pLevel->aInLoop,
+                                    sizeof(pLevel->aInLoop[0])*2*pLevel->nIn);
     aIn = pLevel->aInLoop;
     if( aIn ){
       aIn += pLevel->nIn*2 - 2;