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 01:48:51 +0300
committerGitHub <noreply@github.com>2017-01-21 01:48:51 +0300
commit56a82fa2f0784762adc44ce290afac6326a1018f (patch)
tree81db1f946fd9156acd765266d112e27a528c5f9e
parent354d0fae2a78ac8b183f8ac4662618918e8d57a3 (diff)
parent9428dfa773914adac20bd2c7c59de2f3e32349ad (diff)
Merge pull request #2554 from shrah/master
Fix PInvoke CPPCodegen
-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