Fix C# wrappers FxCop warning CA2002 in SWIGPendingException

Fixes two warnings in each wrapper:

warning  : CA2002 : Microsoft.Reliability : 'examplePINVOKE.SWIGPendingException.Retrieve()' locks on a reference of type 'Type'. Replace this with a lock against an object with strong-identity.

warning  : CA2002 : Microsoft.Reliability : 'examplePINVOKE.SWIGPendingException.Set(Exception)' locks on a reference of type 'Type'. Replace this with a lock against an object with strong-identity.

Use lock statement advice not to use typeof for locks, see
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/lock-statement
This commit is contained in:
William S Fulton 2019-04-09 19:15:12 +01:00
commit 00528a1ef6
2 changed files with 11 additions and 2 deletions

View file

@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.0.0 (in progress)
===========================
2019-04-09: wsfulton
[C#] Fix FxCop warning CA2002 in SWIGPendingException - a lock on a reference of
type 'Type'.
2019-03-30: wsfulton
[Java, D] Add the parameters typemap attribute to the javadestruct,
javadestruct_derived, ddispose, ddispose_derived typemaps to mirror enhanced

View file

@ -244,6 +244,7 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module(
[global::System.ThreadStatic]
private static global::System.Exception pendingException = null;
private static int numExceptionsPending = 0;
private static global::System.Object exceptionsLock = null;
public static bool Pending {
get {
@ -259,7 +260,7 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module(
if (pendingException != null)
throw new global::System.ApplicationException("FATAL: An earlier pending exception from unmanaged code was missed and thus not thrown (" + pendingException.ToString() + ")", e);
pendingException = e;
lock(typeof($imclassname)) {
lock(exceptionsLock) {
numExceptionsPending++;
}
}
@ -270,13 +271,17 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module(
if (pendingException != null) {
e = pendingException;
pendingException = null;
lock(typeof($imclassname)) {
lock(exceptionsLock) {
numExceptionsPending--;
}
}
}
return e;
}
static SWIGPendingException() {
exceptionsLock = new global::System.Object();
}
}
%}
#endif // SWIG_CSHARP_NO_EXCEPTION_HELPER