aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/btree.c21
-rw-r--r--src/build.c11
-rw-r--r--src/util.c8
3 files changed, 25 insertions, 15 deletions
diff --git a/src/btree.c b/src/btree.c
index 72b2dbc60..bd66a28ce 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
-** $Id: btree.c,v 1.257 2005/05/01 22:52:42 drh Exp $
+** $Id: btree.c,v 1.258 2005/05/03 12:30:34 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
@@ -211,6 +211,12 @@
#include "os.h"
#include <assert.h>
+/* Round up a number to the next larger multiple of 8. This is used
+** to force 8-byte alignment on 64-bit architectures.
+*/
+#define ROUND8(x) ((x+7)&~7)
+
+
/* The following value is the maximum cell size assuming a maximum page
** size give above.
*/
@@ -3896,9 +3902,9 @@ static int balance_nonroot(MemPage *pPage){
apCell = sqliteMallocRaw(
nMaxCells*sizeof(u8*) /* apCell */
+ nMaxCells*sizeof(int) /* szCell */
- + sizeof(MemPage)*NB /* aCopy */
+ + ROUND8(sizeof(MemPage))*NB /* aCopy */
+ pBt->pageSize*(5+NB) /* aSpace */
- + (ISAUTOVACUUM ? nMaxCells : 0) /* aFrom */
+ + (ISAUTOVACUUM ? nMaxCells : 0) /* aFrom */
);
if( apCell==0 ){
rc = SQLITE_NOMEM;
@@ -3906,10 +3912,13 @@ static int balance_nonroot(MemPage *pPage){
}
szCell = (int*)&apCell[nMaxCells];
aCopy[0] = (u8*)&szCell[nMaxCells];
+ assert( ((aCopy[0] - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */
for(i=1; i<NB; i++){
- aCopy[i] = &aCopy[i-1][pBt->pageSize+sizeof(MemPage)];
+ aCopy[i] = &aCopy[i-1][pBt->pageSize+ROUND8(sizeof(MemPage))];
+ assert( ((aCopy[i] - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */
}
- aSpace = &aCopy[NB-1][pBt->pageSize+sizeof(MemPage)];
+ aSpace = &aCopy[NB-1][pBt->pageSize+ROUND8(sizeof(MemPage))];
+ assert( ((aSpace - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */
#ifndef SQLITE_OMIT_AUTOVACUUM
if( pBt->autoVacuum ){
aFrom = &aSpace[5*pBt->pageSize];
@@ -3924,12 +3933,10 @@ static int balance_nonroot(MemPage *pPage){
*/
for(i=0; i<nOld; i++){
MemPage *p = apCopy[i] = (MemPage*)&aCopy[i][pBt->pageSize];
- assert( (((long long unsigned int)p) & 7)==0 );
p->aData = &((u8*)p)[-pBt->pageSize];
memcpy(p->aData, apOld[i]->aData, pBt->pageSize + sizeof(MemPage));
/* The memcpy() above changes the value of p->aData so we have to
** set it again. */
- assert( (((long long unsigned int)p) & 7)==0 );
p->aData = &((u8*)p)[-pBt->pageSize];
}
diff --git a/src/build.c b/src/build.c
index bff72c40c..a5c400d8d 100644
--- a/src/build.c
+++ b/src/build.c
@@ -22,7 +22,7 @@
** COMMIT
** ROLLBACK
**
-** $Id: build.c,v 1.318 2005/03/29 03:10:59 danielk1977 Exp $
+** $Id: build.c,v 1.319 2005/05/03 12:30:34 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -266,9 +266,10 @@ static void sqliteDeleteIndex(sqlite3 *db, Index *p){
}
/*
-** Unlink the given index from its table, then remove
-** the index from the index hash table and free its memory
-** structures.
+** For the index called zIdxName which is found in the database iDb,
+** unlike that index from its Table then remove the index from
+** the index hash table and free all memory structures associated
+** with the index.
*/
void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){
Index *pIndex;
@@ -496,7 +497,7 @@ void sqlite3UnlinkAndDeleteTable(sqlite3 *db, int iDb, const char *zTabName){
** is obtained from sqliteMalloc() and must be freed by the calling
** function.
**
-** Tokens are really just pointers into the original SQL text and so
+** Tokens are often just pointers into the original SQL text and so
** are not \000 terminated and are not persistent. The returned string
** is \000 terminated and is persistent.
*/
diff --git a/src/util.c b/src/util.c
index 4f1930238..fc1614151 100644
--- a/src/util.c
+++ b/src/util.c
@@ -14,7 +14,7 @@
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
-** $Id: util.c,v 1.132 2005/03/18 14:03:15 drh Exp $
+** $Id: util.c,v 1.133 2005/05/03 12:30:34 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
@@ -65,9 +65,11 @@ static int memcnt = 0;
#endif
/*
-** Number of 32-bit guard words
+** Number of 32-bit guard words. This should probably be a multiple of
+** 2 since on 64-bit machines we want the value returned by sqliteMalloc()
+** to be 8-byte aligned.
*/
-#define N_GUARD 1
+#define N_GUARD 2
/*
** Allocate new memory and set it to zero. Return NULL if