Browse Source

Merge pull request #343 from ddobrev/master

Removed a hack made redundant by the improved support for inlines
pull/344/head
João Matos 11 years ago
parent
commit
9ab2cee2ea
  1. 16
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  2. 7
      src/Generator/Types/TypeMap.cs

16
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -1956,28 +1956,12 @@ namespace CppSharp.Generators.CSharp
if (copyCtorMethod == null) if (copyCtorMethod == null)
throw new NotSupportedException("Expected a valid copy constructor"); throw new NotSupportedException("Expected a valid copy constructor");
// Call the copy constructor.
TypeMap typeMap;
if (!copyCtorMethod.IsGenerated && Driver.TypeDatabase.FindTypeMap(@class, out typeMap))
{
var context = new CSharpMarshalContext(Driver)
{
ArgName = "native",
ReturnVarName = "ret",
ReturnType = new QualifiedType(new TagType(@class))
};
typeMap.CSharpMarshalCopyCtorToManaged(context);
WriteLine(context.SupportBefore);
}
else
{
// Allocate memory for a new native object and call the ctor. // Allocate memory for a new native object and call the ctor.
WriteLine("var ret = Marshal.AllocHGlobal({0});", @class.Layout.Size); WriteLine("var ret = Marshal.AllocHGlobal({0});", @class.Layout.Size);
WriteLine("{0}.Internal.{1}(ret, new global::System.IntPtr(&native));", WriteLine("{0}.Internal.{1}(ret, new global::System.IntPtr(&native));",
QualifiedIdentifier(@class), GetFunctionNativeIdentifier(copyCtorMethod)); QualifiedIdentifier(@class), GetFunctionNativeIdentifier(copyCtorMethod));
WriteLine("return ret;"); WriteLine("return ret;");
} }
}
else else
{ {
WriteLine("global::System.IntPtr ret = Marshal.AllocHGlobal({0});", @class.Layout.Size); WriteLine("global::System.IntPtr ret = Marshal.AllocHGlobal({0});", @class.Layout.Size);

7
src/Generator/Types/TypeMap.cs

@ -44,7 +44,7 @@ namespace CppSharp.Types
} }
/// <summary> /// <summary>
/// Determines if the type map performs marshalling or only replaces copy ctors. /// Determines if the type map performs marshalling or only injects custom code.
/// </summary> /// </summary>
public virtual bool DoesMarshalling { get { return true; } } public virtual bool DoesMarshalling { get { return true; } }
@ -65,11 +65,6 @@ namespace CppSharp.Types
throw new NotImplementedException(); throw new NotImplementedException();
} }
public virtual void CSharpMarshalCopyCtorToManaged(MarshalContext ctx)
{
}
/// <summary> /// <summary>
/// Used to construct a new instance of the mapped type. /// Used to construct a new instance of the mapped type.
/// </summary> /// </summary>

Loading…
Cancel
Save