Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
5dfa55a
Add marshal header for value type interop
Aidan63 Dec 15, 2024
ec75e42
finalise boxed objects if the type has a destructor
Aidan63 Dec 15, 2024
b22a024
works with static cast
Aidan63 Dec 16, 2024
4bc2bcc
add value type tests
Aidan63 Dec 16, 2024
44d5a28
move more conversion functions to reference class
Aidan63 Dec 27, 2024
0457958
forward declare everything to avoid order issues
Aidan63 Dec 27, 2024
d718eca
ValueType construction from boxed pointer
Aidan63 Dec 27, 2024
ad7f101
ValueType no longer inherits from struct
Aidan63 Dec 30, 2024
937868a
marshal reference interop with existing pointer types
Aidan63 Jan 1, 2025
5b00db8
Fix trying to dereference a null pointer when creating a boxed object…
Aidan63 Jan 1, 2025
73d18dc
add compare traits specialisation for reference null check
Aidan63 Jan 1, 2025
d4e7dfe
consistent null checking and throwing
Aidan63 Jan 1, 2025
46e0cd3
raise exceptions when value types are assigned null
Aidan63 Jan 1, 2025
e7195b4
reference equality operations
Aidan63 Jan 4, 2025
f92c9a3
remove no return
Aidan63 Jan 4, 2025
b49440f
remove some un-needed constructors
Jan 5, 2025
7f133d3
Make constructors use more templates and use reinterpret cast
Jan 7, 2025
d86f57c
use tagged dispatch
Jan 7, 2025
9f8ab77
support pointer types being held in value type helper
Jan 10, 2025
cfb6fee
Add new marshal pointer type
Jan 11, 2025
23da6f1
rename marshal types in prep for more pointer stuff
Jan 11, 2025
de4c7ec
support reinterpreting value type references
Jan 12, 2025
8004100
seemingly working pointer marshalling types
Jan 16, 2025
5572364
better null checking with pointer references
Jan 19, 2025
2ffcf81
add marshalling tests
Jan 19, 2025
0978d5b
Add pointer collection tests
Jan 19, 2025
d2a9bcf
Move enums into header files
Jan 20, 2025
50301d3
test abstract around pointers
Jan 20, 2025
b1231af
Pointer type changes
Jan 24, 2025
20cb53e
add pointer reference to pointer casting
Jan 25, 2025
5b5cd49
add null test to pointer access
Jan 25, 2025
335fe71
add test for vector of value types
Aidan63 Jan 26, 2025
f2a5e24
add tests showing weird null behaviour
Jan 26, 2025
82abbb4
move marshalling tests to existing native tests
Jan 26, 2025
98c4344
Merge branch 'master' into valuetype-marshal
Jan 26, 2025
7a45f5c
initial managed extern tests
Feb 1, 2025
d4e2d54
managed extern local tests for two different naming schemes
Feb 2, 2025
1354a56
reduce test duplication
Feb 2, 2025
18846ff
Add tests for classes holding managed externs
Feb 2, 2025
e8ac070
change tests so that static functions are tested
Feb 2, 2025
7dbc2ad
un-private point
Feb 2, 2025
bf54265
let enum abstract include meta handle it
Aidan63 Feb 3, 2025
8eb9888
remove analyser meta
Aidan63 Feb 3, 2025
f5a78c3
Merge branch 'master' into valuetype-marshal
Feb 5, 2025
7fcb920
Fix test related to recent pointer changes
Mar 21, 2025
7dc4687
Merge branch 'master' into valuetype-marshal
Aidan63 Nov 8, 2025
f6ecf8f
Add pointer ctor overload
Aidan63 Nov 9, 2025
11bc870
view marshalling type
Nov 15, 2025
92aa55f
Change to value semantics
Aidan63 Nov 15, 2025
e655568
Add view tests
Aidan63 Nov 15, 2025
cc0fbcc
Update some tests
Aidan63 Nov 16, 2025
5f46ac6
String marshalling functions
Nov 16, 2025
5db27ce
Marshalling tests
Aidan63 Nov 16, 2025
6639d0c
Merge remote-tracking branch 'Aidan63/valuetype-marshal' into valuety…
Aidan63 Nov 16, 2025
d595c91
view based string creation and support char16_t in various hxcpp types
Nov 17, 2025
4dc482b
Marshalling string tests
Aidan63 Nov 17, 2025
e15836d
const ref a bit
Nov 17, 2025
6c64ea8
Merge remote-tracking branch 'origin/valuetype-marshal' into valuetyp…
Nov 17, 2025
4e706d4
Don't use byte size in copyTo comparison check
Nov 17, 2025
a8b47b5
view extension tests
Aidan63 Nov 17, 2025
f3d750a
Split across multiple headers
Nov 18, 2025
5f991de
typed read and write helper functions
Nov 18, 2025
40e7fa1
Add compare function
Nov 18, 2025
4e7bdb9
cstring to view conversion function, and allow null pointers
Nov 29, 2025
427e81c
Add view to pointer conversions
Nov 29, 2025
4e39395
View length is now size_t
Nov 30, 2025
3d7d9d4
Add endian specific read and write marshal functions
Aidan63 Dec 5, 2025
513330d
Add OOB checks
Dec 13, 2025
2603e8d
change the public api to use int64_t over size_t
Dec 13, 2025
14dc9b6
Fix string from view conversions to properly use the view length
Dec 13, 2025
a401f07
Add OOB exception tests
Aidan63 Dec 13, 2025
43fec7f
bound check read and write
Dec 13, 2025
c836e3a
make sure view write index is int64_t
Dec 13, 2025
6aac6da
Merge branch 'master' into valuetype-marshal
Dec 13, 2025
a18fca8
add tests for exceptions when reading or writing to small views
Aidan63 Dec 13, 2025
d315b3a
guard including new marshal headers
Dec 13, 2025
fe7ea65
fix dodgy conditional
Dec 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ template<> struct ReturnNull<double> { typedef Dynamic type; };
template<> struct ReturnNull<float> { typedef Dynamic type; };
template<> struct ReturnNull<bool> { typedef Dynamic type; };
template<> struct ReturnNull<char> { typedef Dynamic type; };
template<> struct ReturnNull<char16_t> { typedef Dynamic type; };
template<> struct ReturnNull<signed char> { typedef Dynamic type; };
template<> struct ReturnNull<unsigned char> { typedef Dynamic type; };
template<> struct ReturnNull<short> { typedef Dynamic type; };
Expand Down Expand Up @@ -431,6 +432,7 @@ template<> struct ArrayClassId<unsigned char> { enum { id=hx::clsIdArrayByte };
template<> struct ArrayClassId<signed char> { enum { id=hx::clsIdArrayByte }; };
template<> struct ArrayClassId<unsigned short> { enum { id=hx::clsIdArrayShort }; };
template<> struct ArrayClassId<signed short> { enum { id=hx::clsIdArrayShort }; };
template<> struct ArrayClassId<char16_t> { enum { id = hx::clsIdArrayShort }; };
template<> struct ArrayClassId<unsigned int> { enum { id=hx::clsIdArrayInt }; };
template<> struct ArrayClassId<signed int> { enum { id=hx::clsIdArrayInt }; };
template<> struct ArrayClassId<float> { enum { id=hx::clsIdArrayFloat32 }; };
Expand Down
8 changes: 8 additions & 0 deletions include/Dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
Dynamic(unsigned short inVal);
Dynamic(unsigned char inVal);
Dynamic(signed char inVal);
Dynamic(char16_t inVal);
Dynamic(const cpp::CppInt32__ &inVal);
Dynamic(bool inVal);
Dynamic(double inVal);
Expand Down Expand Up @@ -71,6 +72,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
inline operator unsigned char () const { return mPtr ? mPtr->__ToInt() : 0; }
inline operator char () const { return mPtr ? mPtr->__ToInt() : 0; }
inline operator signed char () const { return mPtr ? mPtr->__ToInt() : 0; }
inline operator char16_t () const { return mPtr ? mPtr->__ToInt() : 0; }
inline operator bool() const { return mPtr && mPtr->__ToInt(); }
inline operator cpp::Int64() const { return mPtr ? mPtr->__ToInt64() : 0; }
inline operator cpp::UInt64() const { return mPtr ? mPtr->__ToInt64() : 0; }
Expand Down Expand Up @@ -171,6 +173,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
bool operator op (unsigned short inRHS) const { return IsNumeric() && ((double)(*this) op (double)inRHS); } \
bool operator op (signed char inRHS) const { return IsNumeric() && ((double)(*this) op (double)inRHS); } \
bool operator op (unsigned char inRHS) const { return IsNumeric() && ((double)(*this) op (double)inRHS); } \
bool operator op (char16_t inRHS) const { return IsNumeric() && ((double)(*this) op (double)inRHS); } \
bool operator op (bool inRHS) const { return IsBool() && ((double)(*this) op (double)inRHS); } \

bool operator != (const String &inRHS) const { return !mPtr || ((String)(*this) != inRHS); }
Expand All @@ -184,6 +187,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
bool operator != (unsigned short inRHS) const { return !IsNumeric() || ((double)(*this) != (double)inRHS); }
bool operator != (signed char inRHS) const { return !IsNumeric() || ((double)(*this) != (double)inRHS); }
bool operator != (unsigned char inRHS) const { return !IsNumeric() || ((double)(*this) != (double)inRHS); }
bool operator != (char16_t inRHS) const { return !IsNumeric() || ((double)(*this) != (double)inRHS); }
bool operator != (bool inRHS) const { return !IsBool() || ((double)(*this) != (double)inRHS); }


Expand Down Expand Up @@ -229,6 +233,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
Dynamic operator+(const unsigned short &i) const;
Dynamic operator+(const signed char &i) const;
Dynamic operator+(const unsigned char &i) const;
Dynamic operator+(const char16_t& i) const;
Dynamic operator+(const double &d) const;
Dynamic operator+(const float &d) const;
Dynamic operator+(const cpp::Variant &d) const;
Expand Down Expand Up @@ -270,6 +275,8 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
{ return mPtr->__GetType()==vtInt ? Dynamic((int)(*this) op inRHS) : Dynamic((double)(*this) op inRHS); } \
Dynamic operator op (const unsigned char &inRHS) const \
{ return mPtr->__GetType()==vtInt ? Dynamic((int)(*this) op inRHS) : Dynamic((double)(*this) op inRHS); } \
Dynamic operator op (const char16_t &inRHS) const \
{ return mPtr->__GetType()==vtInt ? Dynamic((int)(*this) op inRHS) : Dynamic((double)(*this) op inRHS); } \
Dynamic operator op (const cpp::Int64 &inRHS) const \
{ return Dynamic((double)(*this) op inRHS); } \
Dynamic operator op (const cpp::UInt64 &inRHS) const \
Expand Down Expand Up @@ -457,6 +464,7 @@ COMPARE_DYNAMIC_OP( > )
inline double operator op (const unsigned short &inLHS,const Dynamic &inRHS) { return inLHS op (double)inRHS; } \
inline double operator op (const signed char &inLHS,const Dynamic &inRHS) { return inLHS op (double)inRHS; } \
inline double operator op (const unsigned char &inLHS,const Dynamic &inRHS) { return inLHS op (double)inRHS; } \
inline double operator op (const char16_t &inLHS,const Dynamic &inRHS) { return inLHS op (double)inRHS; } \

ARITH_DYNAMIC( - )
ARITH_DYNAMIC( + )
Expand Down
11 changes: 10 additions & 1 deletion include/cpp/Pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,15 @@ class Struct
// This allows 'StaticCast' to be used from arrays
typedef Dynamic Ptr;

inline Struct( ) { }
inline Struct( ) : value() { }
inline Struct( const T &inRHS ) : value(inRHS) { }
inline Struct( const null &) { value = T(); }
inline Struct( const Reference<T> &);
inline Struct( const Dynamic &inRHS) { fromDynamic(inRHS.mPtr); }

template<class... TArgs>
Struct(TArgs... args) : value(std::forward<TArgs>(args)...) {}

inline Struct<T,HANDLER> &operator=( const T &inRHS ) { value = inRHS; return *this; }
inline Struct<T,HANDLER> &operator=( const null & ) { value = T(); return *this; }
inline Struct<T,HANDLER> &operator=( const Dynamic &inRHS ) { return *this = Struct<T,HANDLER>(inRHS); }
Expand Down Expand Up @@ -212,6 +215,7 @@ class Pointer
hx::Object *obj = inVariant.asObject();
ptr = obj ? (T*)inVariant.valObject->__GetHandle() : 0;
}
inline Pointer(const ::cpp::marshal::PointerReference<T>);

template<typename O>
inline Pointer( const O *inValue ) : ptr( (T*) inValue) { }
Expand Down Expand Up @@ -509,6 +513,11 @@ class Pointer_obj
}


template<typename T>
inline static Pointer<T> addressOf(const ::cpp::marshal::ValueReference<T>&);

template<typename T>
inline static Pointer<T*> addressOf(const ::cpp::marshal::PointerReference<T>&);

template<typename T>
inline static Pointer<T> addressOf(T &value) { return Pointer<T>(&value); }
Expand Down
6 changes: 6 additions & 0 deletions include/cpp/Variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ namespace cpp
inline operator unsigned char () const { return asInt(); }
inline operator char () const { return asInt(); }
inline operator signed char () const { return asInt(); }
inline operator char16_t() const { return asInt(); }
inline operator cpp::Int64 () const { return asInt64(); }
inline operator cpp::UInt64 () const { return asInt64(); }
inline bool operator !() const { return !asInt(); }
Expand Down Expand Up @@ -206,6 +207,7 @@ namespace cpp
inline bool operator op (unsigned short inRHS) const { return isNumeric() && (asDouble() op (double)inRHS); } \
inline bool operator op (signed char inRHS) const { return isNumeric() && (asDouble() op (double)inRHS); } \
inline bool operator op (unsigned char inRHS) const { return isNumeric() && (asDouble() op (double)inRHS); } \
inline bool operator op (char16_t inRHS) const { return isNumeric() && (asDouble() op (double)inRHS); } \
inline bool operator op (bool inRHS) const { return isBool() && (asDouble() op (double)inRHS); } \
inline bool operator op (const Dynamic &inRHS) const { return Compare(inRHS) op 0; } \

Expand Down Expand Up @@ -278,6 +280,7 @@ namespace cpp
inline double operator op (const unsigned int &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
inline double operator op (const signed char &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
inline double operator op (const unsigned char &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
inline double operator op (const char16_t &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
inline double operator op (const signed short &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
inline double operator op (const unsigned short &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
inline double operator op (const cpp::Int64 &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
Expand Down Expand Up @@ -604,6 +607,7 @@ HX_VARIANT_OP_ISEQ(short)
HX_VARIANT_OP_ISEQ(unsigned short)
HX_VARIANT_OP_ISEQ(signed char)
HX_VARIANT_OP_ISEQ(unsigned char)
HX_VARIANT_OP_ISEQ(char16_t)
HX_VARIANT_OP_ISEQ(bool)

inline bool operator < (bool inLHS,const cpp::Variant &inRHS) { return false; }
Expand Down Expand Up @@ -633,6 +637,8 @@ inline bool operator > (bool inLHS,const cpp::Variant &inRHS) { return false; }
{ return inRHS.isNumeric() && (inLHS op (double)inRHS); } \
inline bool operator op (unsigned char inLHS,const ::cpp::Variant &inRHS) \
{ return inRHS.isNumeric() && (inLHS op (double)inRHS); } \
inline bool operator op (char16_t inLHS,const ::cpp::Variant &inRHS) \
{ return inRHS.isNumeric() && (inLHS op (double)inRHS); } \
inline bool operator op (const null &,const ::cpp::Variant &inRHS) \
{ return false; } \

Expand Down
39 changes: 39 additions & 0 deletions include/cpp/marshal/Boxed.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include "Definitions.inc"

template<class T>
inline void cpp::marshal::Boxed_obj<T>::finalise(::hx::Object* obj)
{
auto ptr = reinterpret_cast<Boxed_obj<T>*>(obj);

ptr->value.~T();
}

template<class T>
inline void cpp::marshal::Boxed_obj<T>::setFinaliser(std::true_type)
{
::hx::GCSetFinalizer(this, finalise);
}

template<class T>
inline void cpp::marshal::Boxed_obj<T>::setFinaliser(std::false_type) {}

template<class T>
inline cpp::marshal::Boxed_obj<T>::Boxed_obj() : value()
{
setFinaliser(std::is_destructible<T>{});
}

template<class T>
inline cpp::marshal::Boxed_obj<T>::Boxed_obj(T* ptr) : value(*ptr)
{
setFinaliser(std::is_destructible<T>{});
}

template<class T>
template<class ...TArgs>
inline cpp::marshal::Boxed_obj<T>::Boxed_obj(TArgs... args) : value(std::forward<TArgs>(args)...)
{
setFinaliser(std::is_destructible<T>{});
}
Loading
Loading