From 71a1a0f485fb64e5996a6edfe1534e66a7e74add Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 11 Sep 2010 16:15:55 +0000 Subject: [PATCH] Additional evidence marks on the malloc() implementation. Update the documentation to explain that mallocs are not necessarily 8-byte aligned if the SQLITE_4_BYTE_ALIGNED_MALLOC compile-time option is used. FossilOrigin-Name: 42b4bf9e72501cf228b4086437c7660443933f74 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/malloc.c | 10 ++++++---- src/sqlite.h.in | 4 +++- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index f8db8e97bc..81616d2b87 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sassert()\sstatements\sto\sdemonstrate\sthat\smemory\sallocations\sare\salways\naligned\sto\san\s8-byte\sboundary\s(unless\sSQLITE_4_BYTE_ALIGNED_MALLOC\sis\sdefined). -D 2010-09-11T15:54:53 +C Additional\sevidence\smarks\son\sthe\smalloc()\simplementation.\s\sUpdate\sthe\s\ndocumentation\sto\sexplain\sthat\smallocs\sare\snot\snecessarily\s8-byte\saligned\nif\sthe\sSQLITE_4_BYTE_ALIGNED_MALLOC\scompile-time\soption\sis\sused. +D 2010-09-11T16:15:56 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in c599a15d268b1db2aeadea19df2adc3bf2eb6bee F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -140,7 +140,7 @@ F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f F src/lempar.c 7f026423f4d71d989e719a743f98a1cbd4e6d99e F src/loadext.c 6d422ea91cf3d2d00408c5a8f2391cd458da85f8 F src/main.c da74b2269470d97a702d2956eeeb691a5e3a68c3 -F src/malloc.c ab48f49442aa78c8c7019845c634ac05b07e59dc +F src/malloc.c 44a50eb10bb755a7b27799b41b874e53bd6e24e3 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 00bd8265c81abb665c48fea1e0c234eb3b922206 F src/mem2.c e307323e86b5da1853d7111b68fd6b84ad6f09cf @@ -174,7 +174,7 @@ F src/resolve.c 1c0f32b64f8e3f555fe1f732f9d6f501a7f05706 F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697 F src/select.c b0b124781474e4e0c8f64022875e5e2009e13443 F src/shell.c 8517fc1f9c59ae4007e6cc8b9af91ab231ea2056 -F src/sqlite.h.in 8cae23448cb0ebe0990d305c32435c2dfb21f937 +F src/sqlite.h.in b70c0ad68365a229800af55abe9210f1964c1d31 F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89 F src/sqliteInt.h 81343db96497aebf81dff9c695dfd29699b377b3 F src/sqliteLimit.h a17dcd3fb775d63b64a43a55c54cb282f9726f44 @@ -857,7 +857,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 5b63e981f1bef26eae0da3144a08bdc54dc36709 -R 5f696ac739736af24121b122c94485c1 +P 305cc4e6c1164b1ede0c3177e3c0f9b8644df0f6 +R d4739e5fcf915e019da850204032c340 U drh -Z 6c746302b511dbe67ce0549fd9634e5e +Z 342cca73834b234d21ed5424a5f029e5 diff --git a/manifest.uuid b/manifest.uuid index d67b6d88bb..cf0d4b2849 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -305cc4e6c1164b1ede0c3177e3c0f9b8644df0f6 \ No newline at end of file +42b4bf9e72501cf228b4086437c7660443933f74 \ No newline at end of file diff --git a/src/malloc.c b/src/malloc.c index 948eb91d13..d7a103b111 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -293,7 +293,9 @@ static int mallocWithAlarm(int n, void **pp){ */ void *sqlite3Malloc(int n){ void *p; - if( n<=0 || n>=0x7fffff00 ){ + if( n<=0 /* IMP: R-65312-04917 */ + || n>=0x7fffff00 + ){ /* A memory allocation of a number of bytes which is near the maximum ** signed integer value might cause an integer overflow inside of the ** xMalloc(). Hence we limit the maximum size to 0x7fffff00, giving @@ -459,7 +461,7 @@ int sqlite3DbMallocSize(sqlite3 *db, void *p){ ** Free memory previously obtained from sqlite3Malloc(). */ void sqlite3_free(void *p){ - if( p==0 ) return; + if( p==0 ) return; /* IMP: R-49053-54554 */ assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) ); assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); if( sqlite3GlobalConfig.bMemstat ){ @@ -506,10 +508,10 @@ void *sqlite3Realloc(void *pOld, int nBytes){ int nOld, nNew; void *pNew; if( pOld==0 ){ - return sqlite3Malloc(nBytes); + return sqlite3Malloc(nBytes); /* IMP: R-28354-25769 */ } if( nBytes<=0 ){ - sqlite3_free(pOld); + sqlite3_free(pOld); /* IMP: R-31593-10574 */ return 0; } if( nBytes>=0x7fffff00 ){ diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 613ee6e148..a7bc0d0508 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -1947,7 +1947,9 @@ char *sqlite3_snprintf(int,char*,const char*, ...); ** is not freed. ** ** ^The memory returned by sqlite3_malloc() and sqlite3_realloc() -** is always aligned to at least an 8 byte boundary. +** is always aligned to at least an 8 byte boundary, or to a +** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time +** option is used. ** ** In SQLite version 3.5.0 and 3.5.1, it was possible to define ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in