Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* ----------------------------------------------------------------------------- |
2 | * csharphead.swg | |
3 | * | |
4 | * CSharp support code | |
5 | * ----------------------------------------------------------------------------- */ | |
6 | ||
7 | %insert(runtime) %{ | |
8 | #include <stdlib.h> | |
9 | #include <string.h> | |
10 | #include <stdio.h> | |
11 | %} | |
12 | ||
13 | %insert(runtime) %{ | |
14 | /* Support for throwing C# exceptions from C/C++. There are two types: | |
15 | * Exceptions that take a message and ArgumentExceptions that take a message and a parameter name. */ | |
16 | typedef enum { | |
17 | SWIG_CSharpApplicationException, | |
18 | SWIG_CSharpArithmeticException, | |
19 | SWIG_CSharpDivideByZeroException, | |
20 | SWIG_CSharpIndexOutOfRangeException, | |
21 | SWIG_CSharpInvalidOperationException, | |
22 | SWIG_CSharpIOException, | |
23 | SWIG_CSharpNullReferenceException, | |
24 | SWIG_CSharpOutOfMemoryException, | |
25 | SWIG_CSharpOverflowException, | |
26 | SWIG_CSharpSystemException | |
27 | } SWIG_CSharpExceptionCodes; | |
28 | ||
29 | typedef enum { | |
30 | SWIG_CSharpArgumentException, | |
31 | SWIG_CSharpArgumentNullException, | |
32 | SWIG_CSharpArgumentOutOfRangeException | |
33 | } SWIG_CSharpExceptionArgumentCodes; | |
34 | ||
35 | typedef void (SWIGSTDCALL* SWIG_CSharpExceptionCallback_t)(const char *); | |
36 | typedef void (SWIGSTDCALL* SWIG_CSharpExceptionArgumentCallback_t)(const char *, const char *); | |
37 | ||
38 | typedef struct { | |
39 | SWIG_CSharpExceptionCodes code; | |
40 | SWIG_CSharpExceptionCallback_t callback; | |
41 | } SWIG_CSharpException_t; | |
42 | ||
43 | typedef struct { | |
44 | SWIG_CSharpExceptionArgumentCodes code; | |
45 | SWIG_CSharpExceptionArgumentCallback_t callback; | |
46 | } SWIG_CSharpExceptionArgument_t; | |
47 | ||
48 | static SWIG_CSharpException_t SWIG_csharp_exceptions[] = { | |
49 | { SWIG_CSharpApplicationException, NULL }, | |
50 | { SWIG_CSharpArithmeticException, NULL }, | |
51 | { SWIG_CSharpDivideByZeroException, NULL }, | |
52 | { SWIG_CSharpIndexOutOfRangeException, NULL }, | |
53 | { SWIG_CSharpInvalidOperationException, NULL }, | |
54 | { SWIG_CSharpIOException, NULL }, | |
55 | { SWIG_CSharpNullReferenceException, NULL }, | |
56 | { SWIG_CSharpOutOfMemoryException, NULL }, | |
57 | { SWIG_CSharpOverflowException, NULL }, | |
58 | { SWIG_CSharpSystemException, NULL } | |
59 | }; | |
60 | ||
61 | static SWIG_CSharpExceptionArgument_t SWIG_csharp_exceptions_argument[] = { | |
62 | { SWIG_CSharpArgumentException, NULL }, | |
63 | { SWIG_CSharpArgumentNullException, NULL }, | |
64 | { SWIG_CSharpArgumentOutOfRangeException, NULL }, | |
65 | }; | |
66 | ||
67 | static void SWIG_CSharpSetPendingException(SWIG_CSharpExceptionCodes code, const char *msg) { | |
68 | SWIG_CSharpExceptionCallback_t callback = SWIG_csharp_exceptions[SWIG_CSharpApplicationException].callback; | |
69 | if (code >=0 && (size_t)code < sizeof(SWIG_csharp_exceptions)/sizeof(SWIG_CSharpException_t)) { | |
70 | callback = SWIG_csharp_exceptions[code].callback; | |
71 | } | |
72 | callback(msg); | |
73 | } | |
74 | ||
75 | static void SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpExceptionArgumentCodes code, const char *msg, const char *param_name) { | |
76 | SWIG_CSharpExceptionArgumentCallback_t callback = SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentException].callback; | |
77 | if (code >=0 && (size_t)code < sizeof(SWIG_csharp_exceptions_argument)/sizeof(SWIG_CSharpExceptionArgument_t)) { | |
78 | callback = SWIG_csharp_exceptions_argument[code].callback; | |
79 | } | |
80 | callback(msg, param_name); | |
81 | } | |
82 | %} | |
83 | ||
84 | %insert(runtime) %{ | |
85 | #ifdef __cplusplus | |
86 | extern "C" | |
87 | #endif | |
88 | SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionCallbacks_$module( | |
89 | SWIG_CSharpExceptionCallback_t applicationCallback, | |
90 | SWIG_CSharpExceptionCallback_t arithmeticCallback, | |
91 | SWIG_CSharpExceptionCallback_t divideByZeroCallback, | |
92 | SWIG_CSharpExceptionCallback_t indexOutOfRangeCallback, | |
93 | SWIG_CSharpExceptionCallback_t invalidOperationCallback, | |
94 | SWIG_CSharpExceptionCallback_t ioCallback, | |
95 | SWIG_CSharpExceptionCallback_t nullReferenceCallback, | |
96 | SWIG_CSharpExceptionCallback_t outOfMemoryCallback, | |
97 | SWIG_CSharpExceptionCallback_t overflowCallback, | |
98 | SWIG_CSharpExceptionCallback_t systemCallback) { | |
99 | SWIG_csharp_exceptions[SWIG_CSharpApplicationException].callback = applicationCallback; | |
100 | SWIG_csharp_exceptions[SWIG_CSharpArithmeticException].callback = arithmeticCallback; | |
101 | SWIG_csharp_exceptions[SWIG_CSharpDivideByZeroException].callback = divideByZeroCallback; | |
102 | SWIG_csharp_exceptions[SWIG_CSharpIndexOutOfRangeException].callback = indexOutOfRangeCallback; | |
103 | SWIG_csharp_exceptions[SWIG_CSharpInvalidOperationException].callback = invalidOperationCallback; | |
104 | SWIG_csharp_exceptions[SWIG_CSharpIOException].callback = ioCallback; | |
105 | SWIG_csharp_exceptions[SWIG_CSharpNullReferenceException].callback = nullReferenceCallback; | |
106 | SWIG_csharp_exceptions[SWIG_CSharpOutOfMemoryException].callback = outOfMemoryCallback; | |
107 | SWIG_csharp_exceptions[SWIG_CSharpOverflowException].callback = overflowCallback; | |
108 | SWIG_csharp_exceptions[SWIG_CSharpSystemException].callback = systemCallback; | |
109 | } | |
110 | ||
111 | #ifdef __cplusplus | |
112 | extern "C" | |
113 | #endif | |
114 | SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module( | |
115 | SWIG_CSharpExceptionArgumentCallback_t argumentCallback, | |
116 | SWIG_CSharpExceptionArgumentCallback_t argumentNullCallback, | |
117 | SWIG_CSharpExceptionArgumentCallback_t argumentOutOfRangeCallback) { | |
118 | SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentException].callback = argumentCallback; | |
119 | SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentNullException].callback = argumentNullCallback; | |
120 | SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentOutOfRangeException].callback = argumentOutOfRangeCallback; | |
121 | } | |
122 | %} | |
123 | ||
124 | %pragma(csharp) imclasscode=%{ | |
125 | protected class SWIGExceptionHelper { | |
126 | ||
127 | public delegate void ExceptionDelegate(string message); | |
128 | public delegate void ExceptionArgumentDelegate(string message, string paramName); | |
129 | ||
130 | static ExceptionDelegate applicationDelegate = new ExceptionDelegate(SetPendingApplicationException); | |
131 | static ExceptionDelegate arithmeticDelegate = new ExceptionDelegate(SetPendingArithmeticException); | |
132 | static ExceptionDelegate divideByZeroDelegate = new ExceptionDelegate(SetPendingDivideByZeroException); | |
133 | static ExceptionDelegate indexOutOfRangeDelegate = new ExceptionDelegate(SetPendingIndexOutOfRangeException); | |
134 | static ExceptionDelegate invalidOperationDelegate = new ExceptionDelegate(SetPendingInvalidOperationException); | |
135 | static ExceptionDelegate ioDelegate = new ExceptionDelegate(SetPendingIOException); | |
136 | static ExceptionDelegate nullReferenceDelegate = new ExceptionDelegate(SetPendingNullReferenceException); | |
137 | static ExceptionDelegate outOfMemoryDelegate = new ExceptionDelegate(SetPendingOutOfMemoryException); | |
138 | static ExceptionDelegate overflowDelegate = new ExceptionDelegate(SetPendingOverflowException); | |
139 | static ExceptionDelegate systemDelegate = new ExceptionDelegate(SetPendingSystemException); | |
140 | ||
141 | static ExceptionArgumentDelegate argumentDelegate = new ExceptionArgumentDelegate(SetPendingArgumentException); | |
142 | static ExceptionArgumentDelegate argumentNullDelegate = new ExceptionArgumentDelegate(SetPendingArgumentNullException); | |
143 | static ExceptionArgumentDelegate argumentOutOfRangeDelegate = new ExceptionArgumentDelegate(SetPendingArgumentOutOfRangeException); | |
144 | ||
145 | [DllImport("$dllimport", EntryPoint="SWIGRegisterExceptionCallbacks_$module")] | |
146 | public static extern void SWIGRegisterExceptionCallbacks_$module( | |
147 | ExceptionDelegate applicationDelegate, | |
148 | ExceptionDelegate arithmeticDelegate, | |
149 | ExceptionDelegate divideByZeroDelegate, | |
150 | ExceptionDelegate indexOutOfRangeDelegate, | |
151 | ExceptionDelegate invalidOperationDelegate, | |
152 | ExceptionDelegate ioDelegate, | |
153 | ExceptionDelegate nullReferenceDelegate, | |
154 | ExceptionDelegate outOfMemoryDelegate, | |
155 | ExceptionDelegate overflowDelegate, | |
156 | ExceptionDelegate systemExceptionDelegate); | |
157 | ||
158 | [DllImport("$dllimport", EntryPoint="SWIGRegisterExceptionArgumentCallbacks_$module")] | |
159 | public static extern void SWIGRegisterExceptionCallbacksArgument_$module( | |
160 | ExceptionArgumentDelegate argumentDelegate, | |
161 | ExceptionArgumentDelegate argumentNullDelegate, | |
162 | ExceptionArgumentDelegate argumentOutOfRangeDelegate); | |
163 | ||
164 | static void SetPendingApplicationException(string message) { | |
165 | SWIGPendingException.Set(new System.ApplicationException(message)); | |
166 | } | |
167 | static void SetPendingArithmeticException(string message) { | |
168 | SWIGPendingException.Set(new System.ArithmeticException(message)); | |
169 | } | |
170 | static void SetPendingDivideByZeroException(string message) { | |
171 | SWIGPendingException.Set(new System.DivideByZeroException(message)); | |
172 | } | |
173 | static void SetPendingIndexOutOfRangeException(string message) { | |
174 | SWIGPendingException.Set(new System.IndexOutOfRangeException(message)); | |
175 | } | |
176 | static void SetPendingInvalidOperationException(string message) { | |
177 | SWIGPendingException.Set(new System.InvalidOperationException(message)); | |
178 | } | |
179 | static void SetPendingIOException(string message) { | |
180 | SWIGPendingException.Set(new System.IO.IOException(message)); | |
181 | } | |
182 | static void SetPendingNullReferenceException(string message) { | |
183 | SWIGPendingException.Set(new System.NullReferenceException(message)); | |
184 | } | |
185 | static void SetPendingOutOfMemoryException(string message) { | |
186 | SWIGPendingException.Set(new System.OutOfMemoryException(message)); | |
187 | } | |
188 | static void SetPendingOverflowException(string message) { | |
189 | SWIGPendingException.Set(new System.OverflowException(message)); | |
190 | } | |
191 | static void SetPendingSystemException(string message) { | |
192 | SWIGPendingException.Set(new System.SystemException(message)); | |
193 | } | |
194 | ||
195 | static void SetPendingArgumentException(string message, string paramName) { | |
196 | SWIGPendingException.Set(new System.ArgumentException(message, paramName)); | |
197 | } | |
198 | static void SetPendingArgumentNullException(string message, string paramName) { | |
199 | SWIGPendingException.Set(new System.ArgumentNullException(paramName, message)); | |
200 | } | |
201 | static void SetPendingArgumentOutOfRangeException(string message, string paramName) { | |
202 | SWIGPendingException.Set(new System.ArgumentOutOfRangeException(paramName, message)); | |
203 | } | |
204 | ||
205 | static SWIGExceptionHelper() { | |
206 | SWIGRegisterExceptionCallbacks_$module( | |
207 | applicationDelegate, | |
208 | arithmeticDelegate, | |
209 | divideByZeroDelegate, | |
210 | indexOutOfRangeDelegate, | |
211 | invalidOperationDelegate, | |
212 | ioDelegate, | |
213 | nullReferenceDelegate, | |
214 | outOfMemoryDelegate, | |
215 | overflowDelegate, | |
216 | systemDelegate); | |
217 | ||
218 | SWIGRegisterExceptionCallbacksArgument_$module( | |
219 | argumentDelegate, | |
220 | argumentNullDelegate, | |
221 | argumentOutOfRangeDelegate); | |
222 | } | |
223 | } | |
224 | ||
225 | protected static SWIGExceptionHelper swigExceptionHelper = new SWIGExceptionHelper(); | |
226 | ||
227 | public class SWIGPendingException { | |
228 | [ThreadStatic] | |
229 | private static Exception pendingException = null; | |
230 | private static int numExceptionsPending = 0; | |
231 | ||
232 | public static bool Pending { | |
233 | get { | |
234 | bool pending = false; | |
235 | if (numExceptionsPending > 0) | |
236 | if (pendingException != null) | |
237 | pending = true; | |
238 | return pending; | |
239 | } | |
240 | } | |
241 | ||
242 | public static void Set(Exception e) { | |
243 | if (pendingException != null) | |
244 | throw new ApplicationException("FATAL: An earlier pending exception from unmanaged code was missed and thus not thrown (" + pendingException.ToString() + ")", e); | |
245 | pendingException = e; | |
246 | lock(typeof($modulePINVOKE)) { | |
247 | numExceptionsPending++; | |
248 | } | |
249 | } | |
250 | ||
251 | public static Exception Retrieve() { | |
252 | Exception e = null; | |
253 | if (numExceptionsPending > 0) { | |
254 | if (pendingException != null) { | |
255 | e = pendingException; | |
256 | pendingException = null; | |
257 | lock(typeof($modulePINVOKE)) { | |
258 | numExceptionsPending--; | |
259 | } | |
260 | } | |
261 | } | |
262 | return e; | |
263 | } | |
264 | } | |
265 | %} | |
266 | ||
267 | %insert(runtime) %{ | |
268 | /* Callback for returning strings to C# without leaking memory */ | |
269 | typedef char * (SWIGSTDCALL* SWIG_CSharpStringHelperCallback)(const char *); | |
270 | static SWIG_CSharpStringHelperCallback SWIG_csharp_string_callback = NULL; | |
271 | %} | |
272 | ||
273 | %pragma(csharp) imclasscode=%{ | |
274 | protected class SWIGStringHelper { | |
275 | ||
276 | public delegate string SWIGStringDelegate(string message); | |
277 | static SWIGStringDelegate stringDelegate = new SWIGStringDelegate(CreateString); | |
278 | ||
279 | [DllImport("$dllimport", EntryPoint="SWIGRegisterStringCallback_$module")] | |
280 | public static extern void SWIGRegisterStringCallback_$module(SWIGStringDelegate stringDelegate); | |
281 | ||
282 | static string CreateString(string cString) { | |
283 | return cString; | |
284 | } | |
285 | ||
286 | static SWIGStringHelper() { | |
287 | SWIGRegisterStringCallback_$module(stringDelegate); | |
288 | } | |
289 | } | |
290 | ||
291 | static protected SWIGStringHelper swigStringHelper = new SWIGStringHelper(); | |
292 | %} | |
293 | ||
294 | %insert(runtime) %{ | |
295 | #ifdef __cplusplus | |
296 | extern "C" | |
297 | #endif | |
298 | SWIGEXPORT void SWIGSTDCALL SWIGRegisterStringCallback_$module(SWIG_CSharpStringHelperCallback callback) { | |
299 | SWIG_csharp_string_callback = callback; | |
300 | } | |
301 | ||
302 | /* Contract support */ | |
303 | ||
304 | #define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, msg, ""); return nullreturn; } else | |
305 | %} |