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

Improved null handling in reflected method invocation

This commit is contained in:
Brian Fiete 2022-03-01 10:37:13 -08:00
parent 7a227ee7a4
commit f0ff0d3630
2 changed files with 62 additions and 5 deletions

View file

@ -595,13 +595,51 @@ namespace System.Reflection
bool unbox = false;
bool unboxToPtr = false;
let argType = arg.[Friend]RawGetType();
void* dataPtr = (uint8*)Internal.UnsafeCastToPtr(arg) + argType.[Friend]mMemberDataOffset;
void* nullPtr = null;
Type argType = null;
void* dataPtr = null;
bool isValid = true;
bool added = false;
bool handled = false;
if (var refParamType = paramType as RefType)
if (arg == null)
{
isValid = false;
if ((paramType.IsPointer) || (paramType.IsObject) || (paramType.IsInterface))
{
argType = paramType;
dataPtr = &nullPtr;
isValid = true;
}
else if (var genericType = paramType as SpecializedGenericType)
{
if (genericType.UnspecializedType == typeof(Nullable<>))
{
argType = paramType;
dataPtr = ScopedAllocZero!(paramType.Size, 16);
isValid = true;
handled = true;
}
}
}
else
{
argType = arg.[Friend]RawGetType();
dataPtr = (uint8*)Internal.UnsafeCastToPtr(arg) + argType.[Friend]mMemberDataOffset;
}
if (!isValid)
{
// Not valid
}
else if (handled)
{
}
else if (var refParamType = paramType as RefType)
{
if (argType.IsBoxedStructPtr || argType.IsBoxedPrimitivePtr)
{
@ -633,7 +671,7 @@ namespace System.Reflection
}
else if (paramType.IsValueType)
{
bool handled = true;
handled = true;
if (!argType.IsBoxed)
return .Err(.InvalidArgument((.)argIdx));
@ -647,6 +685,10 @@ namespace System.Reflection
dataPtr = *(void**)dataPtr;
handled = true;
}
else
{
isValid = underlyingType == paramType;
}
if (!handled)
{

View file

@ -273,4 +273,19 @@ static
}
data
}
public static mixin ScopedAllocZero(int size, int align)
{
void* data;
if (size <= 128)
{
data = scope:mixin [Align(align)] uint8[size]*;
}
else
{
data = new [Align(align)] uint8[size]*;
defer:mixin delete data;
}
data
}
}