@@ -76,7 +76,6 @@ OBJC_EXPORT __attribute__((__weak_import__))
7676}
7777
7878#if SWIFT_OBJC_INTEROP
79-
8079// / Replacement for ObjC object_isClass(), which is unavailable on
8180// / deployment targets macOS 10.9 and iOS 7.
8281static bool objcObjectIsClass (id object) {
@@ -1352,6 +1351,36 @@ static bool usesNativeSwiftReferenceCounting_nonNull(
13521351 swift_isUniquelyReferenced_nonNull_native ((const HeapObject*)object);
13531352}
13541353
1354+ #if SWIFT_OBJC_INTEROP
1355+ // It would be nice to weak link instead of doing this, but we can't do that
1356+ // until the new API is in the versions of libobjc that we're linking against.
1357+ static bool isUniquelyReferenced (id object) {
1358+ #if OBJC_ISUNIQUELYREFERENCED_DEFINED
1359+ return objc_isUniquelyReferenced (object);
1360+ #else
1361+ auto objcIsUniquelyRefd = SWIFT_LAZY_CONSTANT (reinterpret_cast <bool (*)(id )>(
1362+ dlsym (RTLD_NEXT, " objc_isUniquelyReferenced" )));
1363+
1364+ return objcIsUniquelyRefd && objcIsUniquelyRefd (object);
1365+ #endif /* OBJC_ISUNIQUELYREFERENCED_DEFINED */
1366+ }
1367+ #endif
1368+
1369+ bool swift::swift_isUniquelyReferenced_nonNull (const void *object) {
1370+ assert (object != nullptr );
1371+
1372+ #if SWIFT_OBJC_INTEROP
1373+ if (isObjCTaggedPointer (object))
1374+ return false ;
1375+
1376+ if (!usesNativeSwiftReferenceCounting_nonNull (object)) {
1377+ return isUniquelyReferenced (id_const_cast (object));
1378+ }
1379+ #endif
1380+ return swift_isUniquelyReferenced_nonNull_native (
1381+ static_cast <const HeapObject *>(object));
1382+ }
1383+
13551384// Given an object reference, return true iff it is non-nil and refers
13561385// to a native swift object with strong reference count of 1.
13571386bool swift::swift_isUniquelyReferencedNonObjC (
@@ -1361,6 +1390,12 @@ static bool usesNativeSwiftReferenceCounting_nonNull(
13611390 && swift_isUniquelyReferencedNonObjC_nonNull (object);
13621391}
13631392
1393+ // Given an object reference, return true if it is non-nil and refers
1394+ // to an ObjC or native swift object with a strong reference count of 1.
1395+ bool swift::swift_isUniquelyReferenced (const void *object) {
1396+ return object != nullptr && swift_isUniquelyReferenced_nonNull (object);
1397+ }
1398+
13641399// / Return true if the given bits of a Builtin.BridgeObject refer to a
13651400// / native swift object whose strong reference count is 1.
13661401bool swift::swift_isUniquelyReferencedNonObjC_nonNull_bridgeObject (
@@ -1386,6 +1421,26 @@ static bool usesNativeSwiftReferenceCounting_nonNull(
13861421#endif
13871422}
13881423
1424+ // / Return true if the given bits of a Builtin.BridgeObject refer to
1425+ // / an object whose strong reference count is 1.
1426+ bool swift::swift_isUniquelyReferenced_nonNull_bridgeObject (uintptr_t bits) {
1427+ auto bridgeObject = reinterpret_cast <void *>(bits);
1428+
1429+ if (isObjCTaggedPointer (bridgeObject))
1430+ return false ;
1431+
1432+ const auto object = toPlainObject_unTagged_bridgeObject (bridgeObject);
1433+
1434+ #if SWIFT_OBJC_INTEROP
1435+ return !isNonNative_unTagged_bridgeObject (bridgeObject)
1436+ ? swift_isUniquelyReferenced_nonNull_native (
1437+ (const HeapObject *)object)
1438+ : swift_isUniquelyReferenced_nonNull (object);
1439+ #else
1440+ return swift_isUniquelyReferenced_nonNull_native ((const HeapObject *)object);
1441+ #endif
1442+ }
1443+
13891444// Given a non-@objc object reference, return true iff the
13901445// object is non-nil and has a strong reference count greather than 1
13911446bool swift::swift_isEscapingClosureAtFileLocation (const HeapObject *object,
0 commit comments