Browse Source

Added a check for 'null' before getting the native pointer of a wrapped object.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/109/head
Dimitar Dobrev 12 years ago
parent
commit
8a502835f7
  1. 17
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 2
      tests/CSharpTemp/CSharpTemp.Tests.cs
  3. 10
      tests/CSharpTemp/CSharpTemp.cpp
  4. 2
      tests/CSharpTemp/CSharpTemp.h

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

@ -572,17 +572,24 @@ namespace CppSharp.Generators.CSharp @@ -572,17 +572,24 @@ namespace CppSharp.Generators.CSharp
return;
}
if (Context.Parameter.Type.IsAddress())
string param = Helpers.SafeIdentifier(Context.Parameter.Name);
Type type = Context.Parameter.Type.Desugar();
if (type.IsAddress())
{
Context.Return.Write("{0}.{1}", Helpers.SafeIdentifier(Context.Parameter.Name),
Helpers.InstanceIdentifier);
Class decl;
if (type.IsTagDecl(out decl) && decl.IsValueType)
Context.Return.Write("{0}.{1}", param, Helpers.InstanceIdentifier);
else
Context.Return.Write("{0} == ({2}) null ? global::System.IntPtr.Zero : {0}.{1}", param,
Helpers.InstanceIdentifier, type);
return;
}
var qualifiedIdentifier = CSharpMarshalNativeToManagedPrinter.QualifiedIdentifier(
@class.OriginalClass ?? @class);
Context.Return.Write("*({0}.Internal*){1}.{2}", qualifiedIdentifier,
Helpers.SafeIdentifier(Context.Parameter.Name), Helpers.InstanceIdentifier);
Context.Return.Write(
"{1} == ({0}) null ? new {0}.Internal() : *({0}.Internal*) ({1}.{2})", qualifiedIdentifier,
param, Helpers.InstanceIdentifier);
}
private void MarshalValueClass(Class @class)

2
tests/CSharpTemp/CSharpTemp.Tests.cs

@ -33,7 +33,7 @@ public class CSharpTempTests @@ -33,7 +33,7 @@ public class CSharpTempTests
[Test]
public void TestFixedArrays()
{
Qux qux = new Qux();
Qux qux = new Qux(null);
var array = new[] { 1, 2, 3 };
qux.Array = array;
for (int i = 0; i < qux.Array.Length; i++)

10
tests/CSharpTemp/CSharpTemp.cpp

@ -31,6 +31,16 @@ const Foo& Bar::operator[](int i) const @@ -31,6 +31,16 @@ const Foo& Bar::operator[](int i) const
return m_foo;
}
Qux::Qux()
{
}
Qux::Qux(Foo foo)
{
}
int Qux::farAwayFunc() const
{
return 20;

2
tests/CSharpTemp/CSharpTemp.h

@ -21,6 +21,8 @@ protected: @@ -21,6 +21,8 @@ protected:
class DLL_API Qux
{
public:
Qux();
Qux(Foo foo);
int farAwayFunc() const;
int array[3];
};

Loading…
Cancel
Save