Skip to content

Commit

Permalink
Generate valid C++/CLI for passed primitive refs
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar Dobrev <[email protected]>
  • Loading branch information
Build Agent authored and ddobrev committed Apr 15, 2020
1 parent 64b1efd commit 1610aa5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/Generator/Generators/CLI/CLISources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,12 +1177,6 @@ public struct ParamMarshal
// tracking references when using in/out, we normalize them here to be able
// to use the same code for marshaling.
var paramType = param.Type;
if (paramType is PointerType && isRef)
{
if (!paramType.IsReference())
paramMarshal.Prefix = "&";
paramType = (paramType as PointerType).Pointee;
}

var effectiveParam = new Parameter(param)
{
Expand All @@ -1196,7 +1190,10 @@ public struct ParamMarshal
ArgName = argName,
Function = function
};
if (true)
{

}
var marshal = new CLIMarshalManagedToNativePrinter(ctx);
effectiveParam.Visit(marshal);

Expand Down
8 changes: 8 additions & 0 deletions tests/Common/Common.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,14 @@ public void TestUTF8()
}
}

[Test]
public void TestPointerToPrimitiveTypedefPointerTestMethod()
{
int a = 50;
Common.PointerToPrimitiveTypedefPointerTestMethod(ref a, 100);
Assert.AreEqual(100, a);
}

private class CustomDerivedFromVirtual : AbstractWithVirtualDtor
{
public override void Abstract()
Expand Down
5 changes: 5 additions & 0 deletions tests/Common/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,11 @@ LPCSTR TakeTypedefedMappedType(LPCSTR string)
return UTF8.data();
}

void DLL_API PointerToPrimitiveTypedefPointerTestMethod(LPLONG lp, int valToSet)
{
*lp = valToSet;
}

StructWithCopyCtor::StructWithCopyCtor() {}
StructWithCopyCtor::StructWithCopyCtor(const StructWithCopyCtor& other) : mBits(other.mBits) {}

Expand Down
2 changes: 2 additions & 0 deletions tests/Common/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,8 @@ DLL_API void overloadPointer(const void* p, int i = 0);
DLL_API const char* takeReturnUTF8(const char* utf8);
typedef const char* LPCSTR;
DLL_API LPCSTR TakeTypedefedMappedType(LPCSTR string);
typedef int* LPLONG;
void DLL_API PointerToPrimitiveTypedefPointerTestMethod(LPLONG lp, int valToSet);
DLL_API std::string UTF8;

struct DLL_API StructWithCopyCtor
Expand Down

0 comments on commit 1610aa5

Please sign in to comment.