Merge branch 'master' into 1.1

This commit is contained in:
Wojtek Figat
2021-02-27 16:42:53 +01:00
5 changed files with 75 additions and 19 deletions

View File

@@ -12,8 +12,9 @@ namespace Flax.Build.Bindings
partial class BindingsGenerator
{
private static readonly bool[] CppParamsThatNeedLocalVariable = new bool[64];
private static readonly bool[] CppParamsThatNeedConvertion = new bool[64];
private static readonly string[] CppParamsThatNeedConvertionWrappers = new string[64];
private static readonly bool[] CppParamsThatNeedConversion = new bool[64];
private static readonly string[] CppParamsThatNeedConversionWrappers = new string[64];
private static readonly string[] CppParamsThatNeedConversionTypes = new string[64];
private static readonly string[] CppParamsWrappersCache = new string[64];
public static readonly List<ApiTypeInfo> CppUsedNonPodTypes = new List<ApiTypeInfo>();
private static readonly List<ApiTypeInfo> CppUsedNonPodTypesList = new List<ApiTypeInfo>();
@@ -620,7 +621,7 @@ namespace Flax.Build.Bindings
contents.Append(", ");
separator = true;
CppParamsThatNeedConvertion[i] = false;
CppParamsThatNeedConversion[i] = false;
CppParamsWrappersCache[i] = GenerateCppWrapperManagedToNative(buildData, parameterInfo.Type, caller, out var managedType, functionInfo, out CppParamsThatNeedLocalVariable[i]);
contents.Append(managedType);
if (parameterInfo.IsRef || parameterInfo.IsOut || UsePassByReference(buildData, parameterInfo.Type, caller))
@@ -654,8 +655,8 @@ namespace Flax.Build.Bindings
if (convertOutputParameter)
{
useInlinedReturn = false;
CppParamsThatNeedConvertion[i] = true;
CppParamsThatNeedConvertionWrappers[i] = GenerateCppWrapperNativeToManaged(buildData, parameterInfo.Type, caller, out _, functionInfo);
CppParamsThatNeedConversion[i] = true;
CppParamsThatNeedConversionWrappers[i] = GenerateCppWrapperNativeToManaged(buildData, parameterInfo.Type, caller, out CppParamsThatNeedConversionTypes[i], functionInfo);
}
}
}
@@ -717,7 +718,7 @@ namespace Flax.Build.Bindings
callParams += ", ";
separator = true;
var name = parameterInfo.Name;
if (CppParamsThatNeedConvertion[i] && (!FindApiTypeInfo(buildData, parameterInfo.Type, caller)?.IsStruct ?? false))
if (CppParamsThatNeedConversion[i] && (!FindApiTypeInfo(buildData, parameterInfo.Type, caller)?.IsStruct ?? false))
name = '*' + name;
string param = string.Empty;
@@ -735,7 +736,7 @@ namespace Flax.Build.Bindings
}
// Special case for output result parameters that needs additional converting from native to managed format (such as non-POD structures or output array parameter)
if (CppParamsThatNeedConvertion[i])
if (CppParamsThatNeedConversion[i])
{
var apiType = FindApiTypeInfo(buildData, parameterInfo.Type, caller);
if (apiType != null)
@@ -792,9 +793,41 @@ namespace Flax.Build.Bindings
var parameterInfo = functionInfo.Parameters[i];
// Special case for output result parameters that needs additional converting from native to managed format (such as non-POD structures or output array parameter)
if (CppParamsThatNeedConvertion[i])
if (CppParamsThatNeedConversion[i])
{
contents.AppendFormat(" *{0} = {1};", parameterInfo.Name, string.Format(CppParamsThatNeedConvertionWrappers[i], parameterInfo.Name + "Temp")).AppendLine();
var value = string.Format(CppParamsThatNeedConversionWrappers[i], parameterInfo.Name + "Temp");
// MonoObject* parameters returned by reference need write barrier for GC
if (parameterInfo.IsOut)
{
var apiType = FindApiTypeInfo(buildData, parameterInfo.Type, caller);
if (apiType != null)
{
if (apiType.IsClass)
{
contents.AppendFormat(" mono_gc_wbarrier_generic_store({0}, (MonoObject*){1});", parameterInfo.Name, value).AppendLine();
continue;
}
if (apiType.IsStruct && !apiType.IsPod)
{
CppIncludeFiles.Add("Engine/Scripting/ManagedCLR/MClass.h");
contents.AppendFormat(" {{ auto _temp = {1}; mono_gc_wbarrier_value_copy({0}, &_temp, 1, {2}::TypeInitializer.GetType().ManagedClass->GetNative()); }}", parameterInfo.Name, value, apiType.FullNameNative).AppendLine();
continue;
}
}
else
{
// BytesContainer
if (parameterInfo.Type.Type == "BytesContainer" && parameterInfo.Type.GenericArgs == null)
{
contents.AppendFormat(" mono_gc_wbarrier_generic_store({0}, (MonoObject*){1});", parameterInfo.Name, value).AppendLine();
continue;
}
throw new Exception($"Unsupported type of parameter '{parameterInfo}' in method '{functionInfo}' to be passed using 'out'");
}
}
contents.AppendFormat(" *{0} = {1};", parameterInfo.Name, value).AppendLine();
}
}
}