@@ -91,7 +91,7 @@ HRESULT CLR_RT_ExecutionEngine::ExecutionEngine_Initialize()
91
91
// CLR_RT_Thread* m_cctorThread;
92
92
//
93
93
#if !defined(NANOCLR_APPDOMAINS)
94
- m_globalLock = nullptr ; // CLR_RT_HeapBlock* m_globalLock;
94
+ m_globalLock = nullptr ; // CLR_RT_HeapBlock* m_globalLock;
95
95
m_outOfMemoryException = nullptr ; // CLR_RT_HeapBlock* m_outOfMemoryException;
96
96
#endif
97
97
@@ -2262,27 +2262,31 @@ HRESULT CLR_RT_ExecutionEngine::NewGenericInstanceObject(
2262
2262
const CLR_RECORD_FIELDDEF *target = nullptr ;
2263
2263
CLR_RT_Assembly *assm = nullptr ;
2264
2264
CLR_RT_TypeDef_Instance instSub = instance;
2265
+ CLR_RT_HeapBlock_GenericInstance *giHeader = nullptr ;
2266
+ CLR_RT_HeapBlock *fieldCursor = nullptr ;
2265
2267
2266
2268
reference.SetObjectReference (nullptr );
2267
2269
2268
2270
int clsFields = instance.target ->instanceFieldsCount ;
2269
2271
int totFields = instance.CrossReference ().totalFields + CLR_RT_HeapBlock::HB_Object_Fields_Offset;
2270
2272
2271
- CLR_RT_HeapBlock_GenericInstance *genericInst;
2273
+ giHeader = (CLR_RT_HeapBlock_GenericInstance *)ExtractHeapBlocksForGenericInstance (0 , genericInstance, totFields);
2274
+ CHECK_ALLOCATION (giHeader);
2272
2275
2273
- genericInst =
2274
- (CLR_RT_HeapBlock_GenericInstance *)ExtractHeapBlocksForGenericInstance (0 , genericInstance, totFields);
2275
- CHECK_ALLOCATION (genericInst);
2276
+ reference.SetObjectReference (giHeader);
2276
2277
2277
- reference.SetObjectReference (genericInst);
2278
+ // Associate the instance with its declaring type for reflection & casting utilities.
2279
+ giHeader->SetObjectCls (instance);
2278
2280
2279
2281
//
2280
2282
// Initialize field types, from last to first.
2281
2283
//
2282
2284
// We do the decrement BEFORE the comparison because we want to stop short of the first field, the
2283
2285
// object descriptor (already initialized).
2284
2286
//
2285
- genericInst += totFields;
2287
+
2288
+ fieldCursor = reinterpret_cast <CLR_RT_HeapBlock *>(giHeader) + totFields;
2289
+
2286
2290
while (--totFields > 0 )
2287
2291
{
2288
2292
while (clsFields == 0 )
@@ -2302,11 +2306,11 @@ HRESULT CLR_RT_ExecutionEngine::NewGenericInstanceObject(
2302
2306
target = assm->GetFieldDef (instSub.target ->firstInstanceField + clsFields);
2303
2307
}
2304
2308
2305
- genericInst --;
2309
+ fieldCursor --;
2306
2310
target--;
2307
2311
clsFields--;
2308
2312
2309
- NANOCLR_CHECK_HRESULT (InitializeReference (*genericInst , target, assm));
2313
+ NANOCLR_CHECK_HRESULT (InitializeReference (*fieldCursor , target, assm));
2310
2314
}
2311
2315
2312
2316
if (instance.HasFinalizer ())
0 commit comments