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

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFaizur Rahman <shrah@microsoft.com>2017-01-21 00:28:05 +0300
committerFaizur Rahman <shrah@microsoft.com>2017-01-21 00:57:56 +0300
commit9428dfa773914adac20bd2c7c59de2f3e32349ad (patch)
tree9deab16e48b179d820417f0d00dadec3738a29af
parent909f23ca551351e12182de173b4c2b123894ae8b (diff)
Fix PInvoke CPPCodegen
This change contains the following: 1. Fixed out SafeHandleMarshaller with CPP codegen as Sedar pointed out. 2. Also enable PInvoke test with CPP Codegen. The generic method ThrowIfNotEquals doesn't work with CPPCodegen. So temporary created overrides to address this.
-rw-r--r--src/Common/src/TypeSystem/Interop/IL/Marshaller.cs6
-rw-r--r--src/ILCompiler.Compiler/src/CppCodeGen/ILToCppImporter.cs2
-rw-r--r--tests/src/Simple/PInvoke/PInvoke.cs17
-rw-r--r--tests/src/Simple/PInvoke/no_cpp1
4 files changed, 15 insertions, 11 deletions
diff --git a/src/Common/src/TypeSystem/Interop/IL/Marshaller.cs b/src/Common/src/TypeSystem/Interop/IL/Marshaller.cs
index 7b6f5cb7d..7701bbbbb 100644
--- a/src/Common/src/TypeSystem/Interop/IL/Marshaller.cs
+++ b/src/Common/src/TypeSystem/Interop/IL/Marshaller.cs
@@ -406,14 +406,14 @@ namespace Internal.TypeSystem.Interop
TypeDesc resolvedType = ((ByRefType)managedType).ParameterType;
var nativeType = PInvokeMethodData.Context.GetWellKnownType(WellKnownType.IntPtr).MakeByRefType();
- var vPinnedOutValue = emitter.NewLocal(nativeType, true);
+ var vOutValue = emitter.NewLocal(PInvokeMethodData.Context.GetWellKnownType(WellKnownType.IntPtr));
var vSafeHandle = emitter.NewLocal(resolvedType);
marshallingCodeStream.Emit(ILOpcode.newobj, emitter.NewToken(resolvedType.GetDefaultConstructor()));
marshallingCodeStream.EmitStLoc(vSafeHandle);
- marshallingCodeStream.EmitLdLoca(vPinnedOutValue);
+ marshallingCodeStream.EmitLdLoca(vOutValue);
unmarshallingCodeStream.EmitLdLoc(vSafeHandle);
- unmarshallingCodeStream.EmitLdLoc(vPinnedOutValue);
+ unmarshallingCodeStream.EmitLdLoc(vOutValue);
unmarshallingCodeStream.Emit(ILOpcode.call, emitter.NewToken(
PInvokeMethodData.SafeHandleType.GetKnownMethod("SetHandle", null)));
diff --git a/src/ILCompiler.Compiler/src/CppCodeGen/ILToCppImporter.cs b/src/ILCompiler.Compiler/src/CppCodeGen/ILToCppImporter.cs
index 7aa132b61..b2b5d0bda 100644
--- a/src/ILCompiler.Compiler/src/CppCodeGen/ILToCppImporter.cs
+++ b/src/ILCompiler.Compiler/src/CppCodeGen/ILToCppImporter.cs
@@ -292,7 +292,7 @@ namespace Internal.IL
private void AppendCastIfNecessary(TypeDesc destType, StackEntry srcEntry)
{
ConstantEntry constant = srcEntry as ConstantEntry;
- if ((constant != null) && (constant.IsCastNecessary(destType)) || !destType.IsValueType)
+ if ((constant != null) && (constant.IsCastNecessary(destType)) || !destType.IsValueType || destType != srcEntry.Type)
{
Append("(");
Append(GetSignatureTypeNameAndAddReference(destType));
diff --git a/tests/src/Simple/PInvoke/PInvoke.cs b/tests/src/Simple/PInvoke/PInvoke.cs
index ed7f53fb1..2804cd614 100644
--- a/tests/src/Simple/PInvoke/PInvoke.cs
+++ b/tests/src/Simple/PInvoke/PInvoke.cs
@@ -8,7 +8,7 @@ using System.Text;
// Name of namespace matches the name of the assembly on purpose to
// ensure that we can handle this (mostly an issue for C++ code generation).
-namespace PInvoke
+namespace PInvokeTests
{
internal class Program
{
@@ -54,9 +54,9 @@ namespace PInvoke
return 100;
}
- public static void ThrowIfNotEquals<T>(T expected, T actual, string message)
+ public static void ThrowIfNotEquals(int expected, int actual, string message)
{
- if (!Object.Equals(expected, actual))
+ if (expected != actual)
{
message += "\nExpected: " + expected + "\n";
message += "Actual: " + actual + "\n";
@@ -64,6 +64,11 @@ namespace PInvoke
}
}
+ public static void ThrowIfNotEquals(bool expected, bool actual, string message)
+ {
+ ThrowIfNotEquals(expected ? 1 : 0, actual ? 1 : 0, message);
+ }
+
private static void TestBlittableType()
{
Console.WriteLine("Testing marshalling blittable types");
@@ -123,9 +128,9 @@ namespace PInvoke
Console.WriteLine("Testing marshalling out SafeHandle");
SafeMemoryHandle hnd2;
- val = SafeHandleOutTest(out hnd2);
- int val2 = unchecked((int)hnd2.DangerousGetHandle().ToInt64());
- ThrowIfNotEquals(val, val2, "SafeHandle out marshalling failed");
+ int actual = SafeHandleOutTest(out hnd2);
+ int expected = unchecked((int)hnd2.DangerousGetHandle().ToInt64());
+ ThrowIfNotEquals(actual, expected, "SafeHandle out marshalling failed");
}
}
diff --git a/tests/src/Simple/PInvoke/no_cpp b/tests/src/Simple/PInvoke/no_cpp
deleted file mode 100644
index 639bcaf8b..000000000
--- a/tests/src/Simple/PInvoke/no_cpp
+++ /dev/null
@@ -1 +0,0 @@
-Skip this test for cpp codegen mode