summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2005-06-10 23:29:58 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2005-06-10 23:29:58 +0000
commit3f71da70504da327f6c865b65b7f5a213416d58c (patch)
treecd21993410e56456018962c9bd2cc6bea081dd13
parent4a34bca24dec078c621ad3c5597804a421ced03c (diff)
downloadswig-3f71da70504da327f6c865b65b7f5a213416d58c.tar.gz
Fix early garbage collection for alternative char * typemaps
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7275 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r--SWIG/Lib/csharp/csharp.swg16
1 files changed, 8 insertions, 8 deletions
diff --git a/SWIG/Lib/csharp/csharp.swg b/SWIG/Lib/csharp/csharp.swg
index 8ae9a2a1d..2a1805338 100644
--- a/SWIG/Lib/csharp/csharp.swg
+++ b/SWIG/Lib/csharp/csharp.swg
@@ -653,22 +653,22 @@ using System.Runtime.InteropServices;
/*
// Alternative char * typemaps.
-// Warning the GC may collect the SWIGStringMarshal instance while the unmanaged code is executing, so these typemaps should be avoided.
%pragma(csharp) imclasscode=%{
- public class SWIGStringMarshal {
- public readonly IntPtr ptr;
+ public class SWIGStringMarshal : IDisposable {
+ public readonly HandleRef swigCPtr;
public SWIGStringMarshal(string str) {
- ptr = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(str);
+ swigCPtr = new HandleRef(this, System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(str));
}
- ~SWIGStringMarshal() {
- System.Runtime.InteropServices.Marshal.FreeHGlobal(ptr);
+ public virtual void Dispose() {
+ System.Runtime.InteropServices.Marshal.FreeHGlobal(swigCPtr.Handle);
+ GC.SuppressFinalize(this);
}
}
%}
-%typemap(imtype) char *, char[ANY], char[] "IntPtr"
+%typemap(imtype, out="IntPtr") char *, char[ANY], char[] "HandleRef"
%typemap(out) char *, char[ANY], char[] %{ $result = $1; %}
-%typemap(csin) char *, char[ANY], char[] "new $modulePINVOKE.SWIGStringMarshal($csinput).ptr"
+%typemap(csin) char *, char[ANY], char[] "new $modulePINVOKE.SWIGStringMarshal($csinput).swigCPtr"
%typemap(csout, excode=SWIGEXCODE) char *, char[ANY], char[] {
string ret = System.Runtime.InteropServices.Marshal.PtrToStringAnsi($imcall);$excode
return ret;