Refactor managed array unboxing to handle case of C# array passes as object
#1415
This commit is contained in:
@@ -85,6 +85,7 @@ public:
|
||||
static MClass* GetClass(MClass* elementKlass);
|
||||
static int32 GetLength(const MArray* obj);
|
||||
static void* GetAddress(const MArray* obj);
|
||||
static MArray* Unbox(MObject* obj);
|
||||
|
||||
template<typename T>
|
||||
FORCE_INLINE static T* GetAddress(const MArray* obj)
|
||||
|
||||
@@ -363,11 +363,12 @@ struct MConverter<Array<T>>
|
||||
|
||||
void Unbox(Array<T>& result, MObject* data)
|
||||
{
|
||||
const int32 length = data ? MCore::Array::GetLength((MArray*)data) : 0;
|
||||
MArray* array = MCore::Array::Unbox(data);
|
||||
const int32 length = array ? MCore::Array::GetLength(array) : 0;
|
||||
result.Resize(length);
|
||||
MConverter<T> converter;
|
||||
Span<T> resultSpan(result.Get(), length);
|
||||
converter.ToNativeArray(resultSpan, (MArray*)data);
|
||||
converter.ToNativeArray(resultSpan, array);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -408,6 +408,12 @@ void* MCore::Array::GetAddress(const MArray* obj)
|
||||
return CallStaticMethod<void*, void*>(GetArrayPointerPtr, (void*)obj);
|
||||
}
|
||||
|
||||
MArray* MCore::Array::Unbox(MObject* obj)
|
||||
{
|
||||
static void* GetArrayPtr = GetStaticMethodPointer(TEXT("GetArray"));
|
||||
return (MArray*)CallStaticMethod<void*, void*>(GetArrayPtr, (void*)obj);
|
||||
}
|
||||
|
||||
MGCHandle MCore::GCHandle::New(MObject* obj, bool pinned)
|
||||
{
|
||||
ASSERT(obj);
|
||||
|
||||
@@ -804,6 +804,11 @@ void* MCore::Array::GetAddress(const MArray* obj)
|
||||
return mono_array_addr_with_size((MonoArray*)obj, 0, 0);
|
||||
}
|
||||
|
||||
MArray* MCore::Array::Unbox(MObject* obj)
|
||||
{
|
||||
return (MArray*)obj;
|
||||
}
|
||||
|
||||
MGCHandle MCore::GCHandle::New(MObject* obj, bool pinned)
|
||||
{
|
||||
return mono_gchandle_new(obj, pinned);
|
||||
|
||||
@@ -141,6 +141,11 @@ void* MCore::Array::GetAddress(const MArray* obj)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MArray* MCore::Array::Unbox(MObject* obj)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MGCHandle MCore::GCHandle::New(MObject* obj, bool pinned)
|
||||
{
|
||||
return (MGCHandle)(uintptr)obj;
|
||||
|
||||
Reference in New Issue
Block a user