_wip
This commit is contained in:
@@ -119,7 +119,8 @@ namespace Flax.Build.Bindings
|
||||
// Pass as pointer to local variable converted for managed runtime
|
||||
if (paramType.IsPtr)
|
||||
result = string.Format(nativeToManaged, '*' + paramName);
|
||||
contents.Append($" auto __param_{paramName} = {result};").AppendLine();
|
||||
contents.Append($" auto __param_orig_{paramName} = {result};").AppendLine();
|
||||
contents.Append($" auto __param_{paramName} = __param_orig_{paramName};").AppendLine();
|
||||
result = $"&__param_{paramName}";
|
||||
useLocalVar = true;
|
||||
}
|
||||
@@ -998,6 +999,11 @@ namespace Flax.Build.Bindings
|
||||
}
|
||||
#endif
|
||||
|
||||
if (functionInfo.UniqueName == "SetView" && callerName == "SceneRenderTaskInternal")
|
||||
callerName = callerName;
|
||||
if (functionInfo.UniqueName == "SetDriveControl")
|
||||
callerName = callerName;
|
||||
|
||||
// Setup function binding glue to ensure that wrapper method signature matches for C++ and C#
|
||||
functionInfo.Glue = new FunctionInfo.GlueInfo
|
||||
{
|
||||
@@ -1155,6 +1161,7 @@ namespace Flax.Build.Bindings
|
||||
},
|
||||
IsOut = parameterInfo.IsOut,
|
||||
IsRef = isRefOut || parameterInfo.Type.IsRef,
|
||||
IsConst = true,
|
||||
});
|
||||
}
|
||||
#endif
|
||||
@@ -1560,7 +1567,8 @@ namespace Flax.Build.Bindings
|
||||
if (paramIsRef)
|
||||
{
|
||||
// Pass as pointer to value when using ref/out parameter
|
||||
contents.Append($" auto __param_{parameterInfo.Name} = {paramValue};").AppendLine();
|
||||
contents.Append($" auto __param_orig_{parameterInfo.Name} = {paramValue};").AppendLine();
|
||||
contents.Append($" auto __param_{parameterInfo.Name} = __param_orig_{parameterInfo.Name};").AppendLine();
|
||||
paramValue = $"&__param_{parameterInfo.Name}";
|
||||
useLocalVar = true;
|
||||
}
|
||||
@@ -1640,6 +1648,78 @@ namespace Flax.Build.Bindings
|
||||
else if (!passAsParamPtr)
|
||||
paramValue = '*' + paramValue;
|
||||
contents.Append($" {parameterInfo.Name} = {paramValue};").AppendLine();
|
||||
|
||||
// Release temporary GCHandles
|
||||
/*if (passAsParamPtr)
|
||||
{
|
||||
//contents.Append($" if (params[{i}] != (void*)&__param_{parameterInfo.Name})").AppendLine();
|
||||
contents.Append($" {{").AppendLine();
|
||||
contents.Append($" auto __param{i}_handle = *(MGCHandle*)¶ms[{i}];").AppendLine();
|
||||
contents.Append($" MCore::GCHandle::Free(__param{i}_handle);").AppendLine();
|
||||
contents.Append($" }}").AppendLine();
|
||||
}
|
||||
else
|
||||
{
|
||||
//contents.Append($" if (params[{i}] != (void*)&__param_{parameterInfo.Name})").AppendLine();
|
||||
contents.Append($" {{").AppendLine();
|
||||
contents.Append($" auto __param{i}_handle = *(MGCHandle*)¶ms[{i}];").AppendLine();
|
||||
contents.Append($" MCore::GCHandle::Free(__param{i}_handle);").AppendLine();
|
||||
contents.Append($" }}").AppendLine();
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Release GCHandles of boxed values
|
||||
for (var i = 0; i < functionInfo.Parameters.Count; i++)
|
||||
{
|
||||
var parameterInfo = functionInfo.Parameters[i];
|
||||
var paramValue = GenerateCppWrapperNativeToBox(buildData, parameterInfo.Type, classInfo, out var apiType, parameterInfo.Name);
|
||||
var paramIsRef = parameterInfo.IsRef || parameterInfo.IsOut;
|
||||
|
||||
if (paramValue.Contains("MUtils::Box<")) // FIXME
|
||||
{
|
||||
if (paramIsRef)
|
||||
{
|
||||
//contents.Append($" MUtils::FreeManaged<{parameterInfo.Type.ToString(false)}>((MObject*)__param_{parameterInfo.Name});").AppendLine();
|
||||
/*if (useThunk)
|
||||
{
|
||||
// Release the original handle
|
||||
contents.Append($" if (__param_orig_{parameterInfo.Name} != __param_{parameterInfo.Name}) //asdf1a").AppendLine();
|
||||
contents.Append($" MUtils::FreeManaged<{parameterInfo.Type.ToString(false)}>((MObject*)__param_{parameterInfo.Name});").AppendLine();
|
||||
}*/
|
||||
contents.Append($" MUtils::FreeManaged<{parameterInfo.Type.Type}>((MObject*)__param_{parameterInfo.Name});").AppendLine();
|
||||
if (useThunk)
|
||||
{
|
||||
// Release the original handle
|
||||
contents.Append($" if (__param_orig_{parameterInfo.Name} != __param_{ parameterInfo.Name})").AppendLine();
|
||||
contents.Append($" MUtils::FreeManaged<{parameterInfo.Type.Type}>((MObject*)__param_orig_{parameterInfo.Name});").AppendLine();
|
||||
}
|
||||
}
|
||||
else if (apiType != null && !apiType.IsInBuild)
|
||||
{
|
||||
// int: ispod, isvaluetype
|
||||
// vector: ispod, isvaluetype, isstruct
|
||||
// guid: ispod, isvaluetype, isstruct, isinbuild
|
||||
contents.Append($" MUtils::FreeManaged<{parameterInfo.Type.Type}>((MObject*)params[{i}]); //asdf1b").AppendLine();
|
||||
//contents.Append($" auto __param{i}_handle = *(MGCHandle*)¶ms[{i}]; // asdf1b").AppendLine();
|
||||
//contents.Append($" ASSERT((((unsigned long long)__param{i}_handle & 0xC000000000000000) >> 62) == 0);").AppendLine();
|
||||
//contents.Append($" MCore::GCHandle::Free(__param{i}_handle);").AppendLine();
|
||||
}
|
||||
else if (apiType != null && !apiType.IsValueType)
|
||||
{
|
||||
if (parameterInfo.Type.Type.ToLower().Contains("string"))
|
||||
apiType = apiType;
|
||||
contents.Append($" MUtils::FreeManaged<{parameterInfo.Type.Type}>((MObject*)params[{i}]); //asdf1d").AppendLine();
|
||||
}
|
||||
else //if (apiType != null)
|
||||
{
|
||||
if (parameterInfo.Type.Type.ToLower().Contains("string"))
|
||||
apiType = apiType;
|
||||
//contents.Append($" //asdf1c {parameterInfo.Type.Type}").AppendLine();
|
||||
contents.Append($" auto __param{i}_handle = *(MGCHandle*)¶ms[{i}]; // asdf1c").AppendLine();
|
||||
//contents.Append($" ASSERT((((unsigned long long)__param{i}_handle & 0xC000000000000000) >> 62) == 0);").AppendLine();
|
||||
contents.Append($" MCore::GCHandle::Free(__param{i}_handle);").AppendLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2095,6 +2175,22 @@ namespace Flax.Build.Bindings
|
||||
else if (!passAsParamPtr)
|
||||
paramValue = '*' + paramValue;
|
||||
contents.Append($" arg{i} = {paramValue};").AppendLine();
|
||||
|
||||
// Release temporary GCHandles
|
||||
if (CppParamsThatNeedConversion[i])
|
||||
{
|
||||
// Release the original handle
|
||||
contents.Append($" if (&__param_orig_arg{i} != &__param_arg{i})").AppendLine();
|
||||
contents.Append($" FreeManaged(({managedType})__param_arg{i});").AppendLine();
|
||||
}
|
||||
/*contents.Append($" FreeManaged(({managedType})__param_arg{i}); //hmm1b").AppendLine();
|
||||
if (CppParamsThatNeedConversion[i])
|
||||
{
|
||||
// Release the original handle
|
||||
contents.Append($" if (&__param_orig_arg{i} != &__param_arg{i})").AppendLine();
|
||||
contents.Append($" FreeManaged(({managedType})__param_orig_arg{i});").AppendLine();
|
||||
}*/
|
||||
|
||||
paramType.IsRef = true;
|
||||
}
|
||||
}
|
||||
@@ -2392,6 +2488,7 @@ namespace Flax.Build.Bindings
|
||||
{
|
||||
Type = fieldInfo.Type,
|
||||
Name = "value",
|
||||
IsConst = true,
|
||||
},
|
||||
},
|
||||
ReturnType = new TypeInfo
|
||||
@@ -3001,6 +3098,7 @@ namespace Flax.Build.Bindings
|
||||
header.AppendLine("namespace {");
|
||||
header.AppendFormat("{0} ToManaged(const {1}& value);", wrapperName, fullName).AppendLine();
|
||||
header.AppendFormat("{1} ToNative(const {0}& value);", wrapperName, fullName).AppendLine();
|
||||
header.AppendFormat("void FreeManaged(const {0}& value);", wrapperName).AppendLine();
|
||||
header.AppendLine("}");
|
||||
|
||||
// Generate MConverter for a structure
|
||||
@@ -3016,7 +3114,10 @@ namespace Flax.Build.Bindings
|
||||
|
||||
header.AppendFormat(" DLLEXPORT USED void Unbox({0}& result, MObject* data)", fullName).AppendLine();
|
||||
header.Append(" {").AppendLine();
|
||||
header.AppendFormat(" result = ToNative(*reinterpret_cast<{0}*>(MCore::Object::Unbox(data)));", wrapperName).AppendLine();
|
||||
//header.AppendFormat(" result = ToNative(*reinterpret_cast<{0}*>(MCore::Object::Unbox(data)));", wrapperName).AppendLine();
|
||||
header.AppendFormat(" auto managed = *reinterpret_cast<{0}*>(MCore::Object::Unbox(data));", wrapperName).AppendLine();
|
||||
header.AppendFormat(" result = ToNative(managed);", wrapperName).AppendLine();
|
||||
header.AppendFormat(" ::FreeManaged(managed);", wrapperName).AppendLine();
|
||||
header.Append(" }").AppendLine();
|
||||
|
||||
header.AppendFormat(" DLLEXPORT USED void ToManagedArray(MArray* result, const Span<{0}>& data)", fullName).AppendLine();
|
||||
@@ -3036,6 +3137,13 @@ namespace Flax.Build.Bindings
|
||||
header.Append(" for (int32 i = 0; i < result.Length(); i++)").AppendLine();
|
||||
header.Append(" result[i] = ToNative(dataPtr[i]);").AppendLine();
|
||||
header.Append(" }").AppendLine();
|
||||
header.AppendFormat(" void FreeManaged(MObject* data)", fullName).AppendLine();
|
||||
header.Append(" {").AppendLine();
|
||||
//header.AppendFormat(" auto managed = MCore::Object::Unbox(data);", wrapperName).AppendLine();
|
||||
//header.AppendFormat(" ::FreeManaged(*reinterpret_cast<{0}*>(managed));", wrapperName).AppendLine();
|
||||
header.AppendFormat(" MCore::GCHandle::Free(*(MGCHandle*)&data);", wrapperName).AppendLine();
|
||||
header.Append(" }").AppendLine();
|
||||
|
||||
header.Append('}').Append(';').AppendLine();
|
||||
|
||||
// Generate converting function native -> managed
|
||||
@@ -3110,8 +3218,47 @@ namespace Flax.Build.Bindings
|
||||
header.AppendFormat(" result.{0} = value.{0};", fieldInfo.Name).AppendLine();
|
||||
else
|
||||
header.AppendFormat(" result.{0} = {1};", fieldInfo.Name, string.Format(wrapper, string.Format("value.{0}", fieldInfo.Name))).AppendLine();
|
||||
/*if (wrapper.Contains("::ToNative(")) // FIXME
|
||||
{
|
||||
header.Append($" auto __param{fieldInfo.Name}_handle = *(MGCHandle*)&value.{fieldInfo.Name};").AppendLine();
|
||||
header.Append($" ASSERT((((unsigned long long)__param{fieldInfo.Name}_handle & 0xC000000000000000) >> 62) == 0); // asdf3").AppendLine();
|
||||
header.Append($" MCore::GCHandle::Free(__param{fieldInfo.Name}_handle);").AppendLine();
|
||||
}*/
|
||||
}
|
||||
header.Append(" return result;").AppendLine();
|
||||
header.Append('}').AppendLine();
|
||||
|
||||
// Generate release function for temporary managed handles
|
||||
header.AppendLine();
|
||||
header.AppendFormat("void FreeManaged(const {0}& value)", wrapperName).AppendLine();
|
||||
header.Append('{').AppendLine();
|
||||
for (var i = 0; i < fields.Count; i++)
|
||||
{
|
||||
var fieldInfo = fields[i];
|
||||
if (fieldInfo.IsStatic || fieldInfo.IsConstexpr)
|
||||
continue;
|
||||
|
||||
CppNonPodTypesConvertingGeneration = true;
|
||||
var wrapper = GenerateCppWrapperManagedToNative(buildData, fieldInfo.Type, apiType, out var managedType, out var fieldApiType, null, out _);
|
||||
CppNonPodTypesConvertingGeneration = false;
|
||||
|
||||
if (wrapper.Contains("::ToNative(")) // FIXME fieldApiType.IsScriptingObject
|
||||
{
|
||||
header.Append($" auto __param{fieldInfo.Name}_handle = *(MGCHandle*)&value.{fieldInfo.Name};").AppendLine();
|
||||
//header.Append($" ASSERT((((unsigned long long)__param{fieldInfo.Name}_handle & 0xC000000000000000) >> 62) == 0); // asdf3").AppendLine();
|
||||
header.Append($" if ((((unsigned long long)__param{fieldInfo.Name}_handle & 0xC000000000000000) >> 62) != 0) // asdf3").AppendLine();
|
||||
header.Append($" __param{fieldInfo.Name}_handle = __param{fieldInfo.Name}_handle;").AppendLine();
|
||||
|
||||
header.Append($" MCore::GCHandle::Free(__param{fieldInfo.Name}_handle);").AppendLine();
|
||||
}
|
||||
}
|
||||
if (classInfo != null)
|
||||
{
|
||||
header.Append($" auto __value_handle = *(MGCHandle*)&value;").AppendLine();
|
||||
header.Append($" ASSERT((((unsigned long long)__value_handle & 0xC000000000000000) >> 62) == 0); // asdf4").AppendLine();
|
||||
header.Append($" MCore::GCHandle::Free(__value_handle);").AppendLine();
|
||||
}
|
||||
|
||||
header.Append('}').AppendLine();
|
||||
header.AppendLine("}");
|
||||
}
|
||||
@@ -3190,6 +3337,11 @@ namespace Flax.Build.Bindings
|
||||
header.AppendFormat(" Unbox(result[i], dataPtr[i]);", fullName).AppendLine();
|
||||
header.Append(" }").AppendLine();
|
||||
|
||||
header.AppendFormat(" void FreeManaged(MObject* data) // honk1", fullName).AppendLine();
|
||||
header.Append(" {").AppendLine();
|
||||
//header.Append(" ::FreeManaged(reinterpret_cast<OnlineUserManaged*>(MCore::Object::Unbox(data)));").AppendLine();
|
||||
header.Append(" }").AppendLine();
|
||||
|
||||
header.Append('}').Append(';').AppendLine();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user