From: drh Date: Fri, 25 Sep 2015 16:29:49 +0000 (+0000) Subject: Disable the SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS mechanism and replace it X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ffdcf0051ee6216c4661539183cacb77a668a885;p=thirdparty%2Fsqlite.git Disable the SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS mechanism and replace it with SQLITE_TESTCTRL_BENIGN_MALLOC_CTRL, which gives better control. FossilOrigin-Name: 2c57b2f38691356405b95245fc22fd5e6bfcb2f1 --- diff --git a/manifest b/manifest index e784e63e3f..7939b1c270 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Report\san\serror\sif\sthe\snumber\sof\snamed\scolumns\sin\sa\sVIEW\sis\sdifferent\nfrom\sthe\snumber\sof\sresult\scolumns\sin\sthe\sSELECT\sstatement\sthat\simplements\nthe\sVIEW. -D 2015-09-25T13:42:55.978 +C Disable\sthe\sSQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS\smechanism\sand\sreplace\sit\s\nwith\sSQLITE_TESTCTRL_BENIGN_MALLOC_CTRL,\swhich\sgives\sbetter\scontrol. +D 2015-09-25T16:29:49.729 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1afa6fb2de2bddd50e0ddae8166c2ee9d69b301 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -293,11 +293,11 @@ F src/date.c fb1c99172017dcc8e237339132c91a21a0788584 F src/dbstat.c e637e7a7ff40ef32132a418c6fdf1cfb63aa27c7 F src/delete.c 371df4fc86e96efeaed3d37565aef77f956be109 F src/expr.c 3a76afcdac925294c39903b7002ddb9e5fd29863 -F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb +F src/fault.c a64e879e4713671b3b2bf1db70efa351d6ac9591 F src/fkey.c 83e1baba999bed3144ea5a2143fc922edf51135f F src/func.c ecdd69ec6a1e406f04cc73324be2ebbf6354197f F src/global.c 508e4087f7b41d688e4762dcf4d4fe28cfbc87f9 -F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 +F src/hash.c 5b5ce67bc4fe533f49de10b3671fcb92d4d5c4e9 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 F src/insert.c 9748a37e058256eb2ead69f028ab85ebf203ad15 @@ -305,8 +305,8 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c d344a95d60c24e2f490ee59db9784b1b17439012 F src/loadext.c f0b66d28e377fd6c6d36cc9d92df1ff251ebee44 -F src/main.c e17fcffae4306a9b8334faf3bac80d7396850b54 -F src/malloc.c 3a37ce6979a40f499d8cea9e9ab4e8517854d35d +F src/main.c 710b2e0433a340a10c40f4dbf29838e359a44427 +F src/malloc.c 76c62c8ee6b346aa10a373229a372ef2f2344fe9 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987 F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 @@ -332,7 +332,7 @@ F src/pager.h ac213f8143ebfee6a8bfb91cf4ca02c9a83343c5 F src/parse.y f599aa5e871a493330d567ced93de696f61f48f7 F src/pcache.c 24be750c79272e0ca7b6e007bc94999700f3e5ef F src/pcache.h 9968603796240cdf83da7e7bef76edf90619cea9 -F src/pcache1.c e822007159d53a7ea7aa040d6e28964ddb6de083 +F src/pcache1.c 7f8630a2074997195b86f478840a603818b08d84 F src/pragma.c d71b813e67bf03f3116b9dd5164fbfd81ec673a2 F src/pragma.h 631a91c8b0e6ca8f051a1d8a4a0da4150e04620a F src/prepare.c 82e5db1013846a819f198336fed72c44c974e7b1 @@ -341,11 +341,11 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 1954a0f01bf65d78d7d559aea3d5c67f33376d91 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 33230303f5f32430ee971a6fcc6a370e4a93ae1a -F src/shell.c 6332ef06db1390ef812cfdff1fc97b4fd76cdd42 -F src/sqlite.h.in 4e06cb5fed36736242c66237991db6f3e2395eb9 +F src/shell.c 15186317f2fcb670400f8d16d298ed18731375a0 +F src/sqlite.h.in a6f2cb7741fae0133b007843b65c96f7fcd4d7fd F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 64350bf36833a56ad675e27392a913f417c5c308 -F src/sqliteInt.h 5afc6e50402be1e0a870f28e1cd8b32eb9db590f +F src/sqliteInt.h ca695ea39aa6d459a1b1d36391c5121c432f350f F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179 F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e @@ -375,7 +375,7 @@ F src/test_intarray.c 870124b95ec4c645d4eb84f15efb7133528fb1a5 F src/test_intarray.h 9dc57417fb65bc7835cc18548852cc08cc062202 F src/test_journal.c 5360fbe1d1e4416ca36290562fd5a2e3f70f32aa F src/test_loadext.c a5251f956ab6af21e138dc1f9c0399394a510cb4 -F src/test_malloc.c 27d9e11b6e9d30267465d41ad81edbe24256408b +F src/test_malloc.c 8d0ffe32a7e46aaab2bca5cce28e69678a9a3dc5 F src/test_multiplex.c 9fefd23f6cc3fa9bf0748a5e453167e7b9f193ce F src/test_multiplex.h c08e4e8f8651f0c5e0509b138ff4d5b43ed1f5d3 F src/test_mutex.c dbdfaff8580071f2212a0deae3325a93a737819c @@ -1388,7 +1388,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 1350dd42d056508337b1a07ad8b1c9c97593f8d3 -R 9672ebd00531833a09889a78098f4f34 +P 6e4ac0be2de1a16fcbb2a314504122ad95aa257e +R e9ff57918bb5645931e56acdf4a48d22 +T *branch * malloc-testing +T *sym-malloc-testing * +T -sym-trunk * U drh -Z 160c60a319774154e17ae3a2bf9d8f26 +Z ab3c9d2f368f9a4d4d11dc236e31f593 diff --git a/manifest.uuid b/manifest.uuid index aaf3eedcfb..614afaf655 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6e4ac0be2de1a16fcbb2a314504122ad95aa257e \ No newline at end of file +2c57b2f38691356405b95245fc22fd5e6bfcb2f1 \ No newline at end of file diff --git a/src/fault.c b/src/fault.c index c3028c4f93..23272c8449 100644 --- a/src/fault.c +++ b/src/fault.c @@ -29,59 +29,42 @@ #ifndef SQLITE_OMIT_BUILTIN_TEST /* -** Global variables. +** The default xBenignCtrl function is a no-op */ -typedef struct BenignMallocHooks BenignMallocHooks; -static SQLITE_WSD struct BenignMallocHooks { - void (*xBenignBegin)(void); - void (*xBenignEnd)(void); -} sqlite3Hooks = { 0, 0 }; +static void sqlite3BenignCtrlNoop(int eOp){ + (void)eOp; +} -/* The "wsdHooks" macro will resolve to the appropriate BenignMallocHooks -** structure. If writable static data is unsupported on the target, -** we have to locate the state vector at run-time. In the more common -** case where writable static data is supported, wsdHooks can refer directly -** to the "sqlite3Hooks" state vector declared above. +/* +** Global variable: Pointer to the benign malloc control interface. */ -#ifdef SQLITE_OMIT_WSD -# define wsdHooksInit \ - BenignMallocHooks *x = &GLOBAL(BenignMallocHooks,sqlite3Hooks) -# define wsdHooks x[0] -#else -# define wsdHooksInit -# define wsdHooks sqlite3Hooks -#endif - +static void (*sqlite3xBenignCtrl)(int) = sqlite3BenignCtrlNoop; /* -** Register hooks to call when sqlite3BeginBenignMalloc() and -** sqlite3EndBenignMalloc() are called, respectively. +** Register a pointer to the benign-malloc control interface function. +** If the argument is a NULL pointer, register the default no-op controller. */ -void sqlite3BenignMallocHooks( - void (*xBenignBegin)(void), - void (*xBenignEnd)(void) -){ - wsdHooksInit; - wsdHooks.xBenignBegin = xBenignBegin; - wsdHooks.xBenignEnd = xBenignEnd; +void sqlite3BenignMallocHooks(void (*xBenignCtrl)(int)){ + sqlite3xBenignCtrl = xBenignCtrl ? xBenignCtrl : sqlite3BenignCtrlNoop; } /* -** This (sqlite3EndBenignMalloc()) is called by SQLite code to indicate that -** subsequent malloc failures are benign. A call to sqlite3EndBenignMalloc() -** indicates that subsequent malloc failures are non-benign. +** The sqlite3BeginBenignMalloc() and sqlite3EndBenignMalloc() calls bracket +** sections of code for which malloc failures are non-fatal. */ void sqlite3BeginBenignMalloc(void){ - wsdHooksInit; - if( wsdHooks.xBenignBegin ){ - wsdHooks.xBenignBegin(); - } + sqlite3xBenignCtrl(1); } void sqlite3EndBenignMalloc(void){ - wsdHooksInit; - if( wsdHooks.xBenignEnd ){ - wsdHooks.xBenignEnd(); - } + sqlite3xBenignCtrl(0); +} + +/* +** The sqlite3PreviousBenignMalloc() call indicates that the previous +** malloc call (which must have failed) was a benign failure. +*/ +void sqlite3PreviousBenignMalloc(void){ + sqlite3xBenignCtrl(2); } #endif /* #ifndef SQLITE_OMIT_BUILTIN_TEST */ diff --git a/src/hash.c b/src/hash.c index b5886e0641..969bfea7cd 100644 --- a/src/hash.c +++ b/src/hash.c @@ -118,11 +118,11 @@ static int rehash(Hash *pH, unsigned int new_size){ ** use the actual amount of space allocated for the hash table (which ** may be larger than the requested amount). */ - sqlite3BeginBenignMalloc(); new_ht = (struct _ht *)sqlite3Malloc( new_size*sizeof(struct _ht) ); - sqlite3EndBenignMalloc(); - - if( new_ht==0 ) return 0; + if( new_ht==0 ){ + sqlite3PreviousBenignMalloc(); + return 0; + } sqlite3_free(pH->ht); pH->ht = new_ht; pH->htsize = new_size = sqlite3MallocSize(new_ht)/sizeof(struct _ht); diff --git a/src/main.c b/src/main.c index 575cad92c5..91a6f4e47e 100644 --- a/src/main.c +++ b/src/main.c @@ -664,10 +664,12 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ sz = 0; pStart = 0; }else if( pBuf==0 ){ - sqlite3BeginBenignMalloc(); pStart = sqlite3Malloc( sz*cnt ); /* IMP: R-61949-35727 */ - sqlite3EndBenignMalloc(); - if( pStart ) cnt = sqlite3MallocSize(pStart)/sz; + if( pStart==0 ){ + sqlite3PreviousBenignMalloc(); + }else{ + cnt = sqlite3MallocSize(pStart)/sz; + } }else{ pStart = pBuf; } @@ -3440,18 +3442,18 @@ int sqlite3_test_control(int op, ...){ } /* - ** sqlite3_test_control(BENIGN_MALLOC_HOOKS, xBegin, xEnd) + ** sqlite3_test_control(BENIGN_MALLOC_CTRL, xCtrl) ** - ** Register hooks to call to indicate which malloc() failures - ** are benign. + ** Register a callback function that will handle calls to + ** sqlite3BeginBenignMalloc(), sqlite3EndBenignMalloc(), and + ** sqlite3PreviousBenignMalloc(). If the callback function pointer + ** is NULL, then a built-in default (no-op) handler is used. */ - case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS: { - typedef void (*void_function)(void); - void_function xBenignBegin; - void_function xBenignEnd; - xBenignBegin = va_arg(ap, void_function); - xBenignEnd = va_arg(ap, void_function); - sqlite3BenignMallocHooks(xBenignBegin, xBenignEnd); + case SQLITE_TESTCTRL_BENIGN_MALLOC_CTRL: { + typedef void (*void_function)(int); + void_function xBenignCtrl; + xBenignCtrl = va_arg(ap, void_function); + sqlite3BenignMallocHooks(xBenignCtrl); break; } diff --git a/src/malloc.c b/src/malloc.c index f20eb6e796..953168338f 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -526,6 +526,7 @@ void *sqlite3Realloc(void *pOld, u64 nBytes){ } pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); if( pNew==0 && mem0.alarmThreshold>0 ){ + sqlite3PreviousBenignMalloc(); sqlite3MallocAlarm((int)nBytes); pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); } diff --git a/src/pcache1.c b/src/pcache1.c index ee6ac0b955..27f20dadf1 100644 --- a/src/pcache1.c +++ b/src/pcache1.c @@ -272,7 +272,6 @@ static int pcache1InitBulk(PCache1 *pCache){ if( pcache1.nInitPage==0 ) return 0; /* Do not bother with a bulk allocation if the cache size very small */ if( pCache->nMax<3 ) return 0; - sqlite3BeginBenignMalloc(); if( pcache1.nInitPage>0 ){ szBulk = pCache->szAlloc * (i64)pcache1.nInitPage; }else{ @@ -282,8 +281,9 @@ static int pcache1InitBulk(PCache1 *pCache){ szBulk = pCache->szAlloc*pCache->nMax; } zBulk = pCache->pBulk = sqlite3Malloc( szBulk ); - sqlite3EndBenignMalloc(); - if( zBulk ){ + if( zBulk==0 ){ + sqlite3PreviousBenignMalloc(); + }else{ int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc; int i; for(i=0; i0 ); + memfault.isBenignMode--; + break; + case 1: /* Enter benign malloc mode */ + memfault.isBenignMode++; + break; + case 2: /* Previous failure is benign */ + assert( memfault.nFail>0 ); + if( memfault.isBenignMode==0 ) memfault.nBenign++; + break; + } } /* @@ -207,9 +222,8 @@ static int faultsimInstall(int install){ if( rc==SQLITE_OK ){ rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &m); } - sqlite3_test_control(SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS, - faultsimBeginBenign, faultsimEndBenign - ); + sqlite3_test_control(SQLITE_TESTCTRL_BENIGN_MALLOC_CTRL, + faultsimBenignCtrl); }else{ sqlite3_mem_methods m2; assert(memfault.m.xMalloc); @@ -222,7 +236,7 @@ static int faultsimInstall(int install){ assert( memcmp(&m2, &memfault.m, sizeof(m2))==0 ); rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &memfault.m); - sqlite3_test_control(SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS, 0, 0); + sqlite3_test_control(SQLITE_TESTCTRL_BENIGN_MALLOC_CTRL, 0); } if( rc==SQLITE_OK ){