forked from MapServer/MapServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswig_csharp_extensions.i
More file actions
305 lines (271 loc) · 11.5 KB
/
Copy pathswig_csharp_extensions.i
File metadata and controls
305 lines (271 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/******************************************************************************
* $Id$
*
* Project: MapServer
* Purpose: Fix for the SWIG Interface problems (early GC)
* and implementing SWIGTYPE *DISOWN
* Author: Tamas Szekeres, szekerest@gmail.com
*
******************************************************************************
* Copyright (c) 1996-2008 Regents of the University of Minnesota.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies of this Software or works derived from this Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
// Ensure the class is not marked BeforeFieldInit causing memory corruption with CLR4
%pragma(csharp) imclasscode=%{
public class UTF8Marshaler : System.Runtime.InteropServices.ICustomMarshaler {
static UTF8Marshaler static_instance;
public System.IntPtr MarshalManagedToNative(object managedObj) {
if (managedObj == null)
return System.IntPtr.Zero;
if (!(managedObj is string))
throw new System.Runtime.InteropServices.MarshalDirectiveException(
"UTF8Marshaler must be used on a string.");
// not null terminated
byte[] strbuf = System.Text.Encoding.UTF8.GetBytes((string)managedObj);
System.IntPtr buffer = System.Runtime.InteropServices.Marshal.AllocHGlobal(strbuf.Length + 1);
System.Runtime.InteropServices.Marshal.Copy(strbuf, 0, buffer, strbuf.Length);
// write the terminating null
System.Runtime.InteropServices.Marshal.WriteByte(buffer, strbuf.Length, 0);
return buffer;
}
public object MarshalNativeToManaged(System.IntPtr pNativeData) {
int len = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(pNativeData).Length;
byte[] utf8data = new byte[len];
System.Runtime.InteropServices.Marshal.Copy(pNativeData, utf8data, 0, len);
return System.Text.Encoding.UTF8.GetString(utf8data);
}
public void CleanUpNativeData(System.IntPtr pNativeData) {
System.Runtime.InteropServices.Marshal.FreeHGlobal(pNativeData);
}
public void CleanUpManagedData(object managedObj) {
}
public int GetNativeDataSize() {
return -1;
}
public static System.Runtime.InteropServices.ICustomMarshaler GetInstance(string cookie) {
if (static_instance == null) {
return static_instance = new UTF8Marshaler();
}
return static_instance;
}
}
%}
%typemap(imtype, inattributes="[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]",
outattributes="[return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]")
char *, char *&, char[ANY], char[] "string"
%typemap(csout, excode=SWIGEXCODE) SWIGTYPE {
/* %typemap(csout, excode=SWIGEXCODE) SWIGTYPE */
$&csclassname ret = new $&csclassname($imcall, true, null);$excode
return ret;
}
%typemap(csout, excode=SWIGEXCODE, new="1") SWIGTYPE & {
/* typemap(csout, excode=SWIGEXCODE, new="1") SWIGTYPE & */
$csclassname ret = new $csclassname($imcall, $owner, ThisOwn_$owner());$excode
return ret;
}
%typemap(csout, excode=SWIGEXCODE, new="1") SWIGTYPE *, SWIGTYPE [], SWIGTYPE (CLASS::*) {
/* %typemap(csout, excode=SWIGEXCODE, new="1") SWIGTYPE *, SWIGTYPE [], SWIGTYPE (CLASS::*) */
System.IntPtr cPtr = $imcall;
$csclassname ret = (cPtr == System.IntPtr.Zero) ? null : new $csclassname(cPtr, $owner, ThisOwn_$owner());$excode
return ret;
}
%typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE %{
/* %typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE */
get {
$&csclassname ret = new $&csclassname($imcall, $owner, ThisOwn_$owner());$excode
return ret;
} %}
%typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE & %{
/* %typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE & */
get {
$csclassname ret = new $csclassname($imcall, $owner, ThisOwn_$owner());$excode
return ret;
} %}
%typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE *, struct SWIGTYPE *, SWIGTYPE [], SWIGTYPE (CLASS::*) %{
/* %typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE *, SWIGTYPE [], SWIGTYPE (CLASS::*) */
get {
System.IntPtr cPtr = $imcall;
$csclassname ret = (cPtr == System.IntPtr.Zero) ? null : new $csclassname(cPtr, $owner, ThisOwn_$owner());$excode
return ret;
} %}
%typemap(csout, excode=SWIGEXCODE) SWIGTYPE *& {
/* %typemap(csout, excode=SWIGEXCODE) SWIGTYPE *& */
System.IntPtr cPtr = $imcall;
$*csclassname ret = (cPtr == System.IntPtr.Zero) ? null : new $*csclassname(cPtr, $owner, ThisOwn_$owner());$excode
return ret;
}
// Proxy classes (base classes, ie, not derived classes)
%typemap(csbody) SWIGTYPE %{
/* %typemap(csbody) SWIGTYPE */
private System.Runtime.InteropServices.HandleRef swigCPtr;
protected bool swigCMemOwn;
protected object swigParentRef;
protected static object ThisOwn_true() { return null; }
protected object ThisOwn_false() { return this; }
internal $csclassname(System.IntPtr cPtr, bool cMemoryOwn, object parent) {
swigCMemOwn = cMemoryOwn;
swigParentRef = parent;
swigCPtr = new System.Runtime.InteropServices.HandleRef(this, cPtr);
}
internal static System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new System.Runtime.InteropServices.HandleRef(null, System.IntPtr.Zero) : obj.swigCPtr;
}
internal static System.Runtime.InteropServices.HandleRef getCPtrAndDisown($csclassname obj, object parent) {
if (obj != null)
{
obj.swigCMemOwn = false;
obj.swigParentRef = parent;
return obj.swigCPtr;
}
else
{
return new System.Runtime.InteropServices.HandleRef(null, System.IntPtr.Zero);
}
}
internal static System.Runtime.InteropServices.HandleRef getCPtrAndSetReference($csclassname obj, object parent) {
if (obj != null)
{
obj.swigParentRef = parent;
return obj.swigCPtr;
}
else
{
return new System.Runtime.InteropServices.HandleRef(null, System.IntPtr.Zero);
}
}
%}
// Derived proxy classes
%typemap(csbody_derived) SWIGTYPE %{
/* %typemap(csbody_derived) SWIGTYPE */
private System.Runtime.InteropServices.HandleRef swigCPtr;
internal $csclassname(System.IntPtr cPtr, bool cMemoryOwn, object parent) : base($modulePINVOKE.$csclassnameUpcast(cPtr), cMemoryOwn, parent) {
swigCPtr = new System.Runtime.InteropServices.HandleRef(this, cPtr);
}
internal static System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new System.Runtime.InteropServices.HandleRef(null, System.IntPtr.Zero) : obj.swigCPtr;
}
internal static System.Runtime.InteropServices.HandleRef getCPtrAndDisown($csclassname obj, object parent) {
if (obj != null)
{
obj.swigCMemOwn = false;
obj.swigParentRef = parent;
return obj.swigCPtr;
}
else
{
return new System.Runtime.InteropServices.HandleRef(null, System.IntPtr.Zero);
}
}
internal static System.Runtime.InteropServices.HandleRef getCPtrAndSetReference($csclassname obj, object parent) {
if (obj != null)
{
obj.swigParentRef = parent;
return obj.swigCPtr;
}
else
{
return new System.Runtime.InteropServices.HandleRef(null, System.IntPtr.Zero);
}
}
%}
// Typewrapper classes
%typemap(csbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{
/* %typemap(csbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) */
private System.Runtime.InteropServices.HandleRef swigCPtr;
internal $csclassname(System.IntPtr cPtr, bool futureUse, object parent) {
swigCPtr = new System.Runtime.InteropServices.HandleRef(this, cPtr);
}
protected $csclassname() {
swigCPtr = new System.Runtime.InteropServices.HandleRef(null, System.IntPtr.Zero);
}
internal static System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new System.Runtime.InteropServices.HandleRef(null, System.IntPtr.Zero) : obj.swigCPtr;
}
%}
#if SWIG_VERSION < 0x040000
%typemap(csfinalize) SWIGTYPE %{
/* %typemap(csfinalize) SWIGTYPE */
~$csclassname() {
Dispose();
}
%}
#endif
%typemap(csconstruct, excode=SWIGEXCODE) SWIGTYPE %{: this($imcall, true, null) {$excode
}
%}
#if SWIG_VERSION < 0x040000
%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") SWIGTYPE {
lock(this) {
if(swigCPtr.Handle != System.IntPtr.Zero && swigCMemOwn) {
swigCMemOwn = false;
$imcall;
}
swigCPtr = new System.Runtime.InteropServices.HandleRef(null, System.IntPtr.Zero);
swigParentRef = null;
System.GC.SuppressFinalize(this);
}
}
#endif
%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") TYPE {
lock(this) {
if(swigCPtr.Handle != System.IntPtr.Zero && swigCMemOwn) {
swigCMemOwn = false;
$imcall;
}
swigCPtr = new System.Runtime.InteropServices.HandleRef(null, System.IntPtr.Zero);
swigParentRef = null;
System.GC.SuppressFinalize(this);
base.Dispose();
}
}
%typemap(csin) SWIGTYPE *DISOWN "$csclassname.getCPtrAndDisown($csinput, ThisOwn_false())"
%typemap(csin) SWIGTYPE *SETREFERENCE "$csclassname.getCPtrAndSetReference($csinput, ThisOwn_false())"
%pragma(csharp) modulecode=%{
/* %pragma(csharp) modulecode */
internal class $moduleObject : global::System.IDisposable {
public virtual void Dispose() {
}
}
internal static $moduleObject the$moduleObject = new $moduleObject();
protected static object ThisOwn_true() { return null; }
protected static object ThisOwn_false() { return the$moduleObject; }
[System.Runtime.InteropServices.DllImport("$dllimport", EntryPoint="SetEnvironmentVariable")]
public static extern int SetEnvironmentVariable(string envstring);
%}
%insert(runtime) %{
#ifdef __cplusplus
extern "C"
#endif
#ifdef SWIGEXPORT
SWIGEXPORT int SWIGSTDCALL SetEnvironmentVariable(const char *envstring) {
/* putenv may not make a copy, so do it ourselves despite the memory leak */
char* envstringDup = (char*)malloc(strlen(envstring)+1);
memcpy(envstringDup, envstring, strlen(envstring)+1);
return putenv(envstringDup);
}
#else
DllExport int SWIGSTDCALL SetEnvironmentVariable(const char *envstring) {
/* putenv may not make a copy, so do it ourselves despite the memory leak */
char* envstringDup = (char*)malloc(strlen(envstring)+1);
memcpy(envstringDup, envstring, strlen(envstring)+1);
return putenv(envstringDup);
}
#endif
%}