Browse Source

Use GenerateInternalFunctionCall when generating class constructors.

Fixes #149.
pull/146/merge
triton 12 years ago
parent
commit
22b6a3c11f
  1. 17
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  2. 11
      tests/Basic/Basic.h

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

@ -1933,20 +1933,11 @@ namespace CppSharp.Generators.CSharp
private void GenerateClassConstructor(Method method, Class @class) private void GenerateClassConstructor(Method method, Class @class)
{ {
var @params = GenerateFunctionParamsMarshal(method.Parameters, method);
WriteLine("{0} = Marshal.AllocHGlobal({1});", Helpers.InstanceIdentifier, WriteLine("{0} = Marshal.AllocHGlobal({1});", Helpers.InstanceIdentifier,
@class.Layout.Size); @class.Layout.Size);
if (!method.IsDefaultConstructor || @class.HasNonTrivialDefaultConstructor) if (!method.IsDefaultConstructor || @class.HasNonTrivialDefaultConstructor)
{ GenerateInternalFunctionCall(method);
Write("Internal.{0}({1}", GetFunctionNativeIdentifier(method),
Helpers.InstanceIdentifier);
if (@params.Any())
Write(", ");
GenerateFunctionParams(@params);
WriteLine(");");
}
GenerateVTableClassSetupCall(@class); GenerateVTableClassSetupCall(@class);
} }
@ -2182,12 +2173,6 @@ namespace CppSharp.Generators.CSharp
public CSharpMarshalContext Context; public CSharpMarshalContext Context;
} }
public void GenerateFunctionParams(List<ParamMarshal> @params)
{
var names = @params.Select(param => param.Name).ToList();
Write(string.Join(", ", names));
}
public List<ParamMarshal> GenerateFunctionParamsMarshal(IEnumerable<Parameter> @params, public List<ParamMarshal> GenerateFunctionParamsMarshal(IEnumerable<Parameter> @params,
Function function = null) Function function = null)
{ {

11
tests/Basic/Basic.h

@ -47,6 +47,8 @@ struct DLL_API Bar
Bar* returnPointerToValueType(); Bar* returnPointerToValueType();
}; };
DLL_API Bar::Item operator |(Bar::Item left, Bar::Item right);
struct DLL_API Bar2 : public Bar struct DLL_API Bar2 : public Bar
{ {
// Conversion operators // Conversion operators
@ -234,4 +236,11 @@ struct DLL_API TestDelegates
DelegateInGlobalNamespace B; DelegateInGlobalNamespace B;
}; };
DLL_API Bar::Item operator |(Bar::Item left, Bar::Item right); // Tests memory leaks in constructors
// C#: Marshal.FreeHGlobal(arg0);
struct DLL_API TestMemoryLeaks
{
TestMemoryLeaks(const char* name) {}
};

Loading…
Cancel
Save