/ Check-in [c8a8a189]
Login

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

Overview
Comment:More strict aliasing fixes. The single source file library now runs successfully with -fstrict-alias. (CVS 3725)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c8a8a189a82500aab501e9949f5b197c0b80b3a9
User & Date: drh 2007-03-27 13:36:37
Context
2007-03-27
14:05
Fix off-by-one errors in the header comments of btree.c. Ticket #2272. (CVS 3726) check-in: a70ea720 user: drh tags: trunk
13:36
More strict aliasing fixes. The single source file library now runs successfully with -fstrict-alias. (CVS 3725) check-in: c8a8a189 user: drh tags: trunk
12:04
Get the -DSQLITE_OMIT_XFER_OPT option working. Run speed tests on a full regression. Add the script for generating sqlite3.c. (CVS 3724) check-in: 1dd9d077 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

    18     18   **     CREATE INDEX
    19     19   **     DROP INDEX
    20     20   **     creating ID lists
    21     21   **     BEGIN TRANSACTION
    22     22   **     COMMIT
    23     23   **     ROLLBACK
    24     24   **
    25         -** $Id: build.c,v 1.416 2007/03/26 22:05:01 drh Exp $
           25  +** $Id: build.c,v 1.417 2007/03/27 13:36:37 drh Exp $
    26     26   */
    27     27   #include "sqliteInt.h"
    28     28   #include <ctype.h>
    29     29   
    30     30   /*
    31     31   ** This routine is called when a new SQL statement is beginning to
    32     32   ** be parsed.  Initialize the pParse structure as needed.
................................................................................
    78     78       if( p->iDb==iDb && p->iTab==iTab ){
    79     79         p->isWriteLock = (p->isWriteLock || isWriteLock);
    80     80         return;
    81     81       }
    82     82     }
    83     83   
    84     84     nBytes = sizeof(TableLock) * (pParse->nTableLock+1);
    85         -  sqliteReallocOrFree(&pParse->aTableLock, nBytes);
           85  +  pParse->aTableLock = sqliteReallocOrFree(pParse->aTableLock, nBytes);
    86     86     if( pParse->aTableLock ){
    87     87       p = &pParse->aTableLock[pParse->nTableLock++];
    88     88       p->iDb = iDb;
    89     89       p->iTab = iTab;
    90     90       p->isWriteLock = isWriteLock;
    91     91       p->zName = zName;
    92     92     }
................................................................................
  2779   2779     }
  2780   2780   
  2781   2781   exit_drop_index:
  2782   2782     sqlite3SrcListDelete(pName);
  2783   2783   }
  2784   2784   
  2785   2785   /*
  2786         -** ppArray points into a structure where there is an array pointer
  2787         -** followed by two integers. The first integer is the
  2788         -** number of elements in the structure array.  The second integer
  2789         -** is the number of allocated slots in the array.
  2790         -**
  2791         -** In other words, the structure looks something like this:
  2792         -**
  2793         -**        struct Example1 {
  2794         -**          struct subElem *aEntry;
  2795         -**          int nEntry;
  2796         -**          int nAlloc;
  2797         -**        }
  2798         -**
  2799         -** The pnEntry parameter points to the equivalent of Example1.nEntry.
  2800         -**
  2801         -** This routine allocates a new slot in the array, zeros it out,
  2802         -** and returns its index.  If malloc fails a negative number is returned.
  2803         -**
  2804         -** szEntry is the sizeof of a single array entry.  initSize is the 
  2805         -** number of array entries allocated on the initial allocation.
  2806         -*/
  2807         -int sqlite3ArrayAllocate(void *ppArray, int szEntry, int initSize){
  2808         -  char *p;
  2809         -  void **pp = (void**)ppArray;
  2810         -  int *an = (int*)&pp[1];
  2811         -  if( an[0]>=an[1] ){
         2786  +** pArray is a pointer to an array of objects.  Each object in the
         2787  +** array is szEntry bytes in size.  This routine allocates a new
         2788  +** object on the end of the array.
         2789  +**
         2790  +** *pnEntry is the number of entries already in use.  *pnAlloc is
         2791  +** the previously allocated size of the array.  initSize is the
         2792  +** suggested initial array size allocation.
         2793  +**
         2794  +** The index of the new entry is returned in *pIdx.
         2795  +**
         2796  +** This routine returns a pointer to the array of objects.  This
         2797  +** might be the same as the pArray parameter or it might be a different
         2798  +** pointer if the array was resized.
         2799  +*/
         2800  +void *sqlite3ArrayAllocate(
         2801  +  void *pArray,     /* Array of objects.  Might be reallocated */
         2802  +  int szEntry,      /* Size of each object in the array */
         2803  +  int initSize,     /* Suggested initial allocation, in elements */
         2804  +  int *pnEntry,     /* Number of objects currently in use */
         2805  +  int *pnAlloc,     /* Current size of the allocation, in elements */
         2806  +  int *pIdx         /* Write the index of a new slot here */
         2807  +){
         2808  +  char *z;
         2809  +  if( *pnEntry >= *pnAlloc ){
  2812   2810       void *pNew;
  2813   2811       int newSize;
  2814         -    newSize = an[1]*2 + initSize;
  2815         -    pNew = sqliteRealloc(*pp, newSize*szEntry);
         2812  +    newSize = (*pnAlloc)*2 + initSize;
         2813  +    pNew = sqliteRealloc(pArray, newSize*szEntry);
  2816   2814       if( pNew==0 ){
  2817         -      return -1;
         2815  +      *pIdx = -1;
         2816  +      return pArray;
  2818   2817       }
  2819         -    an[1] = newSize;
  2820         -    *pp = pNew;
         2818  +    *pnAlloc = newSize;
         2819  +    pArray = pNew;
  2821   2820     }
  2822         -  p = *pp;
  2823         -  memset(&p[an[0]*szEntry], 0, szEntry);
  2824         -  return an[0]++;
         2821  +  z = (char*)pArray;
         2822  +  memset(&z[*pnEntry * szEntry], 0, szEntry);
         2823  +  *pIdx = *pnEntry;
         2824  +  ++*pnEntry;
         2825  +  return pArray;
  2825   2826   }
  2826   2827   
  2827   2828   /*
  2828   2829   ** Append a new element to the given IdList.  Create a new IdList if
  2829   2830   ** need be.
  2830   2831   **
  2831   2832   ** A new IdList is returned, or NULL if malloc() fails.
................................................................................
  2833   2834   IdList *sqlite3IdListAppend(IdList *pList, Token *pToken){
  2834   2835     int i;
  2835   2836     if( pList==0 ){
  2836   2837       pList = sqliteMalloc( sizeof(IdList) );
  2837   2838       if( pList==0 ) return 0;
  2838   2839       pList->nAlloc = 0;
  2839   2840     }
  2840         -  i = sqlite3ArrayAllocate(&pList->a, sizeof(pList->a[0]), 5);
         2841  +  pList->a = sqlite3ArrayAllocate(
         2842  +      pList->a,
         2843  +      sizeof(pList->a[0]),
         2844  +      5,
         2845  +      &pList->nId,
         2846  +      &pList->nAlloc,
         2847  +      &i
         2848  +  );
  2841   2849     if( i<0 ){
  2842   2850       sqlite3IdListDelete(pList);
  2843   2851       return 0;
  2844   2852     }
  2845   2853     pList->a[i].zName = sqlite3NameFromToken(pToken);
  2846   2854     return pList;
  2847   2855   }

Changes to src/expr.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains routines used for analyzing expressions and
    13     13   ** for generating VDBE code that evaluates expressions in SQLite.
    14     14   **
    15         -** $Id: expr.c,v 1.282 2007/03/26 22:05:01 drh Exp $
           15  +** $Id: expr.c,v 1.283 2007/03/27 13:36:37 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <ctype.h>
    19     19   
    20     20   /*
    21     21   ** Return the 'affinity' of the expression pExpr if any.
    22     22   **
................................................................................
   400    400           break;
   401    401         }
   402    402       }
   403    403       if( i>=pParse->nVarExpr ){
   404    404         pExpr->iTable = ++pParse->nVar;
   405    405         if( pParse->nVarExpr>=pParse->nVarExprAlloc-1 ){
   406    406           pParse->nVarExprAlloc += pParse->nVarExprAlloc + 10;
   407         -        sqliteReallocOrFree(&pParse->apVarExpr,
          407  +        pParse->apVarExpr = sqliteReallocOrFree(pParse->apVarExpr,
   408    408                          pParse->nVarExprAlloc*sizeof(pParse->apVarExpr[0]) );
   409    409         }
   410    410         if( !sqlite3MallocFailed() ){
   411    411           assert( pParse->apVarExpr!=0 );
   412    412           pParse->apVarExpr[pParse->nVarExpr++] = pExpr;
   413    413         }
   414    414       }
................................................................................
  2233   2233   
  2234   2234   /*
  2235   2235   ** Add a new element to the pAggInfo->aCol[] array.  Return the index of
  2236   2236   ** the new element.  Return a negative number if malloc fails.
  2237   2237   */
  2238   2238   static int addAggInfoColumn(AggInfo *pInfo){
  2239   2239     int i;
  2240         -  i = sqlite3ArrayAllocate(&pInfo->aCol, sizeof(pInfo->aCol[0]), 3);
  2241         -  if( i<0 ){
  2242         -    return -1;
  2243         -  }
         2240  +  pInfo->aCol = sqlite3ArrayAllocate(
         2241  +       pInfo->aCol,
         2242  +       sizeof(pInfo->aCol[0]),
         2243  +       3,
         2244  +       &pInfo->nColumn,
         2245  +       &pInfo->nColumnAlloc,
         2246  +       &i
         2247  +  );
  2244   2248     return i;
  2245   2249   }    
  2246   2250   
  2247   2251   /*
  2248   2252   ** Add a new element to the pAggInfo->aFunc[] array.  Return the index of
  2249   2253   ** the new element.  Return a negative number if malloc fails.
  2250   2254   */
  2251   2255   static int addAggInfoFunc(AggInfo *pInfo){
  2252   2256     int i;
  2253         -  i = sqlite3ArrayAllocate(&pInfo->aFunc, sizeof(pInfo->aFunc[0]), 2);
  2254         -  if( i<0 ){
  2255         -    return -1;
  2256         -  }
         2257  +  pInfo->aFunc = sqlite3ArrayAllocate(
         2258  +       pInfo->aFunc,
         2259  +       sizeof(pInfo->aFunc[0]),
         2260  +       3,
         2261  +       &pInfo->nFunc,
         2262  +       &pInfo->nFuncAlloc,
         2263  +       &i
         2264  +  );
  2257   2265     return i;
  2258   2266   }    
  2259   2267   
  2260   2268   /*
  2261   2269   ** This is an xFunc for walkExprTree() used to implement 
  2262   2270   ** sqlite3ExprAnalyzeAggregates().  See sqlite3ExprAnalyzeAggregates
  2263   2271   ** for additional information.

Changes to src/pager.c.

    14     14   ** The pager is used to access a database disk file.  It implements
    15     15   ** atomic commit and rollback through the use of a journal file that
    16     16   ** is separate from the database file.  The pager also implements file
    17     17   ** locking to prevent two processes from writing the same database
    18     18   ** file simultaneously, or one process from reading the database while
    19     19   ** another is writing.
    20     20   **
    21         -** @(#) $Id: pager.c,v 1.300 2007/03/26 22:05:02 drh Exp $
           21  +** @(#) $Id: pager.c,v 1.301 2007/03/27 13:36:37 drh Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   #include "os.h"
    26     26   #include "pager.h"
    27     27   #include <assert.h>
    28     28   #include <string.h>
................................................................................
  1824   1824   ** and returned.
  1825   1825   */
  1826   1826   int sqlite3PagerSetPagesize(Pager *pPager, int pageSize){
  1827   1827     assert( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE );
  1828   1828     if( !pPager->memDb && pPager->nRef==0 ){
  1829   1829       pager_reset(pPager);
  1830   1830       pPager->pageSize = pageSize;
  1831         -    sqlite3ReallocOrFree(&pPager->pTmpSpace, pageSize);
         1831  +    pPager->pTmpSpace = sqlite3ReallocOrFree(pPager->pTmpSpace, pageSize);
  1832   1832     }
  1833   1833     return pPager->pageSize;
  1834   1834   }
  1835   1835   
  1836   1836   /*
  1837   1837   ** The following set of routines are used to disable the simulated
  1838   1838   ** I/O error mechanism.  These routines are used to avoid simulated

Changes to src/sqliteInt.h.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Internal interface definitions for SQLite.
    13     13   **
    14         -** @(#) $Id: sqliteInt.h,v 1.544 2007/03/26 22:05:02 drh Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.545 2007/03/27 13:36:37 drh Exp $
    15     15   */
    16     16   #ifndef _SQLITEINT_H_
    17     17   #define _SQLITEINT_H_
    18     18   
    19     19   #if defined(SQLITE_TCL) || defined(TCLSH)
    20     20   # include <tcl.h>
    21     21   #endif
................................................................................
  1563   1563   void *sqlite3Malloc(int,int);
  1564   1564   void *sqlite3MallocRaw(int,int);
  1565   1565   void sqlite3Free(void*);
  1566   1566   void *sqlite3Realloc(void*,int);
  1567   1567   char *sqlite3StrDup(const char*);
  1568   1568   char *sqlite3StrNDup(const char*, int);
  1569   1569   # define sqlite3CheckMemory(a,b)
  1570         -void sqlite3ReallocOrFree(void*,int);
         1570  +void *sqlite3ReallocOrFree(void*,int);
  1571   1571   void sqlite3FreeX(void*);
  1572   1572   void *sqlite3MallocX(int);
  1573   1573   int sqlite3AllocSize(void *);
  1574   1574   
  1575   1575   char *sqlite3MPrintf(const char*, ...);
  1576   1576   char *sqlite3VMPrintf(const char*, va_list);
  1577   1577   void sqlite3DebugPrintf(const char*, ...);
................................................................................
  1620   1620   #else
  1621   1621   # define sqlite3ViewGetColumnNames(A,B) 0
  1622   1622   #endif
  1623   1623   
  1624   1624   void sqlite3DropTable(Parse*, SrcList*, int, int);
  1625   1625   void sqlite3DeleteTable(sqlite3*, Table*);
  1626   1626   void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
  1627         -int sqlite3ArrayAllocate(void*,int,int);
         1627  +void *sqlite3ArrayAllocate(void*,int,int,int*,int*,int*);
  1628   1628   IdList *sqlite3IdListAppend(IdList*, Token*);
  1629   1629   int sqlite3IdListIndex(IdList*,const char*);
  1630   1630   SrcList *sqlite3SrcListAppend(SrcList*, Token*, Token*);
  1631   1631   SrcList *sqlite3SrcListAppendFromTerm(SrcList*, Token*, Token*, Token*,
  1632   1632                                         Select*, Expr*, IdList*);
  1633   1633   void sqlite3SrcListShiftJoinType(SrcList*);
  1634   1634   void sqlite3SrcListAssignCursors(Parse*, SrcList*);

Changes to src/util.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Utility functions used throughout sqlite.
    13     13   **
    14     14   ** This file contains functions for allocating memory, comparing
    15     15   ** strings, and stuff like that.
    16     16   **
    17         -** $Id: util.c,v 1.196 2007/03/26 22:05:02 drh Exp $
           17  +** $Id: util.c,v 1.197 2007/03/27 13:36:37 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "os.h"
    21     21   #include <stdarg.h>
    22     22   #include <ctype.h>
    23     23   
    24     24   /*
................................................................................
   657    657   void *sqlite3Malloc(int n, int doMemManage){
   658    658     void *p = sqlite3MallocRaw(n, doMemManage);
   659    659     if( p ){
   660    660       memset(p, 0, n);
   661    661     }
   662    662     return p;
   663    663   }
   664         -void sqlite3ReallocOrFree(void *pp, int n){
   665         -  char **x = (char**)pp;
   666         -  void *p = sqlite3Realloc(*x, n);
   667         -  if( !p ){
   668         -    sqlite3FreeX(*x);
          664  +void *sqlite3ReallocOrFree(void *p, int n){
          665  +  void *pNew;
          666  +  pNew = sqlite3Realloc(p, n);
          667  +  if( !pNew ){
          668  +    sqlite3FreeX(p);
   669    669     }
   670         -  *x = p;
          670  +  return pNew;
   671    671   }
   672    672   
   673    673   /*
   674    674   ** sqlite3ThreadSafeMalloc() and sqlite3ThreadSafeFree() are used in those
   675    675   ** rare scenarios where sqlite may allocate memory in one thread and free
   676    676   ** it in another. They are exactly the same as sqlite3Malloc() and 
   677    677   ** sqlite3Free() except that:

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.592 2007/03/26 22:05:02 drh Exp $
           46  +** $Id: vdbe.c,v 1.593 2007/03/27 13:36:37 drh Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include "os.h"
    50     50   #include <ctype.h>
    51     51   #include "vdbeInt.h"
    52     52   
    53     53   /*
................................................................................
  4232   4232     int i = p->contextStackTop++;
  4233   4233     Context *pContext;
  4234   4234   
  4235   4235     assert( i>=0 );
  4236   4236     /* FIX ME: This should be allocated as part of the vdbe at compile-time */
  4237   4237     if( i>=p->contextStackDepth ){
  4238   4238       p->contextStackDepth = i+1;
  4239         -    sqliteReallocOrFree(&p->contextStack, sizeof(Context)*(i+1));
         4239  +    p->contextStack = sqliteReallocOrFree(p->contextStack,
         4240  +                                          sizeof(Context)*(i+1));
  4240   4241       if( p->contextStack==0 ) goto no_mem;
  4241   4242     }
  4242   4243     pContext = &p->contextStack[i];
  4243   4244     pContext->lastRowid = db->lastRowid;
  4244   4245     pContext->nChange = p->nChange;
  4245   4246     pContext->sFifo = p->sFifo;
  4246   4247     sqlite3VdbeFifoInit(&p->sFifo);

Changes to src/vdbeaux.c.

   191    191   */
   192    192   int sqlite3VdbeMakeLabel(Vdbe *p){
   193    193     int i;
   194    194     i = p->nLabel++;
   195    195     assert( p->magic==VDBE_MAGIC_INIT );
   196    196     if( i>=p->nLabelAlloc ){
   197    197       p->nLabelAlloc = p->nLabelAlloc*2 + 10;
   198         -    sqliteReallocOrFree(&p->aLabel, p->nLabelAlloc*sizeof(p->aLabel[0]));
          198  +    p->aLabel = sqliteReallocOrFree(p->aLabel,
          199  +                                    p->nLabelAlloc*sizeof(p->aLabel[0]));
   199    200     }
   200    201     if( p->aLabel ){
   201    202       p->aLabel[i] = -1;
   202    203     }
   203    204     return -1-i;
   204    205   }
   205    206   

Changes to src/where.c.

    12     12   ** This module contains C code that generates VDBE code used to process
    13     13   ** the WHERE clause of SQL statements.  This module is reponsible for
    14     14   ** generating the code that loops through a table looking for applicable
    15     15   ** rows.  Indices are selected and used to speed the search when doing
    16     16   ** so is applicable.  Because this module is responsible for selecting
    17     17   ** indices, you might also think of this module as the "query optimizer".
    18     18   **
    19         -** $Id: where.c,v 1.240 2007/03/26 22:05:02 drh Exp $
           19  +** $Id: where.c,v 1.241 2007/03/27 13:36:37 drh Exp $
    20     20   */
    21     21   #include "sqliteInt.h"
    22     22   
    23     23   /*
    24     24   ** The number of bits in a Bitmask.  "BMS" means "BitMask Size".
    25     25   */
    26     26   #define BMS  (sizeof(Bitmask)*8)
................................................................................
  1703   1703   
  1704   1704       assert( pX->op==TK_IN );
  1705   1705       sqlite3CodeSubselect(pParse, pX);
  1706   1706       iTab = pX->iTable;
  1707   1707       sqlite3VdbeAddOp(v, OP_Rewind, iTab, 0);
  1708   1708       VdbeComment((v, "# %.*s", pX->span.n, pX->span.z));
  1709   1709       pLevel->nIn++;
  1710         -    sqliteReallocOrFree(&pLevel->aInLoop,
  1711         -                        sizeof(pLevel->aInLoop[0])*2*pLevel->nIn);
         1710  +    pLevel->aInLoop = sqliteReallocOrFree(pLevel->aInLoop,
         1711  +                                    sizeof(pLevel->aInLoop[0])*2*pLevel->nIn);
  1712   1712       aIn = pLevel->aInLoop;
  1713   1713       if( aIn ){
  1714   1714         aIn += pLevel->nIn*2 - 2;
  1715   1715         aIn[0] = iTab;
  1716   1716         aIn[1] = sqlite3VdbeAddOp(v, OP_Column, iTab, 0);
  1717   1717       }else{
  1718   1718         pLevel->nIn = 0;