Skip to content

Commit 00528a1

Browse files
committed
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
1 parent d674637 commit 00528a1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

CHANGES.current

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
77
Version 4.0.0 (in progress)
88
===========================
99

10+
2019-04-09: wsfulton
11+
[C#] Fix FxCop warning CA2002 in SWIGPendingException - a lock on a reference of
12+
type 'Type'.
13+
1014
2019-03-30: wsfulton
1115
[Java, D] Add the parameters typemap attribute to the javadestruct,
1216
javadestruct_derived, ddispose, ddispose_derived typemaps to mirror enhanced

Lib/csharp/csharphead.swg

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module(
244244
[global::System.ThreadStatic]
245245
private static global::System.Exception pendingException = null;
246246
private static int numExceptionsPending = 0;
247+
private static global::System.Object exceptionsLock = null;
247248

248249
public static bool Pending {
249250
get {
@@ -259,7 +260,7 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module(
259260
if (pendingException != null)
260261
throw new global::System.ApplicationException("FATAL: An earlier pending exception from unmanaged code was missed and thus not thrown (" + pendingException.ToString() + ")", e);
261262
pendingException = e;
262-
lock(typeof($imclassname)) {
263+
lock(exceptionsLock) {
263264
numExceptionsPending++;
264265
}
265266
}
@@ -270,13 +271,17 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module(
270271
if (pendingException != null) {
271272
e = pendingException;
272273
pendingException = null;
273-
lock(typeof($imclassname)) {
274+
lock(exceptionsLock) {
274275
numExceptionsPending--;
275276
}
276277
}
277278
}
278279
return e;
279280
}
281+
282+
static SWIGPendingException() {
283+
exceptionsLock = new global::System.Object();
284+
}
280285
}
281286
%}
282287
#endif // SWIG_CSHARP_NO_EXCEPTION_HELPER

0 commit comments

Comments
 (0)