Skip to content

Commit

Permalink
Add a generic pointer to resolve ambiguity
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information
ddobrev committed Apr 10, 2019
1 parent c75e9f6 commit 304d673
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
3 changes: 1 addition & 2 deletions build/Tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,10 @@ function SetupTestProjectsCSharp(name, depends, extraFiles, suffix)
files { name .. ".Tests.cs" }
vpaths { ["*"] = "*" }

links { name .. ".CSharp", "CppSharp.Generator.Tests" }
links { name .. ".CSharp", "CppSharp.Generator.Tests", "CppSharp.Runtime" }
dependson { name .. ".Native" }

LinkNUnit()
links { "CppSharp.Runtime" }

filter { "action:netcore" }
dotnetframework "netcoreapp2.0"
Expand Down
10 changes: 7 additions & 3 deletions src/Generator/Generators/CSharp/CSharpTypePrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,13 @@ public TypePrinterResult VisitTemplateArgument(TemplateArgument a)
if (a.Type.Type == null)
return a.Integral.ToString(CultureInfo.InvariantCulture);
var type = a.Type.Type.Desugar();
return type.IsPointerToPrimitiveType() && !type.IsConstCharString() ?
IntPtrType : type.IsPrimitiveType(PrimitiveType.Void) ? "object" :
type.Visit(this).Type;
PrimitiveType pointee;
if (type.IsPointerToPrimitiveType(out pointee) && !type.IsConstCharString())
{
return $@"CppSharp.Runtime.Pointer<{(pointee == PrimitiveType.Void ? IntPtrType :
VisitPrimitiveType(pointee, new TypeQualifiers()).Type)}>";
}
return (type.IsPrimitiveType(PrimitiveType.Void)) ? "object" : type.Visit(this).Type;
}

public override TypePrinterResult VisitParameterDecl(Parameter parameter)
Expand Down
13 changes: 13 additions & 0 deletions src/Runtime/Pointer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace CppSharp.Runtime
{
public class Pointer<T>
{
public Pointer(IntPtr ptr) => this.ptr = ptr;

public static implicit operator IntPtr(Pointer<T> pointer) => pointer.ptr;

private readonly IntPtr ptr;
}
}

0 comments on commit 304d673

Please sign in to comment.