Skip to content

Commit 0475307

Browse files
author
Greg Parker
committed
[stdlib] Don't call object_isClass().
object_isClass() is unavailable on Swift's oldest deployment targets. rdar://33872748
1 parent fd253da commit 0475307

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

stdlib/public/runtime/SwiftObject.mm

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ static uintptr_t computeISAMask() {
7979
#endif
8080
}
8181

82+
#if SWIFT_OBJC_INTEROP
83+
/// \brief Replacement for ObjC object_isClass(), which is unavailable on
84+
/// deployment targets macOS 10.9 and iOS 7.
85+
static bool objcObjectIsClass(id object) {
86+
// same as object_isClass(object)
87+
return class_isMetaClass(object_getClass(object));
88+
}
89+
#endif
90+
8291
/// \brief Fetch the type metadata associated with the formal dynamic
8392
/// type of the given (possibly Objective-C) object. The formal
8493
/// dynamic type ignores dynamic subclasses such as those introduced
@@ -105,7 +114,7 @@ static uintptr_t computeISAMask() {
105114

106115
id objcObject = reinterpret_cast<id>(object);
107116
Class objcClass = [objcObject class];
108-
if (object_isClass(objcObject)) {
117+
if (objcObjectIsClass(objcObject)) {
109118
// Original object is a class. We want a
110119
// metaclass but +class doesn't give that to us.
111120
objcClass = object_getClass(objcClass);

0 commit comments

Comments
 (0)