Browse Source

Fix regressed indexers in templates with non-trivial ctors

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
bug-pass-const-char-star-no-copy
Dimitar Dobrev 7 years ago
parent
commit
e430f6f8dc
  1. 3
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 22
      src/Generator/Generators/CSharp/CSharpSources.cs

3
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -711,7 +711,8 @@ namespace CppSharp.Generators.CSharp @@ -711,7 +711,8 @@ namespace CppSharp.Generators.CSharp
Context.Parameter.Name}"", ""Cannot be null because it is passed by value."");");
var realClass = @class.OriginalClass ?? @class;
var qualifiedIdentifier = typePrinter.PrintNative(realClass);
Context.Return.Write($"*({qualifiedIdentifier}*) {paramInstance}");
Context.ArgumentPrefix.Write($"*({qualifiedIdentifier}*) ");
Context.Return.Write(paramInstance);
return;
}

22
src/Generator/Generators/CSharp/CSharpSources.cs

@ -876,7 +876,8 @@ namespace CppSharp.Generators.CSharp @@ -876,7 +876,8 @@ namespace CppSharp.Generators.CSharp
if (ctx.HasCodeBlock)
Indent();
WriteLine($"*{ptr} = {marshal.Context.Return};", marshal.Context.Return);
WriteLine($@"*{ptr} = {marshal.Context.ArgumentPrefix}{
marshal.Context.Return};", marshal.Context.Return);
if (ctx.HasCodeBlock)
UnindentAndWriteCloseBrace();
@ -974,7 +975,7 @@ namespace CppSharp.Generators.CSharp @@ -974,7 +975,7 @@ namespace CppSharp.Generators.CSharp
Write("(object) ");
}
}
WriteLine($"{marshal.Context.Return};");
WriteLine($"{marshal.Context.ArgumentPrefix}{marshal.Context.Return};");
}
if ((arrayType != null && @class.IsValueType) || ctx.HasCodeBlock)
@ -1049,7 +1050,7 @@ namespace CppSharp.Generators.CSharp @@ -1049,7 +1050,7 @@ namespace CppSharp.Generators.CSharp
GetInstanceParam(function)}, {paramMarshal.Context.ArgumentPrefix}{paramMarshal.Name})";
if (type.IsPrimitiveType())
{
WriteLine($"*{call} = {marshal.Context.Return};");
WriteLine($"*{call} = {marshal.Context.ArgumentPrefix}{marshal.Context.Return};");
}
else
{
@ -1057,13 +1058,13 @@ namespace CppSharp.Generators.CSharp @@ -1057,13 +1058,13 @@ namespace CppSharp.Generators.CSharp
if (type.TryGetClass(out @class) && @class.HasNonTrivialCopyConstructor)
{
Method cctor = @class.Methods.First(c => c.IsCopyConstructor);
WriteLine($@"{@class.Visit(TypePrinter)}.{Helpers.InternalStruct}.{
GetFunctionNativeIdentifier(cctor)}({call}, {
ctx.Parameter.Name}.{Helpers.InstanceIdentifier});");
WriteLine($@"{TypePrinter.PrintNative(type)}.{
GetFunctionNativeIdentifier(cctor)}({call}, {marshal.Context.Return});");
}
else
{
WriteLine($"*({TypePrinter.PrintNative(type)}*) {call} = {marshal.Context.Return};");
WriteLine($@"*({TypePrinter.PrintNative(type)}*) {call} = {
marshal.Context.ArgumentPrefix}{marshal.Context.Return};");
}
}
}
@ -1790,13 +1791,12 @@ namespace CppSharp.Generators.CSharp @@ -1790,13 +1791,12 @@ namespace CppSharp.Generators.CSharp
if (method.HasIndirectReturnTypeParameter)
{
var retParam = method.Parameters.First(p => p.Kind == ParameterKind.IndirectReturnType);
WriteLine("*({0}*) {1} = {2};",
TypePrinter.PrintNative(method.OriginalReturnType),
retParam.Name, marshal.Context.Return);
WriteLine($@"*({TypePrinter.PrintNative(method.OriginalReturnType)}*) {
retParam.Name} = {marshal.Context.ArgumentPrefix}{marshal.Context.Return};");
}
else
{
WriteLine("return {0};", marshal.Context.Return);
WriteLine($"return {marshal.Context.ArgumentPrefix}{marshal.Context.Return};");
}
}

Loading…
Cancel
Save