Browse Source

Fixed code generation for constant arrays of function pointers.

Fixes https://github.com/mono/CppSharp/issues/632 and SDL sample.
pull/621/merge
João Matos 10 years ago
parent
commit
4d89bfa001
  1. 13
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  2. 11
      tests/Common/Common.h

13
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -126,8 +126,10 @@ namespace CppSharp.Generators.CSharp @@ -126,8 +126,10 @@ namespace CppSharp.Generators.CSharp
array.SizeType == ArrayType.ArraySize.Constant)
{
Type arrayType = array.Type.Desugar();
PrimitiveType primitiveType;
if (arrayType.IsPointerToPrimitiveType(out primitiveType))
if (arrayType.IsPointerToPrimitiveType(out primitiveType) &&
!(arrayType is FunctionType))
{
if (primitiveType == PrimitiveType.Void)
{
@ -146,11 +148,18 @@ namespace CppSharp.Generators.CSharp @@ -146,11 +148,18 @@ namespace CppSharp.Generators.CSharp
};
}
var arrayElemType = array.Type.Visit(this, quals).ToString();
// C# does not support fixed arrays of machine pointer type (void* or IntPtr).
// In that case, replace it by a pointer to an integer type of the same size.
if (arrayElemType == IntPtrType)
arrayElemType = driver.TargetInfo.PointerWidth == 64 ? "long" : "int";
// Do not write the fixed keyword multiple times for nested array types
var fixedKeyword = array.Type is ArrayType ? string.Empty : "fixed ";
return new CSharpTypePrinterResult()
{
Type = string.Format("{0}{1}", fixedKeyword, array.Type.Visit(this, quals)),
Type = string.Format("{0}{1}", fixedKeyword, arrayElemType),
NameSuffix = string.Format("[{0}]", array.Size)
};
}

11
tests/Common/Common.h

@ -617,6 +617,17 @@ LPCWSTR TestWideStrings::GetWideNullPointer() { return 0; } @@ -617,6 +617,17 @@ LPCWSTR TestWideStrings::GetWideNullPointer() { return 0; }
enum struct MyEnum { A, B, C };
typedef void (*VoidPtrRetFunctionTypedef) ();
class DLL_API TestFixedArrays
{
public:
TestFixedArrays();
VoidPtrRetFunctionTypedef Array[10];
};
TestFixedArrays::TestFixedArrays() {}
class DLL_API TestArraysPointers
{
public:

Loading…
Cancel
Save