summaryrefslogtreecommitdiffstats
path: root/third_party/sqlite/src/fault.c
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/sqlite/src/fault.c')
-rw-r--r--third_party/sqlite/src/fault.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/third_party/sqlite/src/fault.c b/third_party/sqlite/src/fault.c
index 5ede8b9..b36dd36 100644
--- a/third_party/sqlite/src/fault.c
+++ b/third_party/sqlite/src/fault.c
@@ -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();
}
}