Browse Source

Generate valid C# for returned const char*&

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

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

@ -146,8 +146,10 @@ namespace CppSharp.Generators.CSharp @@ -146,8 +146,10 @@ namespace CppSharp.Generators.CSharp
var pointee = pointer.Pointee.Desugar();
var finalPointee = pointer.GetFinalPointee().Desugar();
var type = Context.ReturnType.Type.Desugar(
resolveTemplateSubstitution: false);
PrimitiveType primitive;
if ((pointee.IsConstCharString() && isRefParam) ||
if ((pointee.IsConstCharString() && (isRefParam || type.IsReference())) ||
(!finalPointee.IsPrimitiveType(out primitive) &&
!finalPointee.IsEnumType()))
return pointer.QualifiedPointee.Visit(this);
@ -162,8 +164,6 @@ namespace CppSharp.Generators.CSharp @@ -162,8 +164,6 @@ namespace CppSharp.Generators.CSharp
primitive == PrimitiveType.Char)
Context.Return.Write($"({pointer}) ");
var type = Context.ReturnType.Type.Desugar(
resolveTemplateSubstitution: false);
if (Context.Function != null &&
Context.Function.OperatorKind == CXXOperatorKind.Subscript)
{

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

@ -218,9 +218,16 @@ namespace CppSharp.Types.Std @@ -218,9 +218,16 @@ namespace CppSharp.Types.Std
if (Equals(encoding, Encoding.ASCII))
encoding = Context.Options.Encoding;
string returnVarName = ctx.Function != null &&
ctx.Function.ReturnType.Type.Desugar().IsAddress() ?
$"(global::System.IntPtr) {ctx.ReturnVarName}" : ctx.ReturnVarName;
string returnVarName = ctx.ReturnVarName;
if (ctx.Function != null)
{
Type returnType = ctx.Function.ReturnType.Type.Desugar();
if (returnType.IsAddress() &&
returnType.GetPointee().Desugar().IsAddress())
{
returnVarName = $"new global::System.IntPtr(*{returnVarName})";
}
}
if (Equals(encoding, Encoding.ASCII))
{

2
tests/CSharp/CSharp.cpp

@ -1560,7 +1560,7 @@ char* returnCharPointer() @@ -1560,7 +1560,7 @@ char* returnCharPointer()
return 0;
}
const char* takeConstCharStarRef(const char*& c)
const char*& takeConstCharStarRef(const char*& c)
{
return c;
}

2
tests/CSharp/CSharp.h

@ -1305,7 +1305,7 @@ public: @@ -1305,7 +1305,7 @@ public:
DLL_API void va_listFunction(va_list v);
DLL_API char* returnCharPointer();
DLL_API const char* takeConstCharStarRef(const char*& c);
DLL_API const char*& takeConstCharStarRef(const char*& c);
struct {
struct {

Loading…
Cancel
Save