Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/ObjCRuntime/Class.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public partial class Class : INativeObject

// We use the last significant bit of the IntPtr to store if this is a custom class or not.
static Dictionary<Type, IntPtr> type_to_class; // accessed from multiple threads, locking required.
static Type[] class_to_type;

internal IntPtr handle;

Expand All @@ -33,12 +34,15 @@ internal unsafe static void Initialize (Runtime.InitializationOptions* options)
{
type_to_class = new Dictionary<Type, IntPtr> (Runtime.TypeEqualityComparer);

if (!Runtime.DynamicRegistrationSupported)
return; // Only the dynamic registrar needs the list of registered assemblies.

var map = options->RegistrationMap;
if (map == null)
return;

class_to_type = new Type [map->map_count];

if (!Runtime.DynamicRegistrationSupported)
return; // Only the dynamic registrar needs the list of registered assemblies.


for (int i = 0; i < map->assembly_count; i++) {
var ptr = Marshal.ReadIntPtr (map->assembly, i * IntPtr.Size);
Expand Down Expand Up @@ -340,10 +344,14 @@ internal unsafe static Type FindType (IntPtr @class, out bool is_custom_type)
return null;
}

Type type = class_to_type [mapIndex];
if (type != null)
return type;

// Resolve the map entry we found to a managed type
var type_reference = map->map [mapIndex].type_reference;
var member = ResolveTokenReference (type_reference, 0x02000000);
var type = member as Type;
type = member as Type;

if (type == null && member != null)
throw ErrorHelper.CreateError (8022, $"Expected the token reference 0x{type_reference:X} to be a type, but it's a {member.GetType ().Name}. Please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new.");
Expand All @@ -352,6 +360,8 @@ internal unsafe static Type FindType (IntPtr @class, out bool is_custom_type)
Console.WriteLine ($"FindType (0x{@class:X} = {Marshal.PtrToStringAuto (class_getName (@class))}) => {type.FullName}; is custom: {is_custom_type} (token reference: 0x{type_reference:X}).");
#endif

class_to_type [mapIndex] = type;

return type;
}

Expand Down