Browse Source

Marshal pointer to primitive typedefs in C++/CLI (#1355)

Co-authored-by: Build Agent <admin@sage.com>
pull/1358/head
Ali Alamiri 6 years ago committed by GitHub
parent
commit
c23ef39bca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/Generator/Generators/CLI/CLISources.cs
  2. 8
      tests/Common/Common.Tests.cs
  3. 5
      tests/Common/Common.cpp
  4. 4
      tests/Common/Common.h

15
src/Generator/Generators/CLI/CLISources.cs

@ -1173,10 +1173,23 @@ namespace CppSharp.Generators.CLI @@ -1173,10 +1173,23 @@ namespace CppSharp.Generators.CLI
var argName = Generator.GeneratedIdentifier("arg") + paramIndex.ToString(CultureInfo.InvariantCulture);
var isRef = param.IsOut || param.IsInOut;
var paramType = param.Type;
// Get actual type if the param type is a typedef but not a function type because function types have to be typedef.
// We need to get the actual type this early before we visit any marshalling code to ensure we hit the marshalling
// logic for the actual type and not the typedef.
// This fixes issues where typedefs to primitive pointers are involved.
FunctionType functionType;
var paramTypeAsTypedef = paramType as TypedefType;
if (paramTypeAsTypedef != null && !paramTypeAsTypedef.Declaration.Type.IsPointerTo(out functionType))
{
paramType = param.Type.Desugar();
}
// Since both pointers and references to types are wrapped as CLI
// 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())

8
tests/Common/Common.Tests.cs

@ -1095,4 +1095,12 @@ This is a very long string. This is a very long string. This is a very long stri @@ -1095,4 +1095,12 @@ This is a very long string. This is a very long string. This is a very long stri
const string @string = "string";
Assert.That(Common.TakeTypedefedMappedType(@string), Is.EqualTo(@string));
}
[Test]
public void TestPointerToPrimitiveTypedefPointerTestMethod()
{
int a = 50;
Common.PointerToPrimitiveTypedefPointerTestMethod(ref a, 100);
Assert.AreEqual(100, a);
}
}

5
tests/Common/Common.cpp

@ -1215,3 +1215,8 @@ void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp @@ -1215,3 +1215,8 @@ void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp
{
(*(*lp)).val = valToSet;
}
void DLL_API PointerToPrimitiveTypedefPointerTestMethod(LPINT lp, int valToSet)
{
*lp = valToSet;
}

4
tests/Common/Common.h

@ -1616,3 +1616,7 @@ struct DLL_API PointerToTypedefPointerTest @@ -1616,3 +1616,7 @@ struct DLL_API PointerToTypedefPointerTest
typedef PointerToTypedefPointerTest *LPPointerToTypedefPointerTest;
void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet);
typedef int *LPINT;
void DLL_API PointerToPrimitiveTypedefPointerTestMethod(LPINT lp, int valToSet);
Loading…
Cancel
Save