Fixed code generation for marshaling of reference types in arrays.
This commit is contained in:
Родитель
fc77d1b3e1
Коммит
a34eb2a372
|
@ -98,8 +98,11 @@ namespace MonoManagedToNative.Generators
|
|||
var elementId = CGenerator.GenId(string.Format("{0}_array_element",
|
||||
Context.ArgName));
|
||||
|
||||
support.WriteLine("char* {0} = mono_array_addr_with_size({1}, {2}, {3});",
|
||||
elementId, arrayId, elementSizeId, iteratorId);
|
||||
var isValueType = CMarshalNativeToManaged.IsValueType(array.Array.Type);
|
||||
support.WriteLine("{5} {0} = {4}mono_array_addr_with_size({1}, {2}, {3});",
|
||||
elementId, arrayId, elementSizeId, iteratorId,
|
||||
isValueType ? string.Empty : "*(MonoObject**)",
|
||||
isValueType ? "char*" : "MonoObject*");
|
||||
|
||||
var ctx = new MarshalContext(Context.Context)
|
||||
{
|
||||
|
|
|
@ -55,9 +55,15 @@ TEST_CASE("EnumTypes", "[EnumTypes]") {
|
|||
}
|
||||
|
||||
TEST_CASE("ArrayTypes", "[ArrayTypes]") {
|
||||
_IntArray array = ArrayTypes_ReturnsIntArray();
|
||||
REQUIRE(array.array->len == 3);
|
||||
REQUIRE(g_array_index(array.array, int, 0) == 1);
|
||||
REQUIRE(g_array_index(array.array, int, 1) == 2);
|
||||
REQUIRE(g_array_index(array.array, int, 2) == 3);
|
||||
_IntArray _int = ArrayTypes_ReturnsIntArray();
|
||||
REQUIRE(_int.array->len == 3);
|
||||
REQUIRE(g_array_index(_int.array, int, 0) == 1);
|
||||
REQUIRE(g_array_index(_int.array, int, 1) == 2);
|
||||
REQUIRE(g_array_index(_int.array, int, 2) == 3);
|
||||
|
||||
_CharArray _string = ArrayTypes_ReturnsStringArray();
|
||||
REQUIRE(_string.array->len == 3);
|
||||
REQUIRE(strcmp(g_array_index(_string.array, gchar*, 0), "1") == 0);
|
||||
REQUIRE(strcmp(g_array_index(_string.array, gchar*, 1), "2") == 0);
|
||||
REQUIRE(strcmp(g_array_index(_string.array, gchar*, 2), "3") == 0);
|
||||
}
|
||||
|
|
|
@ -38,6 +38,9 @@ public class BuiltinTypes
|
|||
public static class ArrayTypes
|
||||
{
|
||||
public static int[] ReturnsIntArray() { return new int[] { 1, 2, 3 }; }
|
||||
|
||||
public static string[] ReturnsStringArray() { return new string[] { "1", "2", "3" }; }
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
Загрузка…
Ссылка в новой задаче