Skip to content

Commit 304d673

Browse files
committed
Add a generic pointer to resolve ambiguity
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent c75e9f6 commit 304d673

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

build/Tests.lua

+1-2
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,10 @@ function SetupTestProjectsCSharp(name, depends, extraFiles, suffix)
185185
files { name .. ".Tests.cs" }
186186
vpaths { ["*"] = "*" }
187187

188-
links { name .. ".CSharp", "CppSharp.Generator.Tests" }
188+
links { name .. ".CSharp", "CppSharp.Generator.Tests", "CppSharp.Runtime" }
189189
dependson { name .. ".Native" }
190190

191191
LinkNUnit()
192-
links { "CppSharp.Runtime" }
193192

194193
filter { "action:netcore" }
195194
dotnetframework "netcoreapp2.0"

src/Generator/Generators/CSharp/CSharpTypePrinter.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,13 @@ public TypePrinterResult VisitTemplateArgument(TemplateArgument a)
561561
if (a.Type.Type == null)
562562
return a.Integral.ToString(CultureInfo.InvariantCulture);
563563
var type = a.Type.Type.Desugar();
564-
return type.IsPointerToPrimitiveType() && !type.IsConstCharString() ?
565-
IntPtrType : type.IsPrimitiveType(PrimitiveType.Void) ? "object" :
566-
type.Visit(this).Type;
564+
PrimitiveType pointee;
565+
if (type.IsPointerToPrimitiveType(out pointee) && !type.IsConstCharString())
566+
{
567+
return $@"CppSharp.Runtime.Pointer<{(pointee == PrimitiveType.Void ? IntPtrType :
568+
VisitPrimitiveType(pointee, new TypeQualifiers()).Type)}>";
569+
}
570+
return (type.IsPrimitiveType(PrimitiveType.Void)) ? "object" : type.Visit(this).Type;
567571
}
568572

569573
public override TypePrinterResult VisitParameterDecl(Parameter parameter)

src/Runtime/Pointer.cs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace CppSharp.Runtime
4+
{
5+
public class Pointer<T>
6+
{
7+
public Pointer(IntPtr ptr) => this.ptr = ptr;
8+
9+
public static implicit operator IntPtr(Pointer<T> pointer) => pointer.ptr;
10+
11+
private readonly IntPtr ptr;
12+
}
13+
}

0 commit comments

Comments
 (0)