From 9de1c1317cba6477ac806ecaac8452274943c4c5 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Thu, 10 Sep 2026 19:41:01 +0100 Subject: [PATCH] Fix haxe 4 compile time regressions --- include/cpp/Pointer.h | 6 +++++- include/cpp/marshal/Definitions.inc | 26 +---------------------- include/cpp/marshal/View.hpp | 33 ++++++++++++++++++++++++++++- include/hx/LessThanEq.h | 12 +++++++++++ include/hx/zip/Zip.hpp | 4 +++- include/hxString.h | 4 ++++ include/hxcpp.h | 26 ++++++++++++----------- src/String.cpp | 8 +++++++ src/cpp/encoding/Encodings.cpp | 4 ++++ src/hx/thread/Scratch.cpp | 6 +++++- 10 files changed, 88 insertions(+), 41 deletions(-) diff --git a/include/cpp/Pointer.h b/include/cpp/Pointer.h index 582947cba..95564ed88 100644 --- a/include/cpp/Pointer.h +++ b/include/cpp/Pointer.h @@ -215,7 +215,10 @@ class Pointer hx::Object *obj = inVariant.asObject(); ptr = obj ? (T*)inVariant.valObject->__GetHandle() : 0; } + +#if (HXCPP_API_LEVEL >= 500) inline Pointer(const ::cpp::marshal::PointerReference); +#endif template inline Pointer( const O *inValue ) : ptr( (T*) inValue) { } @@ -512,12 +515,13 @@ class Pointer_obj return AutoCast(base->GetBase()); } - +#if (HXCPP_API_LEVEL >= 500) template inline static Pointer addressOf(const ::cpp::marshal::ValueReference&); template inline static Pointer addressOf(const ::cpp::marshal::PointerReference&); +#endif template inline static Pointer addressOf(T &value) { return Pointer(&value); } diff --git a/include/cpp/marshal/Definitions.inc b/include/cpp/marshal/Definitions.inc index ffd5f14b2..efeacce20 100644 --- a/include/cpp/marshal/Definitions.inc +++ b/include/cpp/marshal/Definitions.inc @@ -189,30 +189,6 @@ namespace cpp void set(int64_t index, K value); }; - template - struct View final - { - ::cpp::Pointer ptr; - int64_t length; - - View(::cpp::Pointer _ptr, int64_t _length); - - void clear() const; - void fill(T value) const; - bool isEmpty() const; - View slice(int64_t index) const; - View slice(int64_t index, int64_t length) const; - void copyTo(const View& destination) const; - bool tryCopyTo(const View& destination) const; - template View reinterpret() const; - int compare(const View& inRHS) const; - - bool operator==(const View& inRHS) const; - bool operator!=(const View& inRHS) const; - - T& operator[] (int64_t index) const; - }; - class RootHandle { ::hx::Object** object; @@ -327,4 +303,4 @@ template inline cpp::Pointer::Pointer(const ::cpp::marshal::PointerReference ref) { ptr = *ref.ptr; -} \ No newline at end of file +} diff --git a/include/cpp/marshal/View.hpp b/include/cpp/marshal/View.hpp index d60fd587a..6c06e6b84 100644 --- a/include/cpp/marshal/View.hpp +++ b/include/cpp/marshal/View.hpp @@ -1,6 +1,37 @@ #pragma once -#include "Definitions.inc" +#include +#include + +namespace cpp { +namespace marshal { + +template +struct View final { + ::cpp::Pointer ptr; + int64_t length; + + View(::cpp::Pointer _ptr, int64_t _length); + + void clear() const; + void fill(T value) const; + bool isEmpty() const; + View slice(int64_t index) const; + View slice(int64_t index, int64_t length) const; + void copyTo(const View& destination) const; + bool tryCopyTo(const View& destination) const; + template View reinterpret() const; + int compare(const View& inRHS) const; + + bool operator==(const View& inRHS) const; + bool operator!=(const View& inRHS) const; + + T& operator[] (int64_t index) const; +}; + +}; +}; + #include #include diff --git a/include/hx/LessThanEq.h b/include/hx/LessThanEq.h index 209f69b81..07fcddc01 100644 --- a/include/hx/LessThanEq.h +++ b/include/hx/LessThanEq.h @@ -246,6 +246,8 @@ struct CompareTraits< T * > inline static bool isNull(T *inValue) { return !inValue; } }; +#if (HXCPP_API_LEVEL>=500) + template struct CompareTraits< cpp::marshal::ValueReference > { @@ -274,6 +276,8 @@ struct CompareTraits< cpp::marshal::PointerReference > inline static bool isNull(const ::cpp::marshal::PointerReference& ref) { return nullptr == ref.ptr || nullptr == *ref.ptr; } }; +#endif + template hx::Object *GetExistingObject(const T1 &v1) { @@ -437,6 +441,8 @@ inline bool TestLessEq(const T1 &v1, const T2 &v2) template bool IsEq(const T1 &v1, const T2 &v2) { return TestLessEq(v1,v2); } +#if (HXCPP_API_LEVEL>=500) + template bool IsEq(const ::cpp::marshal::ValueReference& v1, const ::cpp::marshal::ValueReference& v2) { return v1 == v2; } @@ -459,15 +465,21 @@ bool IsEq(const ::cpp::marshal::PointerReference& v1, const ::cpp::marshal:: return *v1.ptr == *v2.ptr; } +#endif + template bool IsNotEq(const T1 &v1, const T2 &v2) { return TestLessEq(v1,v2); } +#if (HXCPP_API_LEVEL>=500) + template bool IsNotEq(const ::cpp::marshal::ValueReference& v1, const ::cpp::marshal::ValueReference& v2) { return v1 != v2; } template bool IsNotEq(const ::cpp::marshal::PointerReference& v1, const ::cpp::marshal::PointerReference& v2) { return IsEq(v1, v2) == false; } +#endif + template bool IsLess(const T1 &v1, const T2 &v2) { return TestLessEq(v1,v2); } diff --git a/include/hx/zip/Zip.hpp b/include/hx/zip/Zip.hpp index 4b3342f3a..c5e7321c4 100644 --- a/include/hx/zip/Zip.hpp +++ b/include/hx/zip/Zip.hpp @@ -4,6 +4,8 @@ #include #endif +#include + HX_DECLARE_CLASS2(hx, zip, Zip) namespace hx @@ -33,4 +35,4 @@ namespace hx virtual void close() = 0; }; } -} \ No newline at end of file +} diff --git a/include/hxString.h b/include/hxString.h index 5fd402561..b12ad174e 100644 --- a/include/hxString.h +++ b/include/hxString.h @@ -47,8 +47,10 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES String static String create(const char16_t *inPtr,int inLen=-1); static String create(const char *inPtr,int inLen=-1); +#if (HXCPP_API_LEVEL >= 500) static String create(const ::cpp::marshal::View& buffer); static String create(const ::cpp::marshal::View& buffer); +#endif // Uses non-gc memory and wont ever be collected static ::String createPermanent(const char *inUtf8, int inLen); @@ -174,8 +176,10 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES String const wchar_t *wchar_str(hx::IStringAlloc *inBuffer = 0) const; const char16_t *wc_str(hx::IStringAlloc *inBuffer = 0, int *outCharLength = 0) const; +#if (HXCPP_API_LEVEL >= 500) bool wc_str(::cpp::marshal::View buffer, int* outCharLength = nullptr) const; bool utf8_str(::cpp::marshal::View buffer, int* outByteLength = nullptr) const; +#endif const char *__CStr() const { return utf8_str(); }; const wchar_t *__WCStr() const { return wchar_str(0); } diff --git a/include/hxcpp.h b/include/hxcpp.h index 3e93511e4..3942cb915 100755 --- a/include/hxcpp.h +++ b/include/hxcpp.h @@ -261,6 +261,7 @@ namespace hx { template class ObjectPtr; } namespace cpp { template class Struct; } namespace cpp { template class Pointer; } namespace cpp { template class Function; } +#if (HXCPP_API_LEVEL>=500) namespace cpp { namespace marshal { template class Boxed_obj; } } namespace cpp { namespace marshal { template using Boxed =::hx::ObjectPtr>; } } namespace cpp { namespace marshal { template class ValueType; } } @@ -268,6 +269,7 @@ namespace cpp { namespace marshal { template class ValueReference; } } namespace cpp { namespace marshal { template class PointerType; } } namespace cpp { namespace marshal { template class PointerReference; } } namespace cpp { namespace marshal { template struct View; } } +#endif template class Array_obj; template class Array; namespace hx { @@ -360,21 +362,21 @@ typedef PropertyAccessMode PropertyAccess; #endif #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include #if (HXCPP_API_LEVEL>=500) -#include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include #endif // second time ... #include diff --git a/src/String.cpp b/src/String.cpp index 1583ea238..11c1f2c3c 100644 --- a/src/String.cpp +++ b/src/String.cpp @@ -790,6 +790,8 @@ String String::create(const char *inString,int inLength) return String(s,len); } +#if (HXCPP_API_LEVEL>=500) + String String::create(const::cpp::marshal::View& buffer) { auto start = buffer.ptr.ptr; @@ -826,6 +828,8 @@ String String::create(const cpp::marshal::View& buffer) return String::create(buffer.ptr.ptr, buffer.length - (end - start) - extra); } +#endif + String::String(const Dynamic &inRHS) { if (inRHS.GetPtr()) @@ -1800,6 +1804,8 @@ const char16_t * String::wc_str(hx::IStringAlloc *inBuffer, int *outCharLength) return str; } +#if (HXCPP_API_LEVEL>=500) + bool String::wc_str(::cpp::marshal::View buffer, int* outCharLength) const { #ifdef HX_SMART_STRINGS @@ -1922,6 +1928,8 @@ bool String::utf8_str(::cpp::marshal::View buffer, int* outByteLength) con return true; } +#endif + const wchar_t * String::wchar_str(hx::IStringAlloc *inBuffer) const { if (!__s) diff --git a/src/cpp/encoding/Encodings.cpp b/src/cpp/encoding/Encodings.cpp index 4451d384b..ade6e088a 100644 --- a/src/cpp/encoding/Encodings.cpp +++ b/src/cpp/encoding/Encodings.cpp @@ -1,4 +1,6 @@ #include + +#if (HXCPP_API_LEVEL>=500) #include using namespace cpp::marshal; @@ -652,3 +654,5 @@ inline char32_t cpp::encoding::Utf16::codepoint(const cpp::marshal::View(first); } } + +#endif diff --git a/src/hx/thread/Scratch.cpp b/src/hx/thread/Scratch.cpp index d6ca33cf9..bef743498 100644 --- a/src/hx/thread/Scratch.cpp +++ b/src/hx/thread/Scratch.cpp @@ -1,4 +1,6 @@ #include + +#if (HXCPP_API_LEVEL>=500) #include #include "ThreadImpl.hpp" @@ -71,4 +73,6 @@ hx::thread::Scratch& hx::thread::Scratch::operator=(const Scratch& _other) } return *this; -} \ No newline at end of file +} + +#endif