- fixed: Dynamic arrays for object pointers need different treatment than arrays for regular pointers, because they require GC::WriteBarrier to be called.

This commit is contained in:
Christoph Oelckers 2018-01-19 19:48:55 +01:00
parent f629678320
commit 19cf887ad1
3 changed files with 131 additions and 1 deletions

View file

@ -51,6 +51,7 @@ typedef TArray<uint32_t> FDynArray_I32;
typedef TArray<float> FDynArray_F32;
typedef TArray<double> FDynArray_F64;
typedef TArray<void*> FDynArray_Ptr;
typedef TArray<DObject*> FDynArray_Obj;
typedef TArray<FString> FDynArray_String;
//-----------------------------------------------------
@ -672,6 +673,112 @@ DEFINE_ACTION_FUNCTION(FDynArray_Ptr, Clear)
}
//-----------------------------------------------------
//
// Object array
//
//-----------------------------------------------------
DEFINE_ACTION_FUNCTION(FDynArray_Obj, Copy)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj);
PARAM_POINTER(other, FDynArray_Obj);
*self = *other;
return 0;
}
DEFINE_ACTION_FUNCTION(FDynArray_Obj, Move)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj);
PARAM_POINTER(other, FDynArray_Obj);
*self = std::move(*other);
return 0;
}
DEFINE_ACTION_FUNCTION(FDynArray_Obj, Find)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj);
PARAM_OBJECT(val, DObject);
ACTION_RETURN_INT(self->Find(val));
}
DEFINE_ACTION_FUNCTION(FDynArray_Obj, Push)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj);
PARAM_OBJECT(val, DObject);
GC::WriteBarrier(val);
ACTION_RETURN_INT(self->Push(val));
}
DEFINE_ACTION_FUNCTION(FDynArray_Obj, Pop)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj);
ACTION_RETURN_BOOL(self->Pop());
}
DEFINE_ACTION_FUNCTION(FDynArray_Obj, Delete)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj);
PARAM_INT(index);
PARAM_INT_DEF(count);
self->Delete(index, count);
return 0;
}
DEFINE_ACTION_FUNCTION(FDynArray_Obj, Insert)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj);
PARAM_INT(index);
PARAM_OBJECT(val, DObject);
GC::WriteBarrier(val);
self->Insert(index, val);
return 0;
}
DEFINE_ACTION_FUNCTION(FDynArray_Obj, ShrinkToFit)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj);
self->ShrinkToFit();
return 0;
}
DEFINE_ACTION_FUNCTION(FDynArray_Obj, Grow)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj);
PARAM_INT(count);
self->Grow(count);
return 0;
}
DEFINE_ACTION_FUNCTION(FDynArray_Obj, Resize)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj);
PARAM_INT(count);
self->Resize(count);
return 0;
}
DEFINE_ACTION_FUNCTION(FDynArray_Obj, Reserve)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj);
PARAM_INT(count);
ACTION_RETURN_INT(self->Reserve(count));
}
DEFINE_ACTION_FUNCTION(FDynArray_Obj, Max)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj);
ACTION_RETURN_INT(self->Max());
}
DEFINE_ACTION_FUNCTION(FDynArray_Obj, Clear)
{
PARAM_SELF_STRUCT_PROLOGUE(FDynArray_Obj);
self->Clear();
return 0;
}
//-----------------------------------------------------
//
// String array
@ -781,4 +888,5 @@ DEFINE_FIELD_NAMED_X(DynArray_I32, FArray, Count, Size)
DEFINE_FIELD_NAMED_X(DynArray_F32, FArray, Count, Size)
DEFINE_FIELD_NAMED_X(DynArray_F64, FArray, Count, Size)
DEFINE_FIELD_NAMED_X(DynArray_Ptr, FArray, Count, Size)
DEFINE_FIELD_NAMED_X(DynArray_Obj, FArray, Count, Size)
DEFINE_FIELD_NAMED_X(DynArray_String, FArray, Count, Size)

View file

@ -2050,6 +2050,9 @@ PDynArray *NewDynArray(PType *type)
break;
case REGT_POINTER:
if (type->isObjectPointer())
backingname = "DynArray_Obj";
else
backingname = "DynArray_Ptr";
break;

View file

@ -115,6 +115,25 @@ struct DynArray_Ptr native
native void Clear ();
}
struct DynArray_Obj native
{
native readonly uint Size;
native void Copy(DynArray_Obj other);
native void Move(DynArray_Obj other);
native uint Find(Object item) const;
native uint Push (Object item);
native bool Pop ();
native void Delete (uint index, int deletecount = 1);
native void Insert (uint index, Object item);
native void ShrinkToFit ();
native void Grow (uint amount);
native void Resize (uint amount);
native uint Reserve (uint amount);
native uint Max () const;
native void Clear ();
}
struct DynArray_String native
{
native readonly uint Size;