From 0208c1140beb4769f1a06c986e78c215b421143a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hendrik=20H=C3=BCbner?= Date: Wed, 19 Aug 2026 15:30:12 +0200 Subject: [PATCH] Call Objective-C IMPs with exact signatures --- arc.mm | 24 +++++++++++++++--------- dtable.c | 5 +++-- runtime.c | 10 +++++++--- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/arc.mm b/arc.mm index 459a3fb8..47945729 100644 --- a/arc.mm +++ b/arc.mm @@ -250,9 +250,12 @@ static TLS_CALLBACK(cleanupPools)(struct arc_tls* tls) static Class AutoreleasePool; -static IMP NewAutoreleasePool; -static IMP DeleteAutoreleasePool; -static IMP AutoreleaseAdd; +typedef id (*NewAutoreleasePoolIMP)(id, SEL); +typedef void (*DeleteAutoreleasePoolIMP)(id, SEL); +typedef void (*AutoreleaseAddIMP)(id, SEL, id); +static NewAutoreleasePoolIMP NewAutoreleasePool; +static DeleteAutoreleasePoolIMP DeleteAutoreleasePool; +static AutoreleaseAddIMP AutoreleaseAdd; static BOOL useARCAutoreleasePool; @@ -566,12 +569,15 @@ static inline void initAutorelease(void) if (!useARCAutoreleasePool) { [AutoreleasePool class]; - NewAutoreleasePool = class_getMethodImplementation(object_getClass(AutoreleasePool), - SELECTOR(new)); - DeleteAutoreleasePool = class_getMethodImplementation(AutoreleasePool, - SELECTOR(release)); - AutoreleaseAdd = class_getMethodImplementation(object_getClass(AutoreleasePool), - SELECTOR(addObject:)); + NewAutoreleasePool = reinterpret_cast( + class_getMethodImplementation(object_getClass(AutoreleasePool), + SELECTOR(new))); + DeleteAutoreleasePool = reinterpret_cast( + class_getMethodImplementation(AutoreleasePool, + SELECTOR(release))); + AutoreleaseAdd = reinterpret_cast( + class_getMethodImplementation(object_getClass(AutoreleasePool), + SELECTOR(addObject:))); } } } diff --git a/dtable.c b/dtable.c index 54c0d729..20f65513 100644 --- a/dtable.c +++ b/dtable.c @@ -673,6 +673,7 @@ LEGACY void update_dispatch_table_for_class(Class cls) } BOOL objc_resolve_class(Class); +typedef void (*InitializeIMP)(id, SEL); __attribute__((unused)) static void objc_release_object_lock(id *x) { @@ -851,6 +852,6 @@ OBJC_PUBLIC void objc_send_initialize(id object) // Store the buffer in the temporary dtables list. Note that it is safe to // insert it into a global list, even though it's a temporary variable, // because we will clean it up after this function. - initializeSlot->imp((id)class, initializeSel); + InitializeIMP initialize = (InitializeIMP)initializeSlot->imp; + initialize((id)class, initializeSel); } - diff --git a/runtime.c b/runtime.c index 45b290e9..907df1fd 100644 --- a/runtime.c +++ b/runtime.c @@ -21,6 +21,9 @@ #define CHECK_ARG(arg) if (0 == arg) { return 0; } +typedef void (*CXXDestructIMP)(id, SEL); +typedef id (*CXXConstructIMP)(id, SEL); + static inline void safe_remove_from_subclass_list(Class cls); PRIVATE BOOL objc_resolve_class(Class); void objc_send_initialize(id object); @@ -46,7 +49,8 @@ PRIVATE void call_cxx_destruct(id obj) cls = cls->super_class; if (currentClass->cxx_destruct) { - currentClass->cxx_destruct(obj, cxx_destruct); + CXXDestructIMP destruct = (CXXDestructIMP)currentClass->cxx_destruct; + destruct(obj, cxx_destruct); } } } @@ -65,7 +69,8 @@ static void call_cxx_construct_for_class(Class cls, id obj) } if (cls->cxx_construct) { - cls->cxx_construct(obj, cxx_construct); + CXXConstructIMP construct = (CXXConstructIMP)cls->cxx_construct; + construct(obj, cxx_construct); } } @@ -846,4 +851,3 @@ void objc_registerClassPair(Class cls) class_table_insert(cls); objc_resolve_class(cls); } -