Browse Source

Generate valid C# for returned const void pointers

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1213/head
Dimitar Dobrev 6 years ago
parent
commit
458293edfc
  1. 7
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 4
      tests/CSharp/CSharp.Tests.cs
  3. 3
      tests/CSharp/CSharp.cpp
  4. 2
      tests/CSharp/CSharp.h

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

@ -182,7 +182,14 @@ namespace CppSharp.Generators.CSharp @@ -182,7 +182,14 @@ namespace CppSharp.Generators.CSharp
}
if (new QualifiedType(pointer, quals).IsConstRefToPrimitive())
{
if (finalPointee.IsPrimitiveType(PrimitiveType.Void))
{
Context.Return.Write($"new {typePrinter.IntPtrType}(*{Context.ReturnVarName})");
return true;
}
Context.Return.Write("*");
}
Context.Return.Write(Context.ReturnVarName);
return true;

4
tests/CSharp/CSharp.Tests.cs

@ -95,7 +95,9 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -95,7 +95,9 @@ public unsafe class CSharpTests : GeneratorTestFixture
}
CSharp.CSharp.ReturnCharPointer();
CSharp.CSharp.RValueReferenceToPointer(null);
int value = 5;
IntPtr intPtr = CSharp.CSharp.RValueReferenceToPointer((void**) &value);
Assert.That((int) intPtr, Is.EqualTo(value));
#pragma warning restore 0168
#pragma warning restore 0219

3
tests/CSharp/CSharp.cpp

@ -1565,8 +1565,9 @@ const char*& takeConstCharStarRef(const char*& c) @@ -1565,8 +1565,9 @@ const char*& takeConstCharStarRef(const char*& c)
return c;
}
void rValueReferenceToPointer(void*&& v)
const void*& rValueReferenceToPointer(void*&& v)
{
return (const void*&) v;
}
boolean_t takeTypemapTypedefParam(boolean_t b)

2
tests/CSharp/CSharp.h

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

Loading…
Cancel
Save