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
Context.Parameter.Name}"", ""Cannot be null because it is passed by value."");"); Context.Parameter.Name}"", ""Cannot be null because it is passed by value."");");
var realClass = @class.OriginalClass ?? @class; var realClass = @class.OriginalClass ?? @class;
var qualifiedIdentifier = typePrinter.PrintNative(realClass); var qualifiedIdentifier = typePrinter.PrintNative(realClass);
Context.Return.Write($"*({qualifiedIdentifier}*) {paramInstance}"); Context.ArgumentPrefix.Write($"*({qualifiedIdentifier}*) ");
Context.Return.Write(paramInstance);
return; return;
} }

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

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

Loading…
Cancel
Save