Skip to content

Instantly share code, notes, and snippets.

@genuinelucifer
Last active August 29, 2015 14:21
Show Gist options
  • Save genuinelucifer/5f704ee5b4ea18ac2753 to your computer and use it in GitHub Desktop.
Save genuinelucifer/5f704ee5b4ea18ac2753 to your computer and use it in GitHub Desktop.
diff --git a/src/Generator/Generators/CLI/CLIMarshal.cs b/src/Generator/Generato
index eb00737..bc6da59 100644
--- a/src/Generator/Generators/CLI/CLIMarshal.cs
+++ b/src/Generator/Generators/CLI/CLIMarshal.cs
@@ -40,13 +40,16 @@ public override bool VisitTagType(TagType tag, TypeQualifier
return decl.Visit(this);
}
+ private static int _arrayNum = 0;
public override bool VisitArrayType(ArrayType array, TypeQualifiers qua
{
switch (array.SizeType)
{
case ArrayType.ArraySize.Constant:
var supportBefore = Context.SupportBefore;
- string value = Generator.GeneratedIdentifier("array");
+ string value = Generator.GeneratedIdentifier("array")
+ + _arrayNum;
+ ++_arrayNum;
supportBefore.WriteLine("cli::array<{0}>^ {1} = nullptr;",
supportBefore.WriteLine("if ({0} != 0)", Context.ReturnVarN
supportBefore.WriteStartBraceIndent();
diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generat
index ef0a242..c878935 100644
--- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs
+++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs
@@ -845,12 +845,29 @@ private void GeneratePropertySetter<T>(QualifiedType retur
WriteStartBraceIndent();
var marshal = new CSharpMarshalManagedToNativePrinter(ctx);
- ctx.ReturnVarName = string.Format("{0}{1}{2}",
+
+ var arrayType = field.Type as ArrayType;
+
+ if(arrayType!=null && @class.IsValueType==true)
+ {
+ CSharpTypePrinter _ctp = new CSharpTypePrinter(ctx.Driver);
+ string type = arrayType.CSharpType(_ctp).Type;
+ WriteLine(string.Format("fixed ({0} __arrPtr = {1}.{2})",
+ type.Replace("[]","*"), Helpers.InstanceField,
+ Helpers.SafeIdentifier(field.OriginalName)));
+ WriteStartBraceIndent();
+ ctx.ReturnVarName = string.Format("__arrPtr");
+ }
+ else
+ {
+ ctx.ReturnVarName = string.Format("{0}{1}{2}",
@class.IsValueType
? Helpers.InstanceField
: string.Format("((Internal*) {0})", Helpers.InstanceId
@class.IsValueType ? "." : "->",
Helpers.SafeIdentifier(field.OriginalName));
+ }
+
param.Visit(marshal);
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))
@@ -861,6 +878,11 @@ private void GeneratePropertySetter<T>(QualifiedType return
WriteLine("{0} = {1};", ctx.ReturnVarName, marshal.Context.
}
+ if (arrayType != null && @class.IsValueType == true)
+ {
+ WriteCloseBraceIndent();
+ }
+
WriteCloseBraceIndent();
}
@@ -951,6 +973,19 @@ private void GeneratePropertyGetter<T>(QualifiedType return
ReturnType = decl.QualifiedType
};
+ var arrayType = field.Type as ArrayType;
+
+ if (arrayType != null && @class.IsValueType == true)
+ {
+ CSharpTypePrinter _ctp = new CSharpTypePrinter(ctx.Driver);
+ string type = arrayType.CSharpType(_ctp).Type;
+ WriteLine(string.Format("fixed ({0} __arrPtr = {1}.{2})",
+ type.Replace("[]", "*"), Helpers.InstanceField,
+ Helpers.SafeIdentifier(field.OriginalName)));
+ WriteStartBraceIndent();
+ ctx.ReturnVarName = string.Format("__arrPtr");
+ }
+
var marshal = new CSharpMarshalNativeToManagedPrinter(ctx);
decl.CSharpMarshalToManaged(marshal);
@@ -958,6 +993,14 @@ private void GeneratePropertyGetter<T>(QualifiedType return
Write(marshal.Context.SupportBefore);
WriteLine("return {0};", marshal.Context.Return);
+
+
+ if (arrayType != null && @class.IsValueType == true)
+ {
+ WriteCloseBraceIndent();
+ }
+
+
}
else if (decl is Variable)
{
diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h
index 488dd2c..baf923f 100644
--- a/tests/Basic/Basic.h
+++ b/tests/Basic/Basic.h
@@ -710,3 +710,13 @@ public:
bool operator ==(const DifferentConstOverloads& other);
bool operator ==(int number) const;
};
+
+#define ARRAY_LENGTH 5
+#define CS_VALUE_TYPE
+struct CS_VALUE_TYPE ValueTypeArrays
+{
+ float firstValueTypeArrray[ARRAY_LENGTH];
+ int secondValueTypeArray[ARRAY_LENGTH];
+ char thirdValueTypeArray[ARRAY_LENGTH];
+ size_t size;
+};
(END)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment