Refactor generated bindings P/Invoke to support name mangling for symbols

This commit is contained in:
Wojciech Figat
2023-01-23 18:41:12 +01:00
parent f3366178ea
commit 405ae519dd
13 changed files with 187 additions and 136 deletions

View File

@@ -260,15 +260,15 @@ namespace FlaxEngine
#region Internal Calls
[LibraryImport("FlaxEngine", EntryPoint = "FlaxEngine.AnimationGraph::Internal_HasConnection")]
[LibraryImport("FlaxEngine", EntryPoint = "AnimGraphInternal_HasConnection")]
[return: MarshalAs(UnmanagedType.U1)]
internal static partial bool Internal_HasConnection(ref AnimationGraph.CustomNode.Context context, int boxId);
[LibraryImport("FlaxEngine", EntryPoint = "FlaxEngine.AnimationGraph::Internal_GetInputValue")]
[LibraryImport("FlaxEngine", EntryPoint = "AnimGraphInternal_GetInputValue")]
[return: MarshalUsing(typeof(FlaxEngine.ManagedHandleMarshaller))]
internal static partial object Internal_GetInputValue(ref AnimationGraph.CustomNode.Context context, int boxId);
[LibraryImport("FlaxEngine", EntryPoint = "FlaxEngine.AnimationGraph::Internal_GetOutputImpulseData")]
[LibraryImport("FlaxEngine", EntryPoint = "AnimGraphInternal_GetOutputImpulseData")]
internal static partial IntPtr Internal_GetOutputImpulseData(ref AnimationGraph.CustomNode.Context context);
#endregion

View File

@@ -32,8 +32,6 @@
#pragma clang diagnostic ignored "-Wnull-dereference"
#pragma clang diagnostic ignored "-Winvalid-noreturn"
#define SCRIPTING_EXPORT(name)
#elif defined(__GNUC__)
#define DLLEXPORT __attribute__ ((__visibility__ ("default")))
@@ -88,8 +86,6 @@
#pragma warning(disable: 4251)
#define SCRIPTING_EXPORT(name) __pragma(comment(linker, "/EXPORT:" #name "=" __FUNCDNAME__))
#else
#pragma error "Unknown compiler."

View File

@@ -1323,7 +1323,6 @@ bool Level::SaveAllScenes()
void Level::SaveAllScenesAsync()
{
SCRIPTING_EXPORT("FlaxEngine.Level::Internal_SaveAllScenesAsync")
ScopeLock lock(_sceneActionsLocker);
for (int32 i = 0; i < Scenes.Count(); i++)
_sceneActions.Enqueue(New<SaveSceneAction>(Scenes[i]));
@@ -1428,7 +1427,6 @@ bool Level::UnloadAllScenes()
void Level::UnloadAllScenesAsync()
{
SCRIPTING_EXPORT("FlaxEngine.Level::Internal_UnloadAllScenesAsync")
ScopeLock lock(_sceneActionsLocker);
_sceneActions.Enqueue(New<UnloadScenesAction>());
}

View File

@@ -304,7 +304,6 @@ bool NetworkManager::StartHost()
void NetworkManager::Stop()
{
SCRIPTING_EXPORT("FlaxEngine.Networking.NetworkManager::Internal_Stop");
if (Mode == NetworkManagerMode::Offline && State == NetworkConnectionState::Offline)
return;
PROFILE_CPU();

View File

@@ -16,7 +16,6 @@ typedef struct _DROPFILES
void WindowsClipboard::Clear()
{
SCRIPTING_EXPORT("FlaxEngine.Clipboard::Internal_Clear");
OpenClipboard(nullptr);
EmptyClipboard();
CloseClipboard();

View File

@@ -700,7 +700,6 @@ void Render2D::Begin(GPUContext* context, GPUTextureView* output, GPUTextureView
void Render2D::End()
{
SCRIPTING_EXPORT("FlaxEngine.Render2D::Internal_End")
RENDER2D_CHECK_RENDERING_STATE;
ASSERT(Context != nullptr && Output != nullptr);
ASSERT(GUIShader != nullptr);
@@ -816,7 +815,6 @@ void Render2D::PeekTransform(Matrix3x3& transform)
void Render2D::PopTransform()
{
SCRIPTING_EXPORT("FlaxEngine.Render2D::Internal_PopTransform")
RENDER2D_CHECK_RENDERING_STATE;
ASSERT(TransformLayersStack.HasItems());
@@ -858,7 +856,6 @@ void Render2D::PeekClip(Rectangle& clipRect)
void Render2D::PopClip()
{
SCRIPTING_EXPORT("FlaxEngine.Render2D::Internal_PopClip")
RENDER2D_CHECK_RENDERING_STATE;
ClipLayersStack.Pop();
@@ -880,7 +877,6 @@ void Render2D::PeekTint(Color& tint)
void Render2D::PopTint()
{
SCRIPTING_EXPORT("FlaxEngine.Render2D::Internal_PopTint")
RENDER2D_CHECK_RENDERING_STATE;
TintLayersStack.Pop();

View File

@@ -1,6 +1,5 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#include "Engine/Platform/FileSystem.h"
#include "Engine/Animations/Graph/AnimGraph.h"
#include "Engine/Scripting/InternalCalls.h"
#include "Engine/Scripting/MException.h"
@@ -8,82 +7,69 @@
#if !COMPILE_WITHOUT_CSHARP
namespace UtilsInternal
#if USE_MONO && !USE_NETCORE
DEFINE_INTERNAL_CALL(MonoObject*) UtilsInternal_ExtractArrayFromList(MonoObject* obj)
{
MonoObject* ExtractArrayFromList(MonoObject* obj)
{
#if USE_MONO
auto klass = mono_object_get_class(obj);
auto field = mono_class_get_field_from_name(klass, "_items");
MonoObject* o;
mono_field_get_value(obj, field, &o);
return o;
#else
SCRIPTING_EXPORT("FlaxEngine.Utils::Internal_ExtractArrayFromList")
return nullptr;
auto klass = mono_object_get_class(obj);
auto field = mono_class_get_field_from_name(klass, "_items");
MonoObject* o;
mono_field_get_value(obj, field, &o);
return o;
}
#endif
}
DEFINE_INTERNAL_CALL(void) PlatformInternal_MemoryCopy(void* dst, const void* src, uint64 size)
{
Platform::MemoryCopy(dst, src, size);
}
namespace DebugLogHandlerInternal
DEFINE_INTERNAL_CALL(void) PlatformInternal_MemoryClear(void* dst, uint64 size)
{
void LogWrite(LogType level, MonoString* msgObj)
{
SCRIPTING_EXPORT("FlaxEngine.DebugLogHandler::Internal_LogWrite")
StringView msg;
MUtils::ToString(msgObj, msg);
Log::Logger::Write(level, msg);
}
void Log(LogType level, MonoString* msgObj, ScriptingObject* obj, MonoString* stackTrace)
{
SCRIPTING_EXPORT("FlaxEngine.DebugLogHandler::Internal_Log")
if (msgObj == nullptr)
return;
// Get info
StringView msg;
MUtils::ToString(msgObj, msg);
//const String objName = obj ? obj->ToString() : String::Empty;
// Send event
// TODO: maybe option for build to threat warnings and errors as fatal errors?
//const String logMessage = String::Format(TEXT("Debug:{1} {2}"), objName, *msg);
Log::Logger::Write(level, msg);
}
void LogException(MonoException* exception, ScriptingObject* obj)
{
SCRIPTING_EXPORT("FlaxEngine.DebugLogHandler::Internal_LogException")
#if USE_MONO
if (exception == nullptr)
return;
// Get info
MException ex(exception);
const String objName = obj ? obj->ToString() : String::Empty;
// Print exception including inner exceptions
// TODO: maybe option for build to threat warnings and errors as fatal errors?
ex.Log(LogType::Warning, objName.GetText());
#endif
}
Platform::MemoryClear(dst, size);
}
namespace FlaxLogWriterInternal
DEFINE_INTERNAL_CALL(int32) PlatformInternal_MemoryCompare(const void* buf1, const void* buf2, uint64 size)
{
void WriteStringToLog(MonoString* msgObj)
{
SCRIPTING_EXPORT("FlaxEngine.FlaxLogWriter::Internal_WriteStringToLog")
if (msgObj == nullptr)
return;
StringView msg;
MUtils::ToString(msgObj, msg);
LOG_STR(Info, msg);
}
return Platform::MemoryCompare(buf1, buf2, size);
}
DEFINE_INTERNAL_CALL(void) DebugLogHandlerInternal_LogWrite(LogType level, MonoString* msgObj)
{
StringView msg;
MUtils::ToString(msgObj, msg);
Log::Logger::Write(level, msg);
}
DEFINE_INTERNAL_CALL(void) DebugLogHandlerInternal_Log(LogType level, MonoString* msgObj, ScriptingObject* obj, MonoString* stackTrace)
{
if (msgObj == nullptr)
return;
// Get info
StringView msg;
MUtils::ToString(msgObj, msg);
//const String objName = obj ? obj->ToString() : String::Empty;
// Send event
// TODO: maybe option for build to threat warnings and errors as fatal errors?
//const String logMessage = String::Format(TEXT("Debug:{1} {2}"), objName, *msg);
Log::Logger::Write(level, msg);
}
DEFINE_INTERNAL_CALL(void) DebugLogHandlerInternal_LogException(MonoException* exception, ScriptingObject* obj)
{
#if USE_MONO
if (exception == nullptr)
return;
// Get info
MException ex(exception);
const String objName = obj ? obj->ToString() : String::Empty;
// Print exception including inner exceptions
// TODO: maybe option for build to threat warnings and errors as fatal errors?
ex.Log(LogType::Warning, objName.GetText());
#endif
}
#endif
@@ -92,13 +78,14 @@ void registerFlaxEngineInternalCalls()
{
AnimGraphExecutor::initRuntime();
#if USE_MONO
ADD_INTERNAL_CALL("FlaxEngine.Utils::MemoryCopy", &Platform::MemoryCopy);
ADD_INTERNAL_CALL("FlaxEngine.Utils::MemoryClear", &Platform::MemoryClear);
ADD_INTERNAL_CALL("FlaxEngine.Utils::MemoryCompare", &Platform::MemoryCompare);
ADD_INTERNAL_CALL("FlaxEngine.Utils::MemoryCopy", &PlatformInternal_MemoryCopy);
ADD_INTERNAL_CALL("FlaxEngine.Utils::MemoryClear", &PlatformInternal_MemoryClear);
ADD_INTERNAL_CALL("FlaxEngine.Utils::MemoryCompare", &PlatformInternal_MemoryCompare);
#if USE_MONO && !USE_NETCORE
ADD_INTERNAL_CALL("FlaxEngine.Utils::Internal_ExtractArrayFromList", &UtilsInternal::ExtractArrayFromList);
ADD_INTERNAL_CALL("FlaxEngine.DebugLogHandler::Internal_LogWrite", &DebugLogHandlerInternal::LogWrite);
ADD_INTERNAL_CALL("FlaxEngine.DebugLogHandler::Internal_Log", &DebugLogHandlerInternal::Log);
ADD_INTERNAL_CALL("FlaxEngine.DebugLogHandler::Internal_LogException", &DebugLogHandlerInternal::LogException);
ADD_INTERNAL_CALL("FlaxEngine.FlaxLogWriter::Internal_WriteStringToLog", &FlaxLogWriterInternal::WriteStringToLog);
#endif
ADD_INTERNAL_CALL("FlaxEngine.DebugLogHandler::Internal_LogWrite", &DebugLogHandlerInternal_LogWrite);
ADD_INTERNAL_CALL("FlaxEngine.DebugLogHandler::Internal_Log", &DebugLogHandlerInternal_Log);
ADD_INTERNAL_CALL("FlaxEngine.DebugLogHandler::Internal_LogException", &DebugLogHandlerInternal_LogException);
#endif
}