C# exception handling improvements - they are robust and don't leak anymore. Requires typemap modifications using attribute canthrow in any unmanaged code typemaps that throw an exception and excode attribute in csout and csconstruct typemaps.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6934 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
df49ff9f1e
commit
bac8f43f79
12 changed files with 288 additions and 156 deletions
|
|
@ -122,6 +122,41 @@ DllExport void SWIGSTDCALL SWIGRegisterExceptionCallbacks_$module(SWIG_CSharpExc
|
|||
}
|
||||
|
||||
static SWIGExceptionHelper exceptionHelper = new SWIGExceptionHelper();
|
||||
|
||||
[ThreadStatic]
|
||||
private static Exception pendingException = null;
|
||||
private static int numExceptionsPending = 0;
|
||||
|
||||
public static bool ExceptionPending {
|
||||
get {
|
||||
bool pending = false;
|
||||
if (numExceptionsPending > 0)
|
||||
if (pendingException != null)
|
||||
pending = true;
|
||||
return pending;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetPendingException(Exception e) {
|
||||
pendingException = e;
|
||||
lock(typeof($modulePINVOKE)) {
|
||||
numExceptionsPending++;
|
||||
}
|
||||
}
|
||||
|
||||
public static Exception RetrievePendingException() {
|
||||
Exception e = null;
|
||||
if (numExceptionsPending > 0) {
|
||||
if (pendingException != null) {
|
||||
e = pendingException;
|
||||
pendingException = null;
|
||||
lock(typeof($modulePINVOKE)) {
|
||||
numExceptionsPending--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return e;
|
||||
}
|
||||
%}
|
||||
|
||||
%insert(runtime) %{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue