[runtime] Throw exception for condition we don't handle in the dynamic registrar. (#20568)

Throw an exception for a condition we don't handle in the dynamic registrar:
calling a base Objective-C constructor (init method) with arguments. Our
current implementation to call the base Objective-C constructor doesn't handle
any arguments, so if the method actually takes any arguments, those will just
be random memory. In other words: a consistent exception is better than a
random invalid memory access.
This commit is contained in:
Rolf Bjarne Kvinge 2024-05-20 18:57:42 +02:00 коммит произвёл GitHub
Родитель 8ea6cd6a66
Коммит 7e8e887d5d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 20 добавлений и 0 удалений

Просмотреть файл

@ -107,6 +107,13 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
}
if (has_nsobject) {
if (strchr (sel_getName (sel), ':') != NULL) {
char *msg = xamarin_strdup_printf ("The dynamic registrar does not support calling base Objective-C constructors with arguments (type: %s, selector: %s). Please use any of the static registrars.", class_getName ([self class]), sel_getName (sel));
exception_gchandle = xamarin_create_product_exception (8058, msg);
xamarin_free (msg);
xamarin_process_managed_exception_gchandle (exception_gchandle);
return;
}
self = xamarin_invoke_objc_method_implementation (self, sel, (IMP) xamarin_ctor_trampoline);
marshal_return_value (context, "|", __SIZEOF_POINTER__, self, NULL, false, NULL, NULL, &exception_gchandle);
xamarin_process_managed_exception_gchandle (exception_gchandle);

9
tools/mtouch/Errors.designer.cs сгенерированный
Просмотреть файл

@ -4266,5 +4266,14 @@ namespace Xamarin.Bundler {
return ResourceManager.GetString("MX8057", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The dynamic registrar does not support calling base Objective-C constructors with arguments (type: %s, selector: %s). Please use any of the static registrars..
/// </summary>
public static string MX8058 {
get {
return ResourceManager.GetString("MX8058", resourceCulture);
}
}
}
}

Просмотреть файл

@ -2271,4 +2271,8 @@
<value>.NET for {0} does not support server garbage collection.</value>
<comment>{0}: the platform (iOS, macOS, etc.)</comment>
</data>
<data name="MX8058" xml:space="preserve">
<value>The dynamic registrar does not support calling base Objective-C constructors with arguments (type: %s, selector: %s). Please use any of the static registrars.</value>
</data>
</root>