Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marshalling Types #1189

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 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
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
649 changes: 649 additions & 0 deletions include/cpp/Marshal.h

Large diffs are not rendered by default.

7 changes: 6 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 @@ -509,6 +512,8 @@ class Pointer_obj
}


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

template<typename T>
inline static Pointer<T> addressOf(T &value) { return Pointer<T>(&value); }
Expand Down
55 changes: 55 additions & 0 deletions include/hx/LessThanEq.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,33 @@ struct CompareTraits< T * >
inline static bool isNull(T *inValue) { return !inValue; }
};

template <typename T>
struct CompareTraits< cpp::marshal::ValueReference<T> >
{
enum { type = (int)CompareAsDynamic };

inline static int toInt(Dynamic inValue) { return inValue; }
inline static double toDouble(Dynamic inValue) { return inValue; }
inline static cpp::Int64 toInt64(Dynamic inValue) { return inValue; }
inline static String toString(Dynamic inValue) { return inValue; }
inline static hx::Object* toObject(Dynamic inValue) { return inValue.mPtr; }
inline static int getDynamicCompareType(const ::Dynamic&) { return type; }
inline static bool isNull(const ::cpp::marshal::ValueReference<T>& ref) { return nullptr == ref.ptr; }
};

template <typename T>
struct CompareTraits< cpp::marshal::PointerReference<T> >
{
enum { type = (int)CompareAsDynamic };

inline static int toInt(Dynamic inValue) { return inValue; }
inline static double toDouble(Dynamic inValue) { return inValue; }
inline static cpp::Int64 toInt64(Dynamic inValue) { return inValue; }
inline static String toString(Dynamic inValue) { return inValue; }
inline static hx::Object* toObject(Dynamic inValue) { return inValue.mPtr; }
inline static int getDynamicCompareType(const ::Dynamic&) { return type; }
inline static bool isNull(const ::cpp::marshal::PointerReference<T>& ref) { return nullptr == ref.ptr || nullptr == *ref.ptr; }
};

template<typename T1>
hx::Object *GetExistingObject(const T1 &v1)
Expand Down Expand Up @@ -410,9 +437,37 @@ inline bool TestLessEq(const T1 &v1, const T2 &v2)
template<typename T1, typename T2>
bool IsEq(const T1 &v1, const T2 &v2) { return TestLessEq<false,true,T1,T2>(v1,v2); }

template<typename T1, typename T2>
bool IsEq(const ::cpp::marshal::ValueReference<T1>& v1, const ::cpp::marshal::ValueReference<T2>& v2) { return v1 == v2; }

template<typename T1, typename T2>
bool IsEq(const ::cpp::marshal::PointerReference<T1>& v1, const ::cpp::marshal::PointerReference<T2>& v2)
{
if (nullptr == v1.ptr && nullptr == v2.ptr)
{
return true;
}
if (nullptr == v1.ptr && nullptr != v2.ptr)
{
return nullptr == *v2.ptr;
}
if (nullptr == v2.ptr && nullptr != v1.ptr)
{
return nullptr == *v1.ptr;
}

return *v1.ptr == *v2.ptr;
}

template<typename T1, typename T2>
bool IsNotEq(const T1 &v1, const T2 &v2) { return TestLessEq<false,false,T1,T2>(v1,v2); }

template<typename T1, typename T2>
bool IsNotEq(const ::cpp::marshal::ValueReference<T1>& v1, const ::cpp::marshal::ValueReference<T2>& v2) { return v1 != v2; }

template<typename T1, typename T2>
bool IsNotEq(const ::cpp::marshal::PointerReference<T1>& v1, const ::cpp::marshal::PointerReference<T2>& v2) { return IsEq(v1, v2) == false; }

template<typename T1, typename T2>
bool IsLess(const T1 &v1, const T2 &v2) { return TestLessEq<true,false,T1,T2>(v1,v2); }

Expand Down
7 changes: 7 additions & 0 deletions include/hxcpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ namespace hx { template<typename O> class ObjectPtr; }
namespace cpp { template<typename S,typename H> class Struct; }
namespace cpp { template<typename T> class Pointer; }
namespace cpp { template<typename T> class Function; }
namespace cpp { namespace marshal { template<class T> class Boxed_obj; } }
namespace cpp { namespace marshal { template<class T> using Boxed =::hx::ObjectPtr<Boxed_obj<T>>; } }
namespace cpp { namespace marshal { template<class T> class ValueType; } }
namespace cpp { namespace marshal { template<class T> class ValueReference; } }
namespace cpp { namespace marshal { template<class T> class PointerType; } }
namespace cpp { namespace marshal { template<class T> class PointerReference; } }
template<typename ELEM_> class Array_obj;
template<typename ELEM_> class Array;
namespace hx {
Expand Down Expand Up @@ -348,6 +354,7 @@ typedef PropertyAccessMode PropertyAccess;
#endif
#include <hx/StdLibs.h>
#include <cpp/Pointer.h>
#include <cpp/Marshal.h>
#include <hx/Native.h>
#include <hx/Operators.h>
#include <hx/Functions.h>
Expand Down
10 changes: 10 additions & 0 deletions test/RunTests.hx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ class RunTests

}

public static function marshalling()
{
setDir("marshalling");

command("haxe", [ "build.hxml" ]);
command("bin" + sep + "Main-debug", []);
}

public static function debugger()
{
Expand Down Expand Up @@ -188,6 +195,9 @@ class RunTests
//run("opMatrix", opMatrix);
run("haxe", runHaxe);
run("telemetry", runTelemetry);
#if (haxe_ver >= 5)
run("marshalling", marshalling);
#end
run("std32", std32);
run("std64", std64);
run("native", native);
Expand Down
32 changes: 31 additions & 1 deletion test/native/Native.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package;

#if (haxe_ver>=5)
@:buildXml("<include name='${this_dir}/../tests/marshalling/Build.xml'/>")
#end
class Native
{
static function main()
Expand All @@ -12,7 +15,34 @@ class Native
new tests.TestNativeGen(),
new tests.TestNonVirtual(),
new tests.TestPtr(),
new tests.TestNativeEnum()
new tests.TestNativeEnum(),

#if (haxe_ver>=5)
new tests.marshalling.classes.TestLocalValueType(),
new tests.marshalling.classes.TestClassValueType(),
new tests.marshalling.classes.TestInterfaceValueType(),
new tests.marshalling.classes.TestEnumValueType(),
new tests.marshalling.classes.TestAbstractValueType(),
new tests.marshalling.classes.TestValueTypeInterop(),
new tests.marshalling.classes.TestValueTypeCollections(),
new tests.marshalling.classes.TestValueTypeFields(),
new tests.marshalling.classes.TestInheritance(),
new tests.marshalling.enums.TestValueTypeEnumAbstract(),
new tests.marshalling.enums.TestValueTypeEnumClassAbstract(),
new tests.marshalling.pointers.TestLocalPointers(),
new tests.marshalling.pointers.TestClassPointers(),
new tests.marshalling.pointers.TestInterfacePointers(),
new tests.marshalling.pointers.TestInheritancePointers(),
new tests.marshalling.pointers.TestEnumPointers(),
new tests.marshalling.pointers.TestPointerFields(),
new tests.marshalling.pointers.TestPointerCollections(),
new tests.marshalling.pointers.TestAbstractPointer(),
new tests.marshalling.pointers.TestPointerInterop(),
new tests.marshalling.managed.TestLocalNonStandardManagedClass(),
new tests.marshalling.managed.TestLocalStandardManagedClass(),
new tests.marshalling.managed.TestClassNonStandardManagedClass(),
new tests.marshalling.managed.TestClassStandardManagedClass()
#end
]);
}
}
2 changes: 1 addition & 1 deletion test/native/compile.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-m Native
-D HXCPP_DEBUGGER
-L utest
-D HXCPP-DEBUGGER
--cpp bin
Binary file added test/native/test.txt
Binary file not shown.
Loading
Loading