Avoid potential race conditions on the Dispose() method
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9444 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
2780b5ee3b
commit
ea6f44edd2
4 changed files with 35 additions and 19 deletions
|
|
@ -6,6 +6,9 @@ Version 1.3.30 (in progress)
|
||||||
(it is now a synchronized method, but is now customisable by changing the
|
(it is now a synchronized method, but is now customisable by changing the
|
||||||
methodmodifier attribute in the the javadestruct or javadestruct_derived typemap)
|
methodmodifier attribute in the the javadestruct or javadestruct_derived typemap)
|
||||||
|
|
||||||
|
[C#] Remove potential race condition on the proxy class' Dispose() method,
|
||||||
|
similar to Java's delete() above.
|
||||||
|
|
||||||
*** POTENTIAL INCOMPATIBILITY ***
|
*** POTENTIAL INCOMPATIBILITY ***
|
||||||
|
|
||||||
10/12/2006: wsfulton
|
10/12/2006: wsfulton
|
||||||
|
|
|
||||||
|
|
@ -1071,12 +1071,14 @@ public class Base : IDisposable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Dispose() {
|
public virtual void Dispose() {
|
||||||
if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
|
lock(this) {
|
||||||
swigCMemOwn = false;
|
if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
|
||||||
examplePINVOKE.delete_Base(swigCPtr);
|
swigCMemOwn = false;
|
||||||
|
examplePINVOKE.delete_Base(swigCPtr);
|
||||||
|
}
|
||||||
|
swigCPtr = new HandleRef(null, IntPtr.Zero);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
swigCPtr = new HandleRef(null, IntPtr.Zero);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual uint UIntMethod(uint x) {
|
public virtual uint UIntMethod(uint x) {
|
||||||
|
|
|
||||||
|
|
@ -787,23 +787,27 @@
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%typemap(csdestruct, methodname="Dispose") SWIGTYPE {
|
%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") SWIGTYPE {
|
||||||
if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
|
lock(this) {
|
||||||
swigCMemOwn = false;
|
if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
|
||||||
$imcall;
|
swigCMemOwn = false;
|
||||||
|
$imcall;
|
||||||
|
}
|
||||||
|
swigCPtr = new HandleRef(null, IntPtr.Zero);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
swigCPtr = new HandleRef(null, IntPtr.Zero);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(csdestruct_derived, methodname="Dispose") SWIGTYPE {
|
%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") SWIGTYPE {
|
||||||
if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
|
lock(this) {
|
||||||
swigCMemOwn = false;
|
if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
|
||||||
$imcall;
|
swigCMemOwn = false;
|
||||||
|
$imcall;
|
||||||
|
}
|
||||||
|
swigCPtr = new HandleRef(null, IntPtr.Zero);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
base.Dispose();
|
||||||
}
|
}
|
||||||
swigCPtr = new HandleRef(null, IntPtr.Zero);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
base.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(directordisconnect, methodname="swigDirectorDisconnect") SWIGTYPE %{
|
%typemap(directordisconnect, methodname="swigDirectorDisconnect") SWIGTYPE %{
|
||||||
|
|
|
||||||
|
|
@ -1542,17 +1542,24 @@ class CSHARP : public Language {
|
||||||
const String *tm = NULL;
|
const String *tm = NULL;
|
||||||
Node *attributes = NewHash();
|
Node *attributes = NewHash();
|
||||||
String *destruct_methodname = NULL;
|
String *destruct_methodname = NULL;
|
||||||
|
String *destruct_methodmodifiers = NULL;
|
||||||
if (derived) {
|
if (derived) {
|
||||||
tm = typemapLookup("csdestruct_derived", typemap_lookup_type, WARN_NONE, attributes);
|
tm = typemapLookup("csdestruct_derived", typemap_lookup_type, WARN_NONE, attributes);
|
||||||
destruct_methodname = Getattr(attributes, "tmap:csdestruct_derived:methodname");
|
destruct_methodname = Getattr(attributes, "tmap:csdestruct_derived:methodname");
|
||||||
|
destruct_methodmodifiers = Getattr(attributes, "tmap:csdestruct_derived:methodmodifiers");
|
||||||
} else {
|
} else {
|
||||||
tm = typemapLookup("csdestruct", typemap_lookup_type, WARN_NONE, attributes);
|
tm = typemapLookup("csdestruct", typemap_lookup_type, WARN_NONE, attributes);
|
||||||
destruct_methodname = Getattr(attributes, "tmap:csdestruct:methodname");
|
destruct_methodname = Getattr(attributes, "tmap:csdestruct:methodname");
|
||||||
|
destruct_methodmodifiers = Getattr(attributes, "tmap:csdestruct:methodmodifiers");
|
||||||
}
|
}
|
||||||
if (!destruct_methodname) {
|
if (!destruct_methodname) {
|
||||||
Swig_error(input_file, line_number,
|
Swig_error(input_file, line_number,
|
||||||
"No methodname attribute defined in csdestruct%s typemap for %s\n", (derived ? "_derived" : ""), proxy_class_name);
|
"No methodname attribute defined in csdestruct%s typemap for %s\n", (derived ? "_derived" : ""), proxy_class_name);
|
||||||
}
|
}
|
||||||
|
if (!destruct_methodmodifiers) {
|
||||||
|
Swig_error(input_file, line_number,
|
||||||
|
"No methodmodifier attribute defined in csdestruct%s typemap for %s.\n", (derived ? "_derived" : ""), proxy_class_name);
|
||||||
|
}
|
||||||
|
|
||||||
// Emit the Finalize and Dispose methods
|
// Emit the Finalize and Dispose methods
|
||||||
if (tm) {
|
if (tm) {
|
||||||
|
|
@ -1569,7 +1576,7 @@ class CSHARP : public Language {
|
||||||
else
|
else
|
||||||
Replaceall(destruct, "$imcall", "throw new MethodAccessException(\"C++ destructor does not have public access\")");
|
Replaceall(destruct, "$imcall", "throw new MethodAccessException(\"C++ destructor does not have public access\")");
|
||||||
if (*Char(destruct))
|
if (*Char(destruct))
|
||||||
Printv(proxy_class_def, "\n public ", derived ? "override" : "virtual", " void ", destruct_methodname, "() ", destruct, "\n", NIL);
|
Printv(proxy_class_def, "\n ", destruct_methodmodifiers, " ", derived ? "override" : "virtual", " void ", destruct_methodname, "() ", destruct, "\n", NIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (feature_director) {
|
if (feature_director) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue