mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-14 06:14:10 +02:00
Improved null handling in reflected method invocation
This commit is contained in:
parent
7a227ee7a4
commit
f0ff0d3630
2 changed files with 62 additions and 5 deletions
|
@ -595,13 +595,51 @@ namespace System.Reflection
|
||||||
bool unbox = false;
|
bool unbox = false;
|
||||||
bool unboxToPtr = false;
|
bool unboxToPtr = false;
|
||||||
|
|
||||||
let argType = arg.[Friend]RawGetType();
|
void* nullPtr = null;
|
||||||
void* dataPtr = (uint8*)Internal.UnsafeCastToPtr(arg) + argType.[Friend]mMemberDataOffset;
|
|
||||||
|
Type argType = null;
|
||||||
|
void* dataPtr = null;
|
||||||
|
|
||||||
bool isValid = true;
|
bool isValid = true;
|
||||||
|
|
||||||
bool added = false;
|
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)
|
if (argType.IsBoxedStructPtr || argType.IsBoxedPrimitivePtr)
|
||||||
{
|
{
|
||||||
|
@ -633,7 +671,7 @@ namespace System.Reflection
|
||||||
}
|
}
|
||||||
else if (paramType.IsValueType)
|
else if (paramType.IsValueType)
|
||||||
{
|
{
|
||||||
bool handled = true;
|
handled = true;
|
||||||
|
|
||||||
if (!argType.IsBoxed)
|
if (!argType.IsBoxed)
|
||||||
return .Err(.InvalidArgument((.)argIdx));
|
return .Err(.InvalidArgument((.)argIdx));
|
||||||
|
@ -647,6 +685,10 @@ namespace System.Reflection
|
||||||
dataPtr = *(void**)dataPtr;
|
dataPtr = *(void**)dataPtr;
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isValid = underlyingType == paramType;
|
||||||
|
}
|
||||||
|
|
||||||
if (!handled)
|
if (!handled)
|
||||||
{
|
{
|
||||||
|
|
|
@ -273,4 +273,19 @@ static
|
||||||
}
|
}
|
||||||
data
|
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
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue