Browse Source

Fix the generated C# for const char*&

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1204/head
Dimitar Dobrev 6 years ago
parent
commit
d5380fe890
  1. 11
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 1
      src/Generator/Types/Std/Stdlib.cs
  3. 6
      tests/CSharp/CSharp.Tests.cs
  4. 5
      tests/CSharp/CSharp.cpp
  5. 3
      tests/CSharp/CSharp.cs
  6. 1
      tests/CSharp/CSharp.h

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

@ -499,7 +499,7 @@ namespace CppSharp.Generators.CSharp @@ -499,7 +499,7 @@ namespace CppSharp.Generators.CSharp
var isRefParam = param != null && (param.IsInOut || param.IsOut);
var pointee = pointer.Pointee.Desugar();
if (pointee.IsConstCharString() && isRefParam)
if (pointee.IsConstCharString())
{
if (param.IsOut)
{
@ -513,13 +513,16 @@ namespace CppSharp.Generators.CSharp @@ -513,13 +513,16 @@ namespace CppSharp.Generators.CSharp
MarshalString(pointee);
pointer.QualifiedPointee.Visit(this);
Context.ArgumentPrefix.Write("&");
return true;
}
else
if (pointer.IsReference)
{
Context.Return.Write($@"({typePrinter.PrintNative(
pointee.GetQualifiedPointee())}*) ");
pointer.QualifiedPointee.Visit(this);
Context.Cleanup.WriteLine($"Marshal.FreeHGlobal({Context.ArgName});");
Context.ArgumentPrefix.Write("&");
return true;
}
return true;
}
var finalPointee = (pointee.GetFinalPointee() ?? pointee).Desugar();

1
src/Generator/Types/Std/Stdlib.cs

@ -168,6 +168,7 @@ namespace CppSharp.Types.Std @@ -168,6 +168,7 @@ namespace CppSharp.Types.Std
public override void CSharpMarshalToNative(CSharpMarshalContext ctx)
{
if (ctx.Parameter.Usage == ParameterUsage.Unknown &&
!ctx.Parameter.Type.IsReference() &&
ctx.MarshalKind != MarshalKind.NativeField &&
ctx.MarshalKind != MarshalKind.VTableReturnValue &&
ctx.MarshalKind != MarshalKind.Variable)

6
tests/CSharp/CSharp.Tests.cs

@ -1255,6 +1255,12 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -1255,6 +1255,12 @@ public unsafe class CSharpTests : GeneratorTestFixture
}
}
[Test]
public void TestConstCharStarRef()
{
Assert.That(CSharp.CSharp.TakeConstCharStarRef("Test"), Is.EqualTo("Test"));
}
public class Inter : SimpleInterface
{
public override int Size => s;

5
tests/CSharp/CSharp.cpp

@ -1551,3 +1551,8 @@ char* returnCharPointer() @@ -1551,3 +1551,8 @@ char* returnCharPointer()
{
return 0;
}
const char* takeConstCharStarRef(const char*& c)
{
return c;
}

3
tests/CSharp/CSharp.cs

@ -259,7 +259,8 @@ namespace CppSharp.Tests @@ -259,7 +259,8 @@ namespace CppSharp.Tests
public override void CSharpMarshalToNative(CSharpMarshalContext ctx)
{
ctx.Return.Write("\"test\"");
ctx.Return.Write(ctx.Parameter.Type.Desugar().IsAddress() ?
"global::System.IntPtr.Zero" : "\"test\"");
}
public override void CSharpMarshalToManaged(CSharpMarshalContext ctx)

1
tests/CSharp/CSharp.h

@ -1297,3 +1297,4 @@ private: @@ -1297,3 +1297,4 @@ private:
DLL_API void va_listFunction(va_list v);
DLL_API char* returnCharPointer();
DLL_API const char* takeConstCharStarRef(const char*& c);

Loading…
Cancel
Save