over eager garbage collection fix - use HandleRef instead of IntPtr to hold the C++ pointer

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7171 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2005-04-28 21:58:24 +00:00
commit f7cad9956b

View file

@ -66,24 +66,24 @@
/* Non primitive types */ /* Non primitive types */
%typemap(ctype) SWIGTYPE "void *" %typemap(ctype) SWIGTYPE "void *"
%typemap(imtype) SWIGTYPE "IntPtr" %typemap(imtype, out="IntPtr") SWIGTYPE "HandleRef"
%typemap(cstype) SWIGTYPE "$&csclassname" %typemap(cstype) SWIGTYPE "$&csclassname"
%typemap(ctype) SWIGTYPE [] "void *" %typemap(ctype) SWIGTYPE [] "void *"
%typemap(imtype) SWIGTYPE [] "IntPtr" %typemap(imtype, out="IntPtr") SWIGTYPE [] "HandleRef"
%typemap(cstype) SWIGTYPE [] "$csclassname" %typemap(cstype) SWIGTYPE [] "$csclassname"
%typemap(ctype) SWIGTYPE * "void *" %typemap(ctype) SWIGTYPE * "void *"
%typemap(imtype) SWIGTYPE * "IntPtr" %typemap(imtype, out="IntPtr") SWIGTYPE * "HandleRef"
%typemap(cstype) SWIGTYPE * "$csclassname" %typemap(cstype) SWIGTYPE * "$csclassname"
%typemap(ctype) SWIGTYPE & "void *" %typemap(ctype) SWIGTYPE & "void *"
%typemap(imtype) SWIGTYPE & "IntPtr" %typemap(imtype, out="IntPtr") SWIGTYPE & "HandleRef"
%typemap(cstype) SWIGTYPE & "$csclassname" %typemap(cstype) SWIGTYPE & "$csclassname"
/* pointer to a class member */ /* pointer to a class member */
%typemap(ctype) SWIGTYPE (CLASS::*) "int" %typemap(ctype) SWIGTYPE (CLASS::*) "int"
%typemap(imtype) SWIGTYPE (CLASS::*) "IntPtr" %typemap(imtype, out="IntPtr") SWIGTYPE (CLASS::*) "HandleRef"
%typemap(cstype) SWIGTYPE (CLASS::*) "$csclassname" %typemap(cstype) SWIGTYPE (CLASS::*) "$csclassname"
/* The following are the in and out typemaps. These are the PInvoke code generating typemaps for converting from C# to C and visa versa. */ /* The following are the in and out typemaps. These are the PInvoke code generating typemaps for converting from C# to C and visa versa. */
@ -539,53 +539,53 @@ $1 = &temp; %}
%typemap(csbase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" %typemap(csbase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
%typemap(csclassmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "public class" %typemap(csclassmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "public class"
%typemap(cscode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" %typemap(cscode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
%typemap(csimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "\nusing System;\n" %typemap(csimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "\nusing System;\nusing System.Runtime.InteropServices;\n"
%typemap(csinterfaces) SWIGTYPE "IDisposable" %typemap(csinterfaces) SWIGTYPE "IDisposable"
%typemap(csinterfaces) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" %typemap(csinterfaces) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
%typemap(csinterfaces_derived) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" %typemap(csinterfaces_derived) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
// Proxy classes (base classes, ie, not derived classes) // Proxy classes (base classes, ie, not derived classes)
%typemap(csbody) SWIGTYPE %{ %typemap(csbody) SWIGTYPE %{
private IntPtr swigCPtr; private HandleRef swigCPtr;
protected bool swigCMemOwn; protected bool swigCMemOwn;
internal $csclassname(IntPtr cPtr, bool cMemoryOwn) { internal $csclassname(IntPtr cPtr, bool cMemoryOwn) {
swigCMemOwn = cMemoryOwn; swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr; swigCPtr = new HandleRef(this, cPtr);
} }
internal static IntPtr getCPtr($csclassname obj) { internal static HandleRef getCPtr($csclassname obj) {
return (obj == null) ? IntPtr.Zero : obj.swigCPtr; return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
} }
%} %}
// Derived proxy classes // Derived proxy classes
%typemap(csbody_derived) SWIGTYPE %{ %typemap(csbody_derived) SWIGTYPE %{
private IntPtr swigCPtr; private HandleRef swigCPtr;
internal $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($modulePINVOKE.$csclassnameUpcast(cPtr), cMemoryOwn) { internal $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($modulePINVOKE.$csclassnameUpcast(cPtr), cMemoryOwn) {
swigCPtr = cPtr; swigCPtr = new HandleRef(this, cPtr);
} }
internal static IntPtr getCPtr($csclassname obj) { internal static HandleRef getCPtr($csclassname obj) {
return (obj == null) ? IntPtr.Zero : obj.swigCPtr; return (obj == null) ? IntPtr.Zero : obj.swigCPtr;
} }
%} %}
// Typewrapper classes // Typewrapper classes
%typemap(csbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ %typemap(csbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{
private IntPtr swigCPtr; private HandleRef swigCPtr;
internal $csclassname(IntPtr cPtr, bool futureUse) { internal $csclassname(IntPtr cPtr, bool futureUse) {
swigCPtr = cPtr; swigCPtr = new HandleRef(this, cPtr);
} }
protected $csclassname() { protected $csclassname() {
swigCPtr = IntPtr.Zero; swigCPtr = new HandleRef(null, IntPtr.Zero);
} }
internal static IntPtr getCPtr($csclassname obj) { internal static HandleRef getCPtr($csclassname obj) {
return (obj == null) ? IntPtr.Zero : obj.swigCPtr; return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
} }
%} %}
@ -600,20 +600,20 @@ $1 = &temp; %}
%} %}
%typemap(csdestruct, methodname="Dispose") SWIGTYPE { %typemap(csdestruct, methodname="Dispose") SWIGTYPE {
if(swigCPtr != IntPtr.Zero && swigCMemOwn) { if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
swigCMemOwn = false; swigCMemOwn = false;
$imcall; $imcall;
} }
swigCPtr = IntPtr.Zero; swigCPtr = new HandleRef(null, IntPtr.Zero);
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
%typemap(csdestruct_derived, methodname="Dispose") SWIGTYPE { %typemap(csdestruct_derived, methodname="Dispose") SWIGTYPE {
if(swigCPtr != IntPtr.Zero && swigCMemOwn) { if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
swigCMemOwn = false; swigCMemOwn = false;
$imcall; $imcall;
} }
swigCPtr = IntPtr.Zero; swigCPtr = new Handle(null, IntPtr.Zero);
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
base.Dispose(); base.Dispose();
} }
@ -631,6 +631,7 @@ $1 = &temp; %}
%pragma(csharp) moduleimports=%{ %pragma(csharp) moduleimports=%{
using System; using System;
using System.Runtime.InteropServices;
%} %}
%pragma(csharp) imclassimports=%{ %pragma(csharp) imclassimports=%{