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
This commit is contained in:
parent
4a34bca24d
commit
3f71da7050
1 changed files with 8 additions and 8 deletions
|
|
@ -653,22 +653,22 @@ using System.Runtime.InteropServices;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Alternative char * typemaps.
|
// 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=%{
|
%pragma(csharp) imclasscode=%{
|
||||||
public class SWIGStringMarshal {
|
public class SWIGStringMarshal : IDisposable {
|
||||||
public readonly IntPtr ptr;
|
public readonly HandleRef swigCPtr;
|
||||||
public SWIGStringMarshal(string str) {
|
public SWIGStringMarshal(string str) {
|
||||||
ptr = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(str);
|
swigCPtr = new HandleRef(this, System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(str));
|
||||||
}
|
}
|
||||||
~SWIGStringMarshal() {
|
public virtual void Dispose() {
|
||||||
System.Runtime.InteropServices.Marshal.FreeHGlobal(ptr);
|
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(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[] {
|
%typemap(csout, excode=SWIGEXCODE) char *, char[ANY], char[] {
|
||||||
string ret = System.Runtime.InteropServices.Marshal.PtrToStringAnsi($imcall);$excode
|
string ret = System.Runtime.InteropServices.Marshal.PtrToStringAnsi($imcall);$excode
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue