@@ -22,8 +22,13 @@ typedef struct CollectMetadataContext
22
22
23
23
static void ContextInsertClass (CollectMetadataContext * context , MonoClass * klass )
24
24
{
25
- if (klass -> inited && g_hash_table_lookup (context -> allTypes , klass ) == NULL )
26
- g_hash_table_insert (context -> allTypes , klass , (gpointer )(context -> currentIndex ++ ));
25
+ gpointer orig_key , value ;
26
+ /* use g_hash_table_lookup_extended as it returns boolean to indicate if value was found.
27
+ * If we use g_hash_table_lookup it returns the value which we were comparing to NULL. The problem is
28
+ * that 0 is a valid class index and was confusing our logic.
29
+ */
30
+ if (klass -> inited && !g_hash_table_lookup_extended (context -> allTypes , klass , & orig_key , & value ))
31
+ g_hash_table_insert (context -> allTypes , klass , GINT_TO_POINTER (context -> currentIndex ++ ));
27
32
}
28
33
29
34
static void CollectHashMapClass (gpointer key , gpointer value , gpointer user_data )
@@ -104,18 +109,18 @@ static void CollectImageMetaData(MonoImage* image, gpointer value, CollectMetada
104
109
105
110
static int FindClassIndex (GHashTable * hashTable , MonoClass * klass )
106
111
{
107
- gpointer value = g_hash_table_lookup ( hashTable , klass ) ;
112
+ gpointer orig_key , value ;
108
113
109
- if (!value )
114
+ if (!g_hash_table_lookup_extended ( hashTable , klass , & orig_key , & value ) )
110
115
return -1 ;
111
116
112
- return ( int ) value ;
117
+ return GPOINTER_TO_INT ( value ) ;
113
118
}
114
119
115
120
static void AddMetadataType (gpointer key , gpointer value , gpointer user_data )
116
121
{
117
122
MonoClass * klass = (MonoClass * )key ;
118
- int index = ( int ) value ;
123
+ int index = GPOINTER_TO_INT ( value ) ;
119
124
CollectMetadataContext * context = (CollectMetadataContext * )user_data ;
120
125
MonoMetadataSnapshot * metadata = context -> metadata ;
121
126
MonoMetadataType * type = & metadata -> types [index ];
@@ -562,7 +567,7 @@ static void VerifySnapshot(MonoManagedMemorySnapshot* snapshot, GHashTable* mono
562
567
while (g_hash_table_iter_next (& iter , & key , NULL ))
563
568
{
564
569
MonoImage * image = (MonoImage * )key ;
565
- fprintf (file , "MonoImage [0x%016llX] dynamic: %i name: '%s'\n" , (void * )image , image -> dynamic , image -> name );
570
+ fprintf (file , "MonoImage [0x%016llX] dynamic: %i name: '%s'\n" , (uint64_t )image , image -> dynamic , image -> name );
566
571
}
567
572
568
573
/* Verify that we have collected memory sections for all types */
0 commit comments