From ed3e0bd54a8fcf9849060d3f57e83f2d91a28b41 Mon Sep 17 00:00:00 2001 From: Pedro Miguel Casaleiro Dias Date: Thu, 23 Jul 2015 16:54:31 +0100 Subject: [PATCH] closes #514. test added to tests/CSharpTemp/CSharpTemp.Tests.cs --- src/Generator/Generators/CSharp/CSharpMarshal.cs | 5 ++--- tests/CSharpTemp/CSharpTemp.Tests.cs | 10 ++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index 0ad09b42..f9853a67 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -401,9 +401,8 @@ namespace CppSharp.Generators.CSharp public bool VisitDelegateType(FunctionType function, string type) { - Context.Return.Write("Marshal.GetFunctionPointerForDelegate({0})", - Context.Parameter.Name); - + Context.Return.Write("{0} == null ? global::System.IntPtr.Zero : Marshal.GetFunctionPointerForDelegate({0})", + Context.Parameter.Name); return true; } diff --git a/tests/CSharpTemp/CSharpTemp.Tests.cs b/tests/CSharpTemp/CSharpTemp.Tests.cs index 2f3f87cf..2ac01f5c 100644 --- a/tests/CSharpTemp/CSharpTemp.Tests.cs +++ b/tests/CSharpTemp/CSharpTemp.Tests.cs @@ -327,4 +327,14 @@ public class CSharpTempTests : GeneratorTestFixture dervClass = new TestParamToInterfacePass(dervClass + baseInterface); Assert.AreEqual(dervClass.M, 2); } + + [Test] + public void TestNullAttributedFunctionPtr() + { + using (var foo = new Foo()) + { + foo.AttributedFunctionPtr = null; + } + } + } \ No newline at end of file