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 a1559de
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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 a1559de

Please sign in to comment.