diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2019-04-09 19:15:12 +0100 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2019-04-09 19:35:00 +0100 |
commit | 00528a1ef68dc2adbe3c34c23e9841a0715c428b (patch) | |
tree | 0274b44769f7a3de0c43feebd792ab24a53f0ea4 | |
parent | d6746379a1d63b9c588d9642cd1d0d6608629e20 (diff) | |
download | swig-00528a1ef68dc2adbe3c34c23e9841a0715c428b.tar.gz |
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
-rw-r--r-- | CHANGES.current | 4 | ||||
-rw-r--r-- | Lib/csharp/csharphead.swg | 9 |
2 files changed, 11 insertions, 2 deletions
diff --git a/CHANGES.current b/CHANGES.current index 9e4b02d4d..6529ac87d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -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 diff --git a/Lib/csharp/csharphead.swg b/Lib/csharp/csharphead.swg index 0b55635b3..7db4c0e3c 100644 --- a/Lib/csharp/csharphead.swg +++ b/Lib/csharp/csharphead.swg @@ -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 |