wasCSharpSQLite – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 using System;
2 using System.Diagnostics;
3  
4 namespace Community.CsharpSqlite
5 {
6 public partial class Sqlite3
7 {
8 /*
9 ** 2008 Jan 22
10 **
11 ** The author disclaims copyright to this source code. In place of
12 ** a legal notice, here is a blessing:
13 **
14 ** May you do good and not evil.
15 ** May you find forgiveness for yourself and forgive others.
16 ** May you share freely, never taking more than you give.
17 *************************************************************************
18 **
19 ** This file contains code to support the concept of "benign"
20 ** malloc failures (when the xMalloc() or xRealloc() method of the
21 ** sqlite3_mem_methods structure fails to allocate a block of memory
22 ** and returns 0).
23 **
24 ** Most malloc failures are non-benign. After they occur, SQLite
25 ** abandons the current operation and returns an error code (usually
26 ** SQLITE_NOMEM) to the user. However, sometimes a fault is not necessarily
27 ** fatal. For example, if a malloc fails while resizing a hash table, this
28 ** is completely recoverable simply by not carrying out the resize. The
29 ** hash table will continue to function normally. So a malloc failure
30 ** during a hash table resize is a benign fault.
31 *************************************************************************
32 ** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart
33 ** C#-SQLite is an independent reimplementation of the SQLite software library
34 **
35 ** SQLITE_SOURCE_ID: 2010-08-23 18:52:01 42537b60566f288167f1b5864a5435986838e3a3
36 **
37 *************************************************************************
38 */
39 //#include "sqliteInt.h"
40  
41 #if !SQLITE_OMIT_BUILTIN_TEST
42 /*
43 ** Global variables.
44 */
45 //typedef struct BenignMallocHooks BenignMallocHooks;
46 public struct BenignMallocHooks//
47 {
48 public void_function xBenignBegin;//void (*xBenignBegin)(void);
49 public void_function xBenignEnd; //void (*xBenignEnd)(void);
50 public BenignMallocHooks( void_function xBenignBegin, void_function xBenignEnd )
51 {
52 this.xBenignBegin = xBenignBegin;
53 this.xBenignEnd = xBenignEnd;
54 }
55 }
56 static BenignMallocHooks sqlite3Hooks = new BenignMallocHooks( null, null );
57  
58 /* The "wsdHooks" macro will resolve to the appropriate BenignMallocHooks
59 ** structure. If writable static data is unsupported on the target,
60 ** we have to locate the state vector at run-time. In the more common
61 ** case where writable static data is supported, wsdHooks can refer directly
62 ** to the "sqlite3Hooks" state vector declared above.
63 */
64 #if SQLITE_OMIT_WSD
65 //# define wsdHooksInit \
66 BenignMallocHooks *x = &GLOBAL(BenignMallocHooks,sqlite3Hooks)
67 //# define wsdHooks x[0]
68 #else
69 //# define wsdHooksInit
70 static void wsdHooksInit()
71 {
72 }
73 //# define wsdHooks sqlite3Hooks
74 static BenignMallocHooks wsdHooks = sqlite3Hooks;
75 #endif
76  
77  
78  
79 /*
80 ** Register hooks to call when sqlite3BeginBenignMalloc() and
81 ** sqlite3EndBenignMalloc() are called, respectively.
82 */
83 static void sqlite3BenignMallocHooks(
84 void_function xBenignBegin, //void (*xBenignBegin)(void),
85 void_function xBenignEnd //void (*xBenignEnd)(void)
86 )
87 {
88 wsdHooksInit();
89 wsdHooks.xBenignBegin = xBenignBegin;
90 wsdHooks.xBenignEnd = xBenignEnd;
91 }
92  
93 /*
94 ** This (sqlite3EndBenignMalloc()) is called by SQLite code to indicate that
95 ** subsequent malloc failures are benign. A call to sqlite3EndBenignMalloc()
96 ** indicates that subsequent malloc failures are non-benign.
97 */
98 static void sqlite3BeginBenignMalloc()
99 {
100 wsdHooksInit();
101 if ( wsdHooks.xBenignBegin != null )
102 {
103 wsdHooks.xBenignBegin();
104 }
105 }
106 static void sqlite3EndBenignMalloc()
107 {
108 wsdHooksInit();
109 if ( wsdHooks.xBenignEnd != null )
110 {
111 wsdHooks.xBenignEnd();
112 }
113 }
114 #endif //* SQLITE_OMIT_BUILTIN_TEST */
115 }
116 }