Browse Source

Fixed the generated C# for public fields with type a dependent function pointer.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1033/head
Dimitar Dobrev 8 years ago
parent
commit
1a1308ad8a
  1. 19
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 2
      tests/CSharp/CSharpTemplates.h

19
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -270,13 +270,18 @@ namespace CppSharp.Generators.CSharp
var functionType = decl.Type as FunctionType; var functionType = decl.Type as FunctionType;
if (functionType != null || decl.Type.IsPointerTo(out functionType)) if (functionType != null || decl.Type.IsPointerTo(out functionType))
{ {
var ptrName = Generator.GeneratedIdentifier("ptr") + var ptrName = $"{Generator.GeneratedIdentifier("ptr")}{Context.ParameterIndex}";
Context.ParameterIndex;
Context.Before.WriteLine($"var {ptrName} = {Context.ReturnVarName};");
Context.Before.WriteLine("var {0} = {1};", ptrName,
Context.ReturnVarName); var specialization = decl.Namespace as ClassTemplateSpecialization;
var res = string.Format(
var res = $"{ptrName} == IntPtr.Zero? null : ({typedef})Marshal.GetDelegateForFunctionPointer({ptrName}, typeof({typedef}))"; "{0} == IntPtr.Zero? null : {1}({2}) Marshal.GetDelegateForFunctionPointer({0}, typeof({2}))",
ptrName,
specialization == null ? string.Empty :
$@"({specialization.TemplatedDecl.TemplatedClass.Typedefs.First(
t => t.Name == decl.Name).Visit(this.typePrinter)}) (object) ",
typedef);
Context.Return.Write(res); Context.Return.Write(res);
return true; return true;
} }

2
tests/CSharp/CSharpTemplates.h

@ -137,6 +137,8 @@ public:
T getDependentValue(); T getDependentValue();
void setDependentValue(const T& value); void setDependentValue(const T& value);
IndependentFields<Nested> returnNestedInTemplate(); IndependentFields<Nested> returnNestedInTemplate();
typedef void (*DependentFunctionPointer)(T);
DependentFunctionPointer dependentFunctionPointerField;
private: private:
T field{}; T field{};
union { union {

Loading…
Cancel
Save