Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElinor Fung <elfung@microsoft.com>2021-04-24 03:16:02 +0300
committerGitHub <noreply@github.com>2021-04-24 03:16:02 +0300
commit842956952e12361390ad92960b6124738500272a (patch)
tree2483a9e903ca4c36be01498ca03cbec030401a56
parent59aa9c7d37cb3c12d34017918116c495b0fdc7ff (diff)
Rename MarshalEx.SetLastWin32Error -> SetLastPInvokeError (dotnet/runtimelab#1007)
Commit migrated from https://github.com/dotnet/runtimelab/commit/82735dd0fef4886ae2f0886267ef30822e17ee8a
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/StubCodeGenerator.cs4
-rw-r--r--src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/MarshalEx.cs10
-rw-r--r--src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/SetLastErrorTests.cs10
3 files changed, 15 insertions, 9 deletions
diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/StubCodeGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/StubCodeGenerator.cs
index 4a5f15ede8d..343f767a0b8 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/StubCodeGenerator.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/StubCodeGenerator.cs
@@ -321,13 +321,13 @@ namespace Microsoft.Interop
if (this.dllImportData.SetLastError && !options.GenerateForwarders())
{
- // Marshal.SetLastWin32Error(<lastError>);
+ // Marshal.SetLastPInvokeError(<lastError>);
allStatements.Add(ExpressionStatement(
InvocationExpression(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
ParseName(TypeNames.MarshalEx(options)),
- IdentifierName("SetLastWin32Error")),
+ IdentifierName("SetLastPInvokeError")),
ArgumentList(SingletonSeparatedList(
Argument(IdentifierName(LastErrorIdentifier)))))));
}
diff --git a/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/MarshalEx.cs b/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/MarshalEx.cs
index 8a53af07090..716dcf28eec 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/MarshalEx.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/MarshalEx.cs
@@ -23,9 +23,15 @@ namespace System.Runtime.InteropServices
/// <summary>
/// Set the last platform invoke error on the thread
/// </summary>
- public static void SetLastWin32Error(int error)
+ public static void SetLastPInvokeError(int error)
{
- typeof(Marshal).GetMethod("SetLastWin32Error", BindingFlags.NonPublic | BindingFlags.Static)!.Invoke(null, new object[] { error });
+ MethodInfo? method = typeof(Marshal).GetMethod("SetLastWin32Error", BindingFlags.NonPublic | BindingFlags.Static);
+ if (method == null)
+ {
+ method = typeof(Marshal).GetMethod("SetLastPInvokeError", BindingFlags.Public | BindingFlags.Static);
+ }
+
+ method!.Invoke(null, new object[] { error });
}
/// <summary>
diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/SetLastErrorTests.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/SetLastErrorTests.cs
index 45407ce0222..04542c7f8f4 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/SetLastErrorTests.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/SetLastErrorTests.cs
@@ -18,7 +18,7 @@ namespace DllImportGenerator.IntegrationTests
public int ToManaged()
{
// Explicity set the last error to something else on unmarshalling
- MarshalEx.SetLastWin32Error(val * 2);
+ MarshalEx.SetLastPInvokeError(val * 2);
return val;
}
}
@@ -54,12 +54,12 @@ namespace DllImportGenerator.IntegrationTests
Assert.Equal(errorString, ret);
// Clear the last error
- MarshalEx.SetLastWin32Error(0);
+ MarshalEx.SetLastPInvokeError(0);
NativeExportsNE.SetLastError.SetError(error, shouldSetError: 1);
Assert.Equal(error, Marshal.GetLastWin32Error());
- MarshalEx.SetLastWin32Error(0);
+ MarshalEx.SetLastPInvokeError(0);
// Custom marshalling sets the last error on unmarshalling.
// Last error should reflect error from native call, not unmarshalling.
@@ -71,7 +71,7 @@ namespace DllImportGenerator.IntegrationTests
public void ClearPreviousError()
{
int error = 100;
- MarshalEx.SetLastWin32Error(error);
+ MarshalEx.SetLastPInvokeError(error);
// Don't actually set the error in the native call. SetLastError=true should clear any existing error.
string errorString = error.ToString();
@@ -79,7 +79,7 @@ namespace DllImportGenerator.IntegrationTests
Assert.Equal(0, Marshal.GetLastWin32Error());
Assert.Equal(errorString, ret);
- MarshalEx.SetLastWin32Error(error);
+ MarshalEx.SetLastPInvokeError(error);
// Don't actually set the error in the native call. SetLastError=true should clear any existing error.
NativeExportsNE.SetLastError.SetError(error, shouldSetError: 0);