1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-19 00:20:25 +02:00

Fixed 'ref' params for reflected method invocations

This commit is contained in:
Brian Fiete 2020-07-04 10:39:50 -07:00
parent 39ad1dbe85
commit c826bac949
3 changed files with 199 additions and 8 deletions

View file

@ -122,7 +122,24 @@ namespace System.Reflection
bool isPtrToPtr = false;
bool isValid = true;
if (paramType.IsValueType)
bool added = false;
if (var refParamType = paramType as RefType)
{
if (argType.IsPointer)
{
Type elemType = argType.UnderlyingType;
if (elemType != refParamType.UnderlyingType)
isValid = false;
ffiParamList.Add(&FFIType.Pointer);
ffiArgList.Add(dataPtr);
added = true;
}
else
isValid = false;
}
else if (paramType.IsValueType)
{
if (argType.IsPointer)
{
@ -162,7 +179,11 @@ namespace System.Reflection
return .Err(.InvalidArgument((.)argIdx));
}
if (paramType.IsStruct)
if (added)
{
// Already handled
}
else if (paramType.IsStruct)
{
TypeInstance paramTypeInst = (TypeInstance)paramType;
@ -376,7 +397,24 @@ namespace System.Reflection
void* dataPtr = (uint8*)Internal.UnsafeCastToPtr(arg) + argType.[Friend]mMemberDataOffset;
bool isValid = true;
if (paramType.IsValueType)
bool added = false;
if (var refParamType = paramType as RefType)
{
if (argType.IsBoxedStructPtr || argType.IsBoxedPrimitivePtr)
{
var elemType = argType.BoxedPtrType;
if (elemType != refParamType.UnderlyingType)
isValid = false;
ffiParamList.Add(&FFIType.Pointer);
ffiArgList.Add(dataPtr);
added = true;
}
else
isValid = false;
}
else if (paramType.IsValueType)
{
bool handled = true;
@ -387,7 +425,7 @@ namespace System.Reflection
if ((paramType.IsPrimitive) && (underlyingType.IsTypedPrimitive)) // Boxed primitive?
underlyingType = underlyingType.UnderlyingType;
if ((argType.IsBoxedStructPtr) || (argIdx == -1))
if (argType.IsBoxedStructPtr || argType.IsBoxedPrimitivePtr)
{
dataPtr = *(void**)dataPtr;
handled = true;
@ -421,7 +459,11 @@ namespace System.Reflection
return .Err(.InvalidArgument((.)argIdx));
}
if (paramType.IsStruct)
if (added)
{
// Already handled
}
else if (paramType.IsStruct)
{
TypeInstance paramTypeInst = (TypeInstance)paramType;

View file

@ -254,6 +254,47 @@ namespace System
}
}
public bool IsBoxedPrimitivePtr
{
get
{
if (!mTypeFlags.HasFlag(.Boxed))
return false;
let underyingType = UnderlyingType;
if (var genericTypeInstance = underyingType as SpecializedGenericType)
{
if (genericTypeInstance.UnspecializedType == typeof(Pointer<>))
return true;
}
return false;
}
}
public Type BoxedPtrType
{
get
{
if (!mTypeFlags.HasFlag(.Boxed))
return null;
if (mTypeFlags.HasFlag(.Pointer))
{
return UnderlyingType;
}
let underyingType = UnderlyingType;
if (var genericTypeInstance = underyingType as SpecializedGenericType)
{
if (genericTypeInstance.UnspecializedType == typeof(Pointer<>))
return genericTypeInstance.GetGenericArg(0);
}
return null;
}
}
public bool IsEnum
{
get
@ -877,6 +918,14 @@ namespace System.Reflection
TypeId mUnspecializedType;
TypeId* mResolvedTypeRefs;
public Type UnspecializedType
{
get
{
return Type.[Friend]GetType(mUnspecializedType);
}
}
public override int32 GenericParamCount
{
get