1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

Continuing work on adding full support for the SQLITE_OMIT_WSD

compile-time option. (CVS 5658)

FossilOrigin-Name: ef26ea5c46d3915d206f8ff7f82a24f4c8955f1f
This commit is contained in:
drh
2008-09-02 00:52:52 +00:00
parent 171fa295c3
commit 78f82d1e6c
13 changed files with 252 additions and 145 deletions

View File

@@ -10,7 +10,7 @@
**
*************************************************************************
**
** $Id: fault.c,v 1.10 2008/06/22 12:37:58 drh Exp $
** $Id: fault.c,v 1.11 2008/09/02 00:52:52 drh Exp $
*/
/*
@@ -35,10 +35,27 @@
/*
** Global variables.
*/
static struct BenignMallocHooks {
typedef struct BenignMallocHooks BenignMallocHooks;
static SQLITE_WSD struct BenignMallocHooks {
void (*xBenignBegin)(void);
void (*xBenignEnd)(void);
} hooks;
} sqlite3Hooks = { 0, 0 };
/* 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.
*/
#ifdef SQLITE_OMIT_WSD
# define wsdHooksInit \
BenignMallocHooks *x = &GLOBAL(BenignMallocHooks,sqlite3Hooks)
# define wsdHooks x[0]
#else
# define wsdHooksInit
# define wsdHooks sqlite3Hooks
#endif
/*
** Register hooks to call when sqlite3BeginBenignMalloc() and
@@ -48,8 +65,9 @@ void sqlite3BenignMallocHooks(
void (*xBenignBegin)(void),
void (*xBenignEnd)(void)
){
hooks.xBenignBegin = xBenignBegin;
hooks.xBenignEnd = xBenignEnd;
wsdHooksInit;
wsdHooks.xBenignBegin = xBenignBegin;
wsdHooks.xBenignEnd = xBenignEnd;
}
/*
@@ -58,13 +76,15 @@ void sqlite3BenignMallocHooks(
** indicates that subsequent malloc failures are non-benign.
*/
void sqlite3BeginBenignMalloc(void){
if( hooks.xBenignBegin ){
hooks.xBenignBegin();
wsdHooksInit;
if( wsdHooks.xBenignBegin ){
wsdHooks.xBenignBegin();
}
}
void sqlite3EndBenignMalloc(void){
if( hooks.xBenignEnd ){
hooks.xBenignEnd();
wsdHooksInit;
if( wsdHooks.xBenignEnd ){
wsdHooks.xBenignEnd();
}
}