OLD | NEW |
1 /* | 1 /* |
2 ** 2008 Jan 22 | 2 ** 2008 Jan 22 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
11 ************************************************************************* | 11 ************************************************************************* |
12 ** | 12 ** |
13 ** This file contains code to support the concept of "benign" | 13 ** This file contains code to support the concept of "benign" |
14 ** malloc failures (when the xMalloc() or xRealloc() method of the | 14 ** malloc failures (when the xMalloc() or xRealloc() method of the |
15 ** sqlite3_mem_methods structure fails to allocate a block of memory | 15 ** sqlite3_mem_methods structure fails to allocate a block of memory |
16 ** and returns 0). | 16 ** and returns 0). |
17 ** | 17 ** |
18 ** Most malloc failures are non-benign. After they occur, SQLite | 18 ** Most malloc failures are non-benign. After they occur, SQLite |
19 ** abandons the current operation and returns an error code (usually | 19 ** abandons the current operation and returns an error code (usually |
20 ** SQLITE_NOMEM) to the user. However, sometimes a fault is not necessarily | 20 ** SQLITE_NOMEM) to the user. However, sometimes a fault is not necessarily |
21 ** fatal. For example, if a malloc fails while resizing a hash table, this | 21 ** fatal. For example, if a malloc fails while resizing a hash table, this |
22 ** is completely recoverable simply by not carrying out the resize. The | 22 ** is completely recoverable simply by not carrying out the resize. The |
23 ** hash table will continue to function normally. So a malloc failure | 23 ** hash table will continue to function normally. So a malloc failure |
24 ** during a hash table resize is a benign fault. | 24 ** during a hash table resize is a benign fault. |
25 */ | 25 */ |
26 | 26 |
27 #include "sqliteInt.h" | 27 #include "sqliteInt.h" |
28 | 28 |
29 #ifndef SQLITE_OMIT_BUILTIN_TEST | 29 #ifndef SQLITE_UNTESTABLE |
30 | 30 |
31 /* | 31 /* |
32 ** Global variables. | 32 ** Global variables. |
33 */ | 33 */ |
34 typedef struct BenignMallocHooks BenignMallocHooks; | 34 typedef struct BenignMallocHooks BenignMallocHooks; |
35 static SQLITE_WSD struct BenignMallocHooks { | 35 static SQLITE_WSD struct BenignMallocHooks { |
36 void (*xBenignBegin)(void); | 36 void (*xBenignBegin)(void); |
37 void (*xBenignEnd)(void); | 37 void (*xBenignEnd)(void); |
38 } sqlite3Hooks = { 0, 0 }; | 38 } sqlite3Hooks = { 0, 0 }; |
39 | 39 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 wsdHooks.xBenignBegin(); | 77 wsdHooks.xBenignBegin(); |
78 } | 78 } |
79 } | 79 } |
80 void sqlite3EndBenignMalloc(void){ | 80 void sqlite3EndBenignMalloc(void){ |
81 wsdHooksInit; | 81 wsdHooksInit; |
82 if( wsdHooks.xBenignEnd ){ | 82 if( wsdHooks.xBenignEnd ){ |
83 wsdHooks.xBenignEnd(); | 83 wsdHooks.xBenignEnd(); |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 #endif /* #ifndef SQLITE_OMIT_BUILTIN_TEST */ | 87 #endif /* #ifndef SQLITE_UNTESTABLE */ |
OLD | NEW |