Closed CuriousTommy closed 3 years ago
Could you share the source of this test?
We need to update our objc4; this method seems to be new in 10.14.4
Sound's like you guys got this figured out, but just in case... here is a very simple source code example.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
NSArray<NSString *> *value = [[NSArray alloc] init];
return 0;
}
Same problem when compiling FSEvents with clang 10.0.1 on Linux.
I backported this function for objc4:
diff --git a/runtime/NSObject.mm b/runtime/NSObject.mm
index c7e7f43..9b299ab 100644
--- a/runtime/NSObject.mm
+++ b/runtime/NSObject.mm
@@ -1774,6 +1774,13 @@ objc_allocWithZone(Class cls)
return callAlloc(cls, true/*checkNil*/, true/*allocWithZone*/);
}
+// Calls [[cls alloc] init].
+id
+objc_alloc_init(Class cls)
+{
+ return [callAlloc(cls, true/*checkNil*/, false/*allocWithZone*/) init];
+}
+
void
_objc_rootDealloc(id obj)
diff --git a/runtime/objc-internal.h b/runtime/objc-internal.h
index 5bcb28c..f112568 100644
--- a/runtime/objc-internal.h
+++ b/runtime/objc-internal.h
@@ -502,6 +502,9 @@ OBJC_EXPORT id objc_alloc(Class cls)
OBJC_EXPORT id objc_allocWithZone(Class cls)
OBJC_AVAILABLE(10.9, 7.0, 9.0, 1.0);
+OBJC_EXPORT id objc_alloc_init(Class _Nullable cls)
+ OBJC_AVAILABLE(10.14.4, 12.2, 12.2, 5.2);
+
OBJC_EXPORT id objc_retain(id obj)
__asm__("_objc_retain")
OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0);
and it works.
This should be fixed; objc4 was updated and this is defined now.
I noticed that Darling fails to execute my program when I use
[[... alloc] init]
. It seems to happen with any Objective C class I use. I used macOS Catalina to compile this software.