Skip to content

Commit

Permalink
Fix unbox.any for GUID type
Browse files Browse the repository at this point in the history
- Add GUID to WellKnownTypes.
- Add code to PerformUnboxing to check for valid GUID unboxing.
  • Loading branch information
josesimoes committed Jun 21, 2021
1 parent 6de2710 commit f6cd2b4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/CLR/Core/CLR_RT_HeapBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,21 @@ HRESULT CLR_RT_HeapBlock::PerformUnboxing(const CLR_RT_TypeDef_Instance &cls)
// No luck. The types in src object and specified by cls are different. Need to throw exceptioin.
NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_CAST);
}

// now check edge cases

//////////////////////////////////////////////////////////
// GUID: can't cast to anything except another GUID object
CLR_RT_TypeDescriptor srcTypeDes;
NANOCLR_CHECK_HRESULT(srcTypeDes.InitializeFromObject(*src));

CLR_RT_TypeDef_Instance& inst = srcTypeDes.m_handlerCls;

if (inst.m_data == g_CLR_RT_WellKnownTypes.m_Guid.m_data)
{
// can't cast GUID class to anything else except another GUID
NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_CAST);
}
}

if (cls.m_target->dataType == DATATYPE_VALUETYPE)
Expand Down
2 changes: 2 additions & 0 deletions src/CLR/Core/TypeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2816,6 +2816,8 @@ static const TypeIndexLookup c_TypeIndexLookup[] = {
TIL("System.Reflection", "RuntimeFieldInfo", m_FieldInfo),

TIL("System", "WeakReference", m_WeakReference),

TIL("System", "Guid", m_Guid),

TIL("nanoFramework.UI", "Bitmap", m_Bitmap),
TIL("nanoFramework.UI", "Font", m_Font),
Expand Down
2 changes: 2 additions & 0 deletions src/CLR/Include/nanoCLR_Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,8 @@ struct CLR_RT_WellKnownTypes

CLR_RT_TypeDef_Index m_WeakReference;

CLR_RT_TypeDef_Index m_Guid;

CLR_RT_TypeDef_Index m_SerializationHintsAttribute;
CLR_RT_TypeDef_Index m_Bitmap;
CLR_RT_TypeDef_Index m_Font;
Expand Down

0 comments on commit f6cd2b4

Please sign in to comment.