From d5d808180941e38db893cc092350e293442428ba Mon Sep 17 00:00:00 2001 From: johnche Date: Wed, 26 Feb 2025 15:36:10 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[unity]=E5=90=88=E5=85=A5=20https://github.?= =?UTF-8?q?com/puerts/papi-quickjs=20=E7=9A=84=E9=81=BF=E5=85=8D=E4=BE=9D?= =?UTF-8?q?=E8=B5=96libc++=E6=96=B9=E9=9D=A2=E7=9A=84=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- unity/native_src/Inc/JSClassRegister.h | 33 +++++++------- unity/native_src/Inc/PString.h | 55 +++++++++++------------ unity/native_src/Inc/PuertsNamespaceDef.h | 33 ++++++++++++++ unity/native_src/Inc/TypeInfo.hpp | 1 + 4 files changed, 76 insertions(+), 46 deletions(-) diff --git a/unity/native_src/Inc/JSClassRegister.h b/unity/native_src/Inc/JSClassRegister.h index 9d1ab066a8d..f2c7d7078f7 100644 --- a/unity/native_src/Inc/JSClassRegister.h +++ b/unity/native_src/Inc/JSClassRegister.h @@ -8,8 +8,6 @@ #pragma once -#include "functional" - #if USING_IN_UNREAL_ENGINE #include "CoreMinimal.h" @@ -19,13 +17,10 @@ PRAGMA_DISABLE_UNDEFINED_IDENTIFIER_WARNINGS #pragma warning(pop) PRAGMA_ENABLE_UNDEFINED_IDENTIFIER_WARNINGS #else -#define JSENV_API #define FORCEINLINE V8_INLINE #define UPTRINT uintptr_t #endif -#include - #include "PuertsNamespaceDef.h" #include "pesapi.h" @@ -42,7 +37,7 @@ class CFunctionInfo; MSVC_PRAGMA(warning(push)) MSVC_PRAGMA(warning(disable : 4191)) -struct JSENV_API JSFunctionInfo +struct REGISTER_API JSFunctionInfo { JSFunctionInfo() : Name(nullptr), Callback(nullptr) { @@ -67,7 +62,7 @@ struct JSENV_API JSFunctionInfo const CFunctionInfo* ReflectionInfo = nullptr; }; -struct JSENV_API JSPropertyInfo +struct REGISTER_API JSPropertyInfo { JSPropertyInfo() : Name(nullptr), Getter(nullptr), Setter(nullptr) { @@ -100,7 +95,7 @@ struct JSENV_API JSPropertyInfo struct NamedFunctionInfo; struct NamedPropertyInfo; -struct JSENV_API JSClassDefinition +struct REGISTER_API JSClassDefinition { const void* TypeId; const void* SuperTypeId; @@ -134,22 +129,24 @@ MSVC_PRAGMA(warning(pop)) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \ } -void JSENV_API RegisterJSClass(const JSClassDefinition& ClassDefinition); +void REGISTER_API RegisterJSClass(const JSClassDefinition& ClassDefinition); -void JSENV_API SetClassTypeInfo(const void* TypeId, const NamedFunctionInfo* ConstructorInfos, const NamedFunctionInfo* MethodInfos, +void REGISTER_API SetClassTypeInfo(const void* TypeId, const NamedFunctionInfo* ConstructorInfos, const NamedFunctionInfo* MethodInfos, const NamedFunctionInfo* FunctionInfos, const NamedPropertyInfo* PropertyInfos, const NamedPropertyInfo* VariableInfos); -void JSENV_API ForeachRegisterClass(std::function); +typedef void (*ClassDefinitionForeachCallback)(const JSClassDefinition* ClassDefinition); + +void REGISTER_API ForeachRegisterClass(ClassDefinitionForeachCallback Callback); -JSENV_API const JSClassDefinition* FindClassByID(const void* TypeId); +REGISTER_API const JSClassDefinition* FindClassByID(const void* TypeId); -JSENV_API void OnClassNotFound(pesapi_class_not_found_callback Callback); +REGISTER_API void OnClassNotFound(pesapi_class_not_found_callback Callback); -JSENV_API const JSClassDefinition* LoadClassByID(const void* TypeId); +REGISTER_API const JSClassDefinition* LoadClassByID(const void* TypeId); -JSENV_API const JSClassDefinition* FindCppTypeClassByName(const PString& Name); +REGISTER_API const JSClassDefinition* FindCppTypeClassByName(const PString& Name); -JSENV_API bool TraceObjectLifecycle(const void* TypeId, pesapi_on_native_object_enter OnEnter, pesapi_on_native_object_exit OnExit); +REGISTER_API bool TraceObjectLifecycle(const void* TypeId, pesapi_on_native_object_enter OnEnter, pesapi_on_native_object_exit OnExit); #if USING_IN_UNREAL_ENGINE typedef void (*AddonRegisterFunc)(v8::Local Context, v8::Local Exports); @@ -158,9 +155,9 @@ AddonRegisterFunc FindAddonRegisterFunc(const PString& Name); void RegisterAddon(const char* Name, AddonRegisterFunc RegisterFunc); -JSENV_API const JSClassDefinition* FindClassByType(UStruct* Type); +REGISTER_API const JSClassDefinition* FindClassByType(UStruct* Type); -JSENV_API bool IsEditorOnlyUFunction(const UFunction* Func); +REGISTER_API bool IsEditorOnlyUFunction(const UFunction* Func); #endif diff --git a/unity/native_src/Inc/PString.h b/unity/native_src/Inc/PString.h index 3ebd183b261..3df53567cef 100644 --- a/unity/native_src/Inc/PString.h +++ b/unity/native_src/Inc/PString.h @@ -8,8 +8,7 @@ #pragma once -#include -#include +#include #include "NamespaceDef.h" namespace PUERTS_NAMESPACE @@ -18,9 +17,9 @@ class PString { public: // Constructors - PString() : data_(nullptr), size_(0) + PString() noexcept: data_(nullptr), size_(0) { - data_ = new char[1]; + data_ = (char*)malloc(1); data_[0] = '\0'; } @@ -28,8 +27,8 @@ class PString { if (str) { - size_ = std::strlen(str); - data_ = new char[size_ + 1]; + size_ = strlen(str); + data_ = (char*)malloc(size_ + 1); #ifdef _MSC_VER strncpy_s(data_, size_ + 1, str, size_); #else @@ -40,7 +39,7 @@ class PString else { size_ = 0; - data_ = new char[1]; + data_ = (char*)malloc(1); data_[0] = '\0'; } } @@ -50,7 +49,7 @@ class PString if (str) { size_ = length; - data_ = new char[size_ + 1]; + data_ = (char*)malloc(size_ + 1); #ifdef _MSC_VER strncpy_s(data_, size_ + 1, str, length); #else @@ -61,15 +60,15 @@ class PString else { size_ = 0; - data_ = new char[1]; + data_ = (char*)malloc(1); data_[0] = '\0'; } } - PString(const PString& other) + PString(const PString& other) noexcept { size_ = other.size_; - data_ = new char[size_ + 1]; + data_ = (char*)malloc(size_ + 1); #ifdef _MSC_VER strncpy_s(data_, size_ + 1, other.data_, size_); #else @@ -78,13 +77,13 @@ class PString data_[size_] = '\0'; } - PString& operator=(const PString& other) + PString& operator=(const PString& other) noexcept { if (this != &other) { - delete[] data_; + free(data_); size_ = other.size_; - data_ = new char[size_ + 1]; + data_ = (char*)malloc(size_ + 1); #ifdef _MSC_VER strncpy_s(data_, size_ + 1, other.data_, size_); #else @@ -95,17 +94,17 @@ class PString return *this; } - ~PString() + ~PString() noexcept { - delete[] data_; + free(data_); } PString operator+(const PString& other) const { PString result; result.size_ = size_ + other.size_; - delete[] result.data_; - result.data_ = new char[result.size_ + 1]; + free(result.data_); + result.data_ = (char*)malloc(result.size_ + 1); #ifdef _MSC_VER strncpy_s(result.data_, result.size_ + 1, data_, size_); strncpy_s(result.data_ + size_, result.size_ - size_ + 1, other.data_, other.size_); @@ -120,10 +119,10 @@ class PString friend PString operator+(const char* lhs, const PString& rhs) { PString result; - size_t lhs_size = std::strlen(lhs); + size_t lhs_size = strlen(lhs); result.size_ = lhs_size + rhs.size_; - delete[] result.data_; - result.data_ = new char[result.size_ + 1]; + free(result.data_); + result.data_ = (char*)malloc(result.size_ + 1); #ifdef _MSC_VER strncpy_s(result.data_, result.size_ + 1, lhs, lhs_size); strncpy_s(result.data_ + lhs_size, result.size_ - lhs_size + 1, rhs.data_, rhs.size_); @@ -138,7 +137,7 @@ class PString PString& operator+=(const PString& other) { size_t new_size = size_ + other.size_; - char* new_data = new char[new_size + 1]; + char* new_data = (char*)malloc(new_size + 1); #ifdef _MSC_VER strncpy_s(new_data, new_size + 1, data_, size_); strncpy_s(new_data + size_, new_size - size_ + 1, other.data_, other.size_); @@ -148,7 +147,7 @@ class PString #endif new_data[new_size] = '\0'; - delete[] data_; + free(data_); data_ = new_data; size_ = new_size; @@ -159,9 +158,9 @@ class PString { if (str) { - size_t str_size = std::strlen(str); + size_t str_size = strlen(str); size_t new_size = size_ + str_size; - char* new_data = new char[new_size + 1]; + char* new_data = (char*)malloc(new_size + 1); #ifdef _MSC_VER strncpy_s(new_data, new_size + 1, data_, size_); strncpy_s(new_data + size_, new_size - size_ + 1, str, str_size); @@ -171,7 +170,7 @@ class PString #endif new_data[new_size] = '\0'; - delete[] data_; + free(data_); data_ = new_data; size_ = new_size; } @@ -195,12 +194,12 @@ class PString bool operator<(const PString& other) const { - return std::strcmp(data_, other.data_) < 0; + return strcmp(data_, other.data_) < 0; } bool operator==(const PString& other) const { - return std::strcmp(data_, other.data_) == 0; + return strcmp(data_, other.data_) == 0; } private: diff --git a/unity/native_src/Inc/PuertsNamespaceDef.h b/unity/native_src/Inc/PuertsNamespaceDef.h index 7cb5b165163..8f6ff75e0b5 100644 --- a/unity/native_src/Inc/PuertsNamespaceDef.h +++ b/unity/native_src/Inc/PuertsNamespaceDef.h @@ -44,3 +44,36 @@ #define MSVC_PRAGMA(...) #endif #endif + +#if defined(__clang__) +# define PUERTS_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility)) +#elif defined(__GNUC__) +# define PUERTS_HAS_ATTRIBUTE_VISIBILITY 1 +#else +# define PUERTS_HAS_ATTRIBUTE_VISIBILITY 0 +#endif + +#ifndef REGISTER_API +#ifdef _MSC_VER +#ifdef BUILDING_REGISTER_API_SHARED +# define REGISTER_API __declspec(dllexport) +#elif USING_REGISTER_API_SHARED +# define REGISTER_API __declspec(dllimport) +#else +# define REGISTER_API +#endif // BUILDING_V8_SHARED + +#else // _MSC_VER + +#if PUERTS_HAS_ATTRIBUTE_VISIBILITY +# ifdef BUILDING_REGISTER_API_SHARED +# define REGISTER_API __attribute__ ((visibility("default"))) +# else +# define REGISTER_API +# endif +#else +# define REGISTER_API +#endif + +#endif // _MSC_VER +#endif diff --git a/unity/native_src/Inc/TypeInfo.hpp b/unity/native_src/Inc/TypeInfo.hpp index 2400fd95ed2..4e42233e597 100644 --- a/unity/native_src/Inc/TypeInfo.hpp +++ b/unity/native_src/Inc/TypeInfo.hpp @@ -8,6 +8,7 @@ #pragma once +#include #include #ifdef WITH_V8_FAST_CALL #include "V8FastCall.hpp" From 356030ddf6ed5fc36ff9cff40af564b4c36d67f8 Mon Sep 17 00:00:00 2001 From: johnche Date: Wed, 26 Feb 2025 15:50:52 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[unity]=E7=BC=96=E8=AF=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- unity/native_src/Inc/DataTransfer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unity/native_src/Inc/DataTransfer.h b/unity/native_src/Inc/DataTransfer.h index a69e4d36f49..27d50b7fc62 100644 --- a/unity/native_src/Inc/DataTransfer.h +++ b/unity/native_src/Inc/DataTransfer.h @@ -235,7 +235,7 @@ struct TOuterLinker::Get)>> }; #endif -class JSENV_API DataTransfer +class REGISTER_API DataTransfer { public: FORCEINLINE static void* MakeAddressWithHighPartOfTwo(void* Address1, void* Address2)