From c96d8530ca54c7ec7c6ca52b9e7f01f33f0c4235 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 3 May 2005 12:30:33 +0000 Subject: [PATCH] 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) FossilOrigin-Name: d9418851cebc1605d8d62aad7987c0d61a905e81 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/btree.c | 21 ++++++++++++++------- src/build.c | 11 ++++++----- src/util.c | 8 +++++--- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/manifest b/manifest index b2473ae1b5..0e4c9fd727 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sthe\spsAligned\svalue\sfrom\sthe\sBTree\sstructure\s-\sthe\spageSize\sis\snow\nalways\saligned\sto\san\s8-byte\sboundary.\s\sAdd\scomments\son\sa\sconfusing\sbit\nof\scode.\s\sTicket\s#1231.\s(CVS\s2451) -D 2005-05-01T22:52:42 +C Make\ssure\sall\sdata\sstructures\shave\s8-byte\salignment\s-\snecessary\sfor\sthe\nsparc\sarchitecture\sand\shelpful\son\sother\s64-bit\splatforms.\s\sTicket\s#1232.\nAlso\supdate\ssome\scomments\sin\sbuild.c.\s(CVS\s2452) +D 2005-05-03T12:30:34 F Makefile.in 5c00d0037104de2a50ac7647a5f12769795957a3 F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -30,9 +30,9 @@ F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a F src/alter.c 9570af388bc99471ea6e1258817fbf06e3120030 F src/attach.c 3615dbe960cbee4aa5ea300b8a213dad36527b0f F src/auth.c 18c5a0befe20f3a58a41e3ddd78f372faeeefe1f -F src/btree.c 659cbf8b9ab4fa3d33fa46f9a8d7fa60ae5d802a +F src/btree.c 238ebc9b5c867cc7def795ef623d98ece9ec5b42 F src/btree.h 41a71ce027db9ddee72cb43df2316bbe3a1d92af -F src/build.c 8afb06c791adcde7787f157bbc55aeef27fb27c1 +F src/build.c 61a0beac459a495f05622132559926d88757e20c F src/date.c 2134ef4388256e8247405178df8a61bd60dc180a F src/delete.c 75b53db21aa1879d3655bbbc208007db31d58a63 F src/experimental.c 50c1e3b34f752f4ac10c36f287db095c2b61766d @@ -73,7 +73,7 @@ F src/tokenize.c 103cbaa932c790f540f8eceb63cd3010e117bdff F src/trigger.c 1a6d0c7c51b70bdc58d5068be72034071eff23ad F src/update.c 04ea9dd784ccfeaf38a681b3edfe3b1c4edfdda7 F src/utf.c bda5eb85039ef16f2d17004c1e18c96e1ab0a80c -F src/util.c 02bc2750336b021b3f10e61538f665c4b0033b5d +F src/util.c ac74ac096cbe61fe0139f041833a47c97a2dec07 F src/vacuum.c 84a3bebac2c79a1463b98ba35fb9fb6aa2374250 F src/vdbe.c d2574042c44baf6b1016c61e8072dec529ac748a F src/vdbe.h 7f586cb6d6b57764e5aac1f87107d6a95ddce24c @@ -279,7 +279,7 @@ F www/tclsqlite.tcl 425be741b8ae664f55cb1ef2371aab0a75109cf9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b F www/whentouse.tcl 528299b8316726dbcc5548e9aa0648c8b1bd055b -P 0667eae9a97059125a77bd90452d19dc17c30a12 -R aa09f451ce42a99806e3bada16ee996b +P 535523e1be692adc940d256a7b3d23c62a4cc947 +R a72ac68975ae652f87834c74a143990a U drh -Z dd1e0985c973b9299d9ae9a3aabf02aa +Z bc2beeb96490a6d1f455c1c7be0e1755 diff --git a/manifest.uuid b/manifest.uuid index a55f7fd3a2..5647fba666 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -535523e1be692adc940d256a7b3d23c62a4cc947 \ No newline at end of file +d9418851cebc1605d8d62aad7987c0d61a905e81 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 72b2dbc609..bd66a28ce6 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 +/* 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; ipageSize+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; ipageSize]; - 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 bff72c40c0..a5c400d8d1 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 @@ -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 4f19302384..fc16141516 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 @@ -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