diff options
author | drh <drh@noemail.net> | 2009-06-03 01:24:54 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2009-06-03 01:24:54 +0000 |
commit | 50d654da3b6768d4ec65e54405fc9763ff3a58d4 (patch) | |
tree | 430016c42e2c66a6ae293c5dd0bff48a66da8cf0 /src | |
parent | e98c9049a0a56ea8c3a704a986298f1dc5a9af2f (diff) | |
download | sqlite-50d654da3b6768d4ec65e54405fc9763ff3a58d4.tar.gz sqlite-50d654da3b6768d4ec65e54405fc9763ff3a58d4.zip |
Additional changes to reduce stack usage. The SQLITE_SMALL_STACK compile-time
option is now available. (CVS 6708)
FossilOrigin-Name: baea79fd0cfeb860973846c3f2776776c87f0ae3
Diffstat (limited to 'src')
-rw-r--r-- | src/func.c | 15 | ||||
-rw-r--r-- | src/loadext.c | 31 | ||||
-rw-r--r-- | src/printf.c | 11 | ||||
-rw-r--r-- | src/where.c | 8 |
4 files changed, 41 insertions, 24 deletions
diff --git a/src/func.c b/src/func.c index 893406ceb..673b77e30 100644 --- a/src/func.c +++ b/src/func.c @@ -16,7 +16,7 @@ ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.236 2009/05/28 01:00:55 drh Exp $ +** $Id: func.c,v 1.237 2009/06/03 01:24:54 drh Exp $ */ #include "sqliteInt.h" #include <stdlib.h> @@ -247,7 +247,7 @@ static void substrFunc( static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ int n = 0; double r; - char zBuf[500]; /* larger than the %f representation of the largest double */ + char *zBuf; assert( argc==1 || argc==2 ); if( argc==2 ){ if( SQLITE_NULL==sqlite3_value_type(argv[1]) ) return; @@ -257,9 +257,14 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ } if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; r = sqlite3_value_double(argv[0]); - sqlite3_snprintf(sizeof(zBuf),zBuf,"%.*f",n,r); - sqlite3AtoF(zBuf, &r); - sqlite3_result_double(context, r); + zBuf = sqlite3_mprintf("%.*f",n,r); + if( zBuf==0 ){ + sqlite3_result_error_nomem(context); + }else{ + sqlite3AtoF(zBuf, &r); + sqlite3_free(zBuf); + sqlite3_result_double(context, r); + } } #endif diff --git a/src/loadext.c b/src/loadext.c index 0c1b5dd6a..1fa6aa39a 100644 --- a/src/loadext.c +++ b/src/loadext.c @@ -12,7 +12,7 @@ ** This file contains code used to dynamically load extensions into ** the SQLite library. ** -** $Id: loadext.c,v 1.59 2009/05/20 02:40:46 drh Exp $ +** $Id: loadext.c,v 1.60 2009/06/03 01:24:54 drh Exp $ */ #ifndef SQLITE_CORE @@ -354,6 +354,7 @@ static int sqlite3LoadExtension( int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); char *zErrmsg = 0; void **aHandle; + const int nMsg = 300; if( pzErrMsg ) *pzErrMsg = 0; @@ -377,12 +378,14 @@ static int sqlite3LoadExtension( handle = sqlite3OsDlOpen(pVfs, zFile); if( handle==0 ){ if( pzErrMsg ){ - char zErr[256]; - zErr[sizeof(zErr)-1] = '\0'; - sqlite3_snprintf(sizeof(zErr)-1, zErr, - "unable to open shared library [%s]", zFile); - sqlite3OsDlError(pVfs, sizeof(zErr)-1, zErr); - *pzErrMsg = sqlite3DbStrDup(0, zErr); + zErrmsg = sqlite3StackAllocZero(db, nMsg); + if( zErrmsg ){ + sqlite3_snprintf(nMsg, zErrmsg, + "unable to open shared library [%s]", zFile); + sqlite3OsDlError(pVfs, nMsg-1, zErrmsg); + *pzErrMsg = sqlite3DbStrDup(0, zErrmsg); + sqlite3StackFree(db, zErrmsg); + } } return SQLITE_ERROR; } @@ -390,12 +393,14 @@ static int sqlite3LoadExtension( sqlite3OsDlSym(pVfs, handle, zProc); if( xInit==0 ){ if( pzErrMsg ){ - char zErr[256]; - zErr[sizeof(zErr)-1] = '\0'; - sqlite3_snprintf(sizeof(zErr)-1, zErr, - "no entry point [%s] in shared library [%s]", zProc,zFile); - sqlite3OsDlError(pVfs, sizeof(zErr)-1, zErr); - *pzErrMsg = sqlite3DbStrDup(0, zErr); + zErrmsg = sqlite3StackAllocZero(db, nMsg); + if( zErrmsg ){ + sqlite3_snprintf(nMsg, zErrmsg, + "no entry point [%s] in shared library [%s]", zProc,zFile); + sqlite3OsDlError(pVfs, nMsg-1, zErrmsg); + *pzErrMsg = sqlite3DbStrDup(0, zErrmsg); + sqlite3StackFree(db, zErrmsg); + } sqlite3OsDlClose(pVfs, handle); } return SQLITE_ERROR; diff --git a/src/printf.c b/src/printf.c index a2c79c5b5..d8d838693 100644 --- a/src/printf.c +++ b/src/printf.c @@ -5,7 +5,7 @@ ** an historical reference. Most of the "enhancements" have been backed ** out so that the functionality is now the same as standard printf(). ** -** $Id: printf.c,v 1.103 2009/05/04 20:20:16 drh Exp $ +** $Id: printf.c,v 1.104 2009/06/03 01:24:54 drh Exp $ ** ************************************************************************** ** @@ -189,11 +189,14 @@ static void appendSpace(StrAccum *pAccum, int N){ /* ** On machines with a small stack size, you can redefine the -** SQLITE_PRINT_BUF_SIZE to be less than 350. But beware - for -** smaller values some %f conversions may go into an infinite loop. +** SQLITE_PRINT_BUF_SIZE to be less than 350. */ #ifndef SQLITE_PRINT_BUF_SIZE -# define SQLITE_PRINT_BUF_SIZE 350 +# if defined(SQLITE_SMALL_STACK) +# define SQLITE_PRINT_BUF_SIZE 50 +# else +# define SQLITE_PRINT_BUF_SIZE 350 +# endif #endif #define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */ diff --git a/src/where.c b/src/where.c index 48651ceb9..d0f0b01d6 100644 --- a/src/where.c +++ b/src/where.c @@ -16,7 +16,7 @@ ** so is applicable. Because this module is responsible for selecting ** indices, you might also think of this module as the "query optimizer". ** -** $Id: where.c,v 1.399 2009/05/28 01:00:55 drh Exp $ +** $Id: where.c,v 1.400 2009/06/03 01:24:54 drh Exp $ */ #include "sqliteInt.h" @@ -132,7 +132,11 @@ struct WhereClause { int nTerm; /* Number of terms */ int nSlot; /* Number of entries in a[] */ WhereTerm *a; /* Each a[] describes a term of the WHERE cluase */ - WhereTerm aStatic[4]; /* Initial static space for a[] */ +#if defined(SQLITE_SMALL_STACK) + WhereTerm aStatic[1]; /* Initial static space for a[] */ +#else + WhereTerm aStatic[8]; /* Initial static space for a[] */ +#endif }; /* |