/ Check-in [d9418851]
Login

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

Overview
Comment:Make sure all data structures have 8-byte alignment - necessary for the sparc architecture and helpful on other 64-bit platforms. Ticket #1232. Also update some comments in build.c. (CVS 2452)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d9418851cebc1605d8d62aad7987c0d61a905e81
User & Date: drh 2005-05-03 12:30:34
Context
2005-05-05
10:30
In the TCL interface, user-defined functions preserve the datatype returned by the Tcl procedure. (CVS 2453) check-in: 99dcba1f user: drh tags: trunk
2005-05-03
12:30
Make sure all data structures have 8-byte alignment - necessary for the sparc architecture and helpful on other 64-bit platforms. Ticket #1232. Also update some comments in build.c. (CVS 2452) check-in: d9418851 user: drh tags: trunk
2005-05-01
22:52
Remove the psAligned value from the BTree structure - the pageSize is now always aligned to an 8-byte boundary. Add comments on a confusing bit of code. Ticket #1231. (CVS 2451) check-in: 535523e1 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     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         -** $Id: btree.c,v 1.257 2005/05/01 22:52:42 drh Exp $
           12  +** $Id: btree.c,v 1.258 2005/05/03 12:30:34 drh Exp $
    13     13   **
    14     14   ** This file implements a external (disk-based) database using BTrees.
    15     15   ** For a detailed discussion of BTrees, refer to
    16     16   **
    17     17   **     Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
    18     18   **     "Sorting And Searching", pages 473-480. Addison-Wesley
    19     19   **     Publishing Company, Reading, Massachusetts.
................................................................................
   206    206   **      *     zero or more pages numbers of leaves
   207    207   */
   208    208   #include "sqliteInt.h"
   209    209   #include "pager.h"
   210    210   #include "btree.h"
   211    211   #include "os.h"
   212    212   #include <assert.h>
          213  +
          214  +/* Round up a number to the next larger multiple of 8.  This is used
          215  +** to force 8-byte alignment on 64-bit architectures.
          216  +*/
          217  +#define ROUND8(x)   ((x+7)&~7)
          218  +
   213    219   
   214    220   /* The following value is the maximum cell size assuming a maximum page
   215    221   ** size give above.
   216    222   */
   217    223   #define MX_CELL_SIZE(pBt)  (pBt->pageSize-8)
   218    224   
   219    225   /* The maximum number of cells on a single page of the database.  This
................................................................................
  3892   3898   
  3893   3899     /*
  3894   3900     ** Allocate space for memory structures
  3895   3901     */
  3896   3902     apCell = sqliteMallocRaw( 
  3897   3903          nMaxCells*sizeof(u8*)                           /* apCell */
  3898   3904        + nMaxCells*sizeof(int)                           /* szCell */
  3899         -     + sizeof(MemPage)*NB                              /* aCopy */
         3905  +     + ROUND8(sizeof(MemPage))*NB                      /* aCopy */
  3900   3906        + pBt->pageSize*(5+NB)                            /* aSpace */
  3901         -     + (ISAUTOVACUUM ? nMaxCells : 0)     /* aFrom */
         3907  +     + (ISAUTOVACUUM ? nMaxCells : 0)                  /* aFrom */
  3902   3908     );
  3903   3909     if( apCell==0 ){
  3904   3910       rc = SQLITE_NOMEM;
  3905   3911       goto balance_cleanup;
  3906   3912     }
  3907   3913     szCell = (int*)&apCell[nMaxCells];
  3908   3914     aCopy[0] = (u8*)&szCell[nMaxCells];
         3915  +  assert( ((aCopy[0] - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */
  3909   3916     for(i=1; i<NB; i++){
  3910         -    aCopy[i] = &aCopy[i-1][pBt->pageSize+sizeof(MemPage)];
         3917  +    aCopy[i] = &aCopy[i-1][pBt->pageSize+ROUND8(sizeof(MemPage))];
         3918  +    assert( ((aCopy[i] - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */
  3911   3919     }
  3912         -  aSpace = &aCopy[NB-1][pBt->pageSize+sizeof(MemPage)];
         3920  +  aSpace = &aCopy[NB-1][pBt->pageSize+ROUND8(sizeof(MemPage))];
         3921  +  assert( ((aSpace - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */
  3913   3922   #ifndef SQLITE_OMIT_AUTOVACUUM
  3914   3923     if( pBt->autoVacuum ){
  3915   3924       aFrom = &aSpace[5*pBt->pageSize];
  3916   3925     }
  3917   3926   #endif
  3918   3927     
  3919   3928     /*
................................................................................
  3920   3929     ** Make copies of the content of pPage and its siblings into aOld[].
  3921   3930     ** The rest of this function will use data from the copies rather
  3922   3931     ** that the original pages since the original pages will be in the
  3923   3932     ** process of being overwritten.
  3924   3933     */
  3925   3934     for(i=0; i<nOld; i++){
  3926   3935       MemPage *p = apCopy[i] = (MemPage*)&aCopy[i][pBt->pageSize];
  3927         -    assert( (((long long unsigned int)p) & 7)==0 );
  3928   3936       p->aData = &((u8*)p)[-pBt->pageSize];
  3929   3937       memcpy(p->aData, apOld[i]->aData, pBt->pageSize + sizeof(MemPage));
  3930   3938       /* The memcpy() above changes the value of p->aData so we have to
  3931   3939       ** set it again. */
  3932         -    assert( (((long long unsigned int)p) & 7)==0 );
  3933   3940       p->aData = &((u8*)p)[-pBt->pageSize];
  3934   3941     }
  3935   3942   
  3936   3943     /*
  3937   3944     ** Load pointers to all cells on sibling pages and the divider cells
  3938   3945     ** into the local apCell[] array.  Make copies of the divider cells
  3939   3946     ** into space obtained form aSpace[] and remove the the divider Cells

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.318 2005/03/29 03:10:59 danielk1977 Exp $
           25  +** $Id: build.c,v 1.319 2005/05/03 12:30:34 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.
................................................................................
   262    262       sqlite3HashInsert(&db->aDb[p->iDb].idxHash, pOld->zName,
   263    263                        strlen(pOld->zName)+1, pOld);
   264    264     }
   265    265     freeIndex(p);
   266    266   }
   267    267   
   268    268   /*
   269         -** Unlink the given index from its table, then remove
   270         -** the index from the index hash table and free its memory
   271         -** structures.
          269  +** For the index called zIdxName which is found in the database iDb,
          270  +** unlike that index from its Table then remove the index from
          271  +** the index hash table and free all memory structures associated
          272  +** with the index.
   272    273   */
   273    274   void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){
   274    275     Index *pIndex;
   275    276     int len;
   276    277   
   277    278     len = strlen(zIdxName);
   278    279     pIndex = sqlite3HashInsert(&db->aDb[iDb].idxHash, zIdxName, len+1, 0);
................................................................................
   492    493   
   493    494   /*
   494    495   ** Given a token, return a string that consists of the text of that
   495    496   ** token with any quotations removed.  Space to hold the returned string
   496    497   ** is obtained from sqliteMalloc() and must be freed by the calling
   497    498   ** function.
   498    499   **
   499         -** Tokens are really just pointers into the original SQL text and so
          500  +** Tokens are often just pointers into the original SQL text and so
   500    501   ** are not \000 terminated and are not persistent.  The returned string
   501    502   ** is \000 terminated and is persistent.
   502    503   */
   503    504   char *sqlite3NameFromToken(Token *pName){
   504    505     char *zName;
   505    506     if( pName ){
   506    507       zName = sqliteStrNDup(pName->z, pName->n);

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.132 2005/03/18 14:03:15 drh Exp $
           17  +** $Id: util.c,v 1.133 2005/05/03 12:30:34 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include <stdarg.h>
    21     21   #include <ctype.h>
    22     22   
    23     23   #if SQLITE_MEMDEBUG>2 && defined(__GLIBC__)
    24     24   #include <execinfo.h>
................................................................................
    61     61   int sqlite3_iMallocFail;     /* Fail sqliteMalloc() after this many calls */
    62     62   int sqlite3_iMallocReset = -1; /* When iMallocFail reaches 0, set to this */
    63     63   #if SQLITE_MEMDEBUG>1
    64     64   static int memcnt = 0;
    65     65   #endif
    66     66   
    67     67   /*
    68         -** Number of 32-bit guard words
           68  +** Number of 32-bit guard words.  This should probably be a multiple of
           69  +** 2 since on 64-bit machines we want the value returned by sqliteMalloc()
           70  +** to be 8-byte aligned.
    69     71   */
    70         -#define N_GUARD 1
           72  +#define N_GUARD 2
    71     73   
    72     74   /*
    73     75   ** Allocate new memory and set it to zero.  Return NULL if
    74     76   ** no memory is available.
    75     77   */
    76     78   void *sqlite3Malloc_(int n, int bZero, char *zFile, int line){
    77     79     void *p;