mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
stdlib: Make isUniquelyReferenced shims properly return bool.
rdar://problem/18573806 is fixed. Swift SVN r23547
This commit is contained in:
@@ -70,7 +70,7 @@ struct _BridgeStorage<
|
|||||||
mutating func isUniquelyReferencedNative() -> Bool {
|
mutating func isUniquelyReferencedNative() -> Bool {
|
||||||
return _swift_isUniquelyReferencedNonObjC_nonNull_bridgeObject(
|
return _swift_isUniquelyReferencedNonObjC_nonNull_bridgeObject(
|
||||||
_bitPattern(rawValue)
|
_bitPattern(rawValue)
|
||||||
) != 0
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public // @testable
|
public // @testable
|
||||||
@@ -110,7 +110,7 @@ struct _BridgeStorage<
|
|||||||
_sanityCheck(isNative)
|
_sanityCheck(isNative)
|
||||||
_sanityCheck(_nonPointerBits(rawValue) == 0)
|
_sanityCheck(_nonPointerBits(rawValue) == 0)
|
||||||
let p: UnsafePointer<HeapObject> = Builtin.reinterpretCast(rawValue)
|
let p: UnsafePointer<HeapObject> = Builtin.reinterpretCast(rawValue)
|
||||||
return _swift_isUniquelyReferenced_nonNull_native(p) != 0
|
return _swift_isUniquelyReferenced_nonNull_native(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
public // @testable
|
public // @testable
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ internal func _usesNativeSwiftReferenceCounting(theClass: AnyClass) -> Bool {
|
|||||||
#if _runtime(_ObjC)
|
#if _runtime(_ObjC)
|
||||||
return _swift_usesNativeSwiftReferenceCounting_class(
|
return _swift_usesNativeSwiftReferenceCounting_class(
|
||||||
unsafeAddressOf(theClass)
|
unsafeAddressOf(theClass)
|
||||||
) != 0
|
)
|
||||||
#else
|
#else
|
||||||
return true
|
return true
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2551,7 +2551,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorageType {
|
|||||||
let o: UnsafePointer<HeapObject> = Builtin.reinterpretCast(self)
|
let o: UnsafePointer<HeapObject> = Builtin.reinterpretCast(self)
|
||||||
let result = _swift_isUniquelyReferenced_native(o)
|
let result = _swift_isUniquelyReferenced_native(o)
|
||||||
Builtin.fixLifetime(self)
|
Builtin.fixLifetime(self)
|
||||||
return result != 0
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
switch self {
|
switch self {
|
||||||
@@ -2559,7 +2559,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorageType {
|
|||||||
let o: UnsafePointer<HeapObject> = Builtin.reinterpretCast(self)
|
let o: UnsafePointer<HeapObject> = Builtin.reinterpretCast(self)
|
||||||
let result = _swift_isUniquelyReferenced_native(o)
|
let result = _swift_isUniquelyReferenced_native(o)
|
||||||
Builtin.fixLifetime(self)
|
Builtin.fixLifetime(self)
|
||||||
return result != 0
|
return result
|
||||||
case .Cocoa:
|
case .Cocoa:
|
||||||
// Don't consider Cocoa storage mutable, even if it is mutable and is
|
// Don't consider Cocoa storage mutable, even if it is mutable and is
|
||||||
// uniquely referenced.
|
// uniquely referenced.
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ internal func _isUniquelyReferenced_native(
|
|||||||
inout x: Builtin.NativeObject?
|
inout x: Builtin.NativeObject?
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
let p: UnsafePointer<_HeapObject> = Builtin.reinterpretCast(x)
|
let p: UnsafePointer<_HeapObject> = Builtin.reinterpretCast(x)
|
||||||
let result = _swift_isUniquelyReferenced_native(p) != 0
|
let result = _swift_isUniquelyReferenced_native(p)
|
||||||
Builtin.fixLifetime(x)
|
Builtin.fixLifetime(x)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@@ -216,7 +216,7 @@ internal struct _HeapBuffer<Value, Element> : Equatable {
|
|||||||
let o: UnsafePointer<HeapObject> = Builtin.reinterpretCast(_storage)
|
let o: UnsafePointer<HeapObject> = Builtin.reinterpretCast(_storage)
|
||||||
let result = _swift_isUniquelyReferenced_native(o)
|
let result = _swift_isUniquelyReferenced_native(o)
|
||||||
Builtin.fixLifetime(_storage)
|
Builtin.fixLifetime(_storage)
|
||||||
return result != 0
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ public struct ManagedBufferPointer<Value, Element> : Equatable {
|
|||||||
let o = UnsafePointer<HeapObject>(Builtin.bridgeToRawPointer(_nativeBuffer))
|
let o = UnsafePointer<HeapObject>(Builtin.bridgeToRawPointer(_nativeBuffer))
|
||||||
let result = _swift_isUniquelyReferenced_nonNull_native(o)
|
let result = _swift_isUniquelyReferenced_nonNull_native(o)
|
||||||
_fixLifetime(_nativeBuffer)
|
_fixLifetime(_nativeBuffer)
|
||||||
return result != 0
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
//===--- internal/private API -------------------------------------------===//
|
//===--- internal/private API -------------------------------------------===//
|
||||||
@@ -414,7 +414,7 @@ public func isUniquelyReferencedNonObjC<T: AnyObject>(inout object: T) -> Bool {
|
|||||||
let o = UnsafePointer<Void>(Builtin.bridgeToRawPointer(object))
|
let o = UnsafePointer<Void>(Builtin.bridgeToRawPointer(object))
|
||||||
let result = _swift_isUniquelyReferencedNonObjC_nonNull(o)
|
let result = _swift_isUniquelyReferencedNonObjC_nonNull(o)
|
||||||
Builtin.fixLifetime(object)
|
Builtin.fixLifetime(object)
|
||||||
return result != 0
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` iff `object` is a non-\ `@objc` class instance with a single
|
/// Returns `true` iff `object` is a non-\ `@objc` class instance with a single
|
||||||
@@ -447,7 +447,7 @@ public func isUniquelyReferenced<T: NonObjectiveCBase>(
|
|||||||
let o = UnsafePointer<HeapObject>(Builtin.bridgeToRawPointer(object))
|
let o = UnsafePointer<HeapObject>(Builtin.bridgeToRawPointer(object))
|
||||||
let result = _swift_isUniquelyReferenced_nonNull_native(o)
|
let result = _swift_isUniquelyReferenced_nonNull_native(o)
|
||||||
Builtin.fixLifetime(object)
|
Builtin.fixLifetime(object)
|
||||||
return result != 0
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` iff `object` is a non-\ `@objc` class instance with
|
/// Returns `true` iff `object` is a non-\ `@objc` class instance with
|
||||||
@@ -482,6 +482,6 @@ public func isUniquelyReferencedNonObjC<T: AnyObject>(
|
|||||||
let o = Builtin.reinterpretCast(object) as UnsafePointer<Void>
|
let o = Builtin.reinterpretCast(object) as UnsafePointer<Void>
|
||||||
let result = _swift_isUniquelyReferencedNonObjC(o)
|
let result = _swift_isUniquelyReferencedNonObjC(o)
|
||||||
Builtin.fixLifetime(object)
|
Builtin.fixLifetime(object)
|
||||||
return result != 0
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ internal func _isUniquelyReferenced_native(
|
|||||||
inout x: Builtin.NativeObject
|
inout x: Builtin.NativeObject
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
let p = UnsafePointer<_HeapObject>(Builtin.bridgeToRawPointer(x))
|
let p = UnsafePointer<_HeapObject>(Builtin.bridgeToRawPointer(x))
|
||||||
let result = _swift_isUniquelyReferenced_nonNull_native(p) != 0
|
let result = _swift_isUniquelyReferenced_nonNull_native(p)
|
||||||
Builtin.fixLifetime(x)
|
Builtin.fixLifetime(x)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -446,7 +446,7 @@ bool swift::usesNativeSwiftReferenceCounting(const ClassMetadata *theClass) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// version for SwiftShims
|
// version for SwiftShims
|
||||||
unsigned char
|
bool
|
||||||
swift::_swift_usesNativeSwiftReferenceCounting_class(const void *theClass) {
|
swift::_swift_usesNativeSwiftReferenceCounting_class(const void *theClass) {
|
||||||
#if SWIFT_OBJC_INTEROP
|
#if SWIFT_OBJC_INTEROP
|
||||||
return usesNativeSwiftReferenceCounting((const ClassMetadata *)theClass);
|
return usesNativeSwiftReferenceCounting((const ClassMetadata *)theClass);
|
||||||
@@ -935,7 +935,7 @@ extern "C" const char *swift_getGenericClassObjCName(const ClassMetadata *clas,
|
|||||||
|
|
||||||
// Given a non-nil object reference, return true iff the object uses
|
// Given a non-nil object reference, return true iff the object uses
|
||||||
// native swift reference counting.
|
// native swift reference counting.
|
||||||
unsigned char swift::_swift_usesNativeSwiftReferenceCounting_nonNull(
|
bool swift::_swift_usesNativeSwiftReferenceCounting_nonNull(
|
||||||
const void* object
|
const void* object
|
||||||
) {
|
) {
|
||||||
assert(object != nullptr);
|
assert(object != nullptr);
|
||||||
@@ -949,7 +949,7 @@ unsigned char swift::_swift_usesNativeSwiftReferenceCounting_nonNull(
|
|||||||
|
|
||||||
// Given a non-nil non-@objc object reference, return true iff the
|
// Given a non-nil non-@objc object reference, return true iff the
|
||||||
// object has a strong reference count of 1.
|
// object has a strong reference count of 1.
|
||||||
unsigned char swift::_swift_isUniquelyReferenced_nonNull_native(
|
bool swift::_swift_isUniquelyReferenced_nonNull_native(
|
||||||
const HeapObject* object
|
const HeapObject* object
|
||||||
) {
|
) {
|
||||||
assert(object != nullptr);
|
assert(object != nullptr);
|
||||||
@@ -959,7 +959,7 @@ unsigned char swift::_swift_isUniquelyReferenced_nonNull_native(
|
|||||||
|
|
||||||
// Given a non-@objc object reference, return true iff the
|
// Given a non-@objc object reference, return true iff the
|
||||||
// object is non-nil and has a strong reference count of 1.
|
// object is non-nil and has a strong reference count of 1.
|
||||||
unsigned char swift::_swift_isUniquelyReferenced_native(
|
bool swift::_swift_isUniquelyReferenced_native(
|
||||||
const HeapObject* object
|
const HeapObject* object
|
||||||
) {
|
) {
|
||||||
return object != nullptr
|
return object != nullptr
|
||||||
@@ -968,7 +968,7 @@ unsigned char swift::_swift_isUniquelyReferenced_native(
|
|||||||
|
|
||||||
// Given a non-nil object reference, return true iff the object is a
|
// Given a non-nil object reference, return true iff the object is a
|
||||||
// native swift object with strong reference count of 1.
|
// native swift object with strong reference count of 1.
|
||||||
unsigned char swift::_swift_isUniquelyReferencedNonObjC_nonNull(
|
bool swift::_swift_isUniquelyReferencedNonObjC_nonNull(
|
||||||
const void* object
|
const void* object
|
||||||
) {
|
) {
|
||||||
assert(object != nullptr);
|
assert(object != nullptr);
|
||||||
@@ -981,22 +981,18 @@ unsigned char swift::_swift_isUniquelyReferencedNonObjC_nonNull(
|
|||||||
|
|
||||||
// Given an object reference, return true iff it is non-nil and refers
|
// Given an object reference, return true iff it is non-nil and refers
|
||||||
// to a native swift object with strong reference count of 1.
|
// to a native swift object with strong reference count of 1.
|
||||||
unsigned char swift::_swift_isUniquelyReferencedNonObjC(
|
bool swift::_swift_isUniquelyReferencedNonObjC(
|
||||||
const void* object
|
const void* object
|
||||||
) {
|
) {
|
||||||
return object != nullptr
|
return object != nullptr
|
||||||
&& _swift_isUniquelyReferencedNonObjC_nonNull(object);
|
&& _swift_isUniquelyReferencedNonObjC_nonNull(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
// FIXME: this should return bool but it chokes the compiler
|
|
||||||
// <rdar://problem/18573806>
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
/// Given the bits of a possibly-nil Native swift object reference, or of a
|
/// Given the bits of a possibly-nil Native swift object reference, or of a
|
||||||
/// word-sized Swift enum containing a Native swift object reference as
|
/// word-sized Swift enum containing a Native swift object reference as
|
||||||
/// a payload, return true iff the object's strong reference count is
|
/// a payload, return true iff the object's strong reference count is
|
||||||
/// 1.
|
/// 1.
|
||||||
unsigned char swift::_swift_isUniquelyReferenced_native_spareBits(
|
bool swift::_swift_isUniquelyReferenced_native_spareBits(
|
||||||
__swift_uintptr_t bits
|
__swift_uintptr_t bits
|
||||||
) {
|
) {
|
||||||
const auto object = reinterpret_cast<HeapObject*>(
|
const auto object = reinterpret_cast<HeapObject*>(
|
||||||
@@ -1012,7 +1008,7 @@ unsigned char swift::_swift_isUniquelyReferenced_native_spareBits(
|
|||||||
|
|
||||||
/// Return true if the given bits of a Builtin.BridgeObject refer to a
|
/// Return true if the given bits of a Builtin.BridgeObject refer to a
|
||||||
/// native swift object whose strong reference count is 1.
|
/// native swift object whose strong reference count is 1.
|
||||||
unsigned char swift::_swift_isUniquelyReferencedNonObjC_nonNull_bridgeObject(
|
bool swift::_swift_isUniquelyReferencedNonObjC_nonNull_bridgeObject(
|
||||||
__swift_uintptr_t bits
|
__swift_uintptr_t bits
|
||||||
) {
|
) {
|
||||||
auto bridgeObject = (void*)bits;
|
auto bridgeObject = (void*)bits;
|
||||||
|
|||||||
@@ -23,18 +23,20 @@
|
|||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
namespace swift { extern "C" {
|
namespace swift { extern "C" {
|
||||||
|
#else
|
||||||
|
#define bool _Bool
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
unsigned char _swift_isUniquelyReferencedNonObjC(const void *);
|
bool _swift_isUniquelyReferencedNonObjC(const void *);
|
||||||
unsigned char _swift_isUniquelyReferencedNonObjC_nonNull(const void *);
|
bool _swift_isUniquelyReferencedNonObjC_nonNull(const void *);
|
||||||
unsigned char _swift_usesNativeSwiftReferenceCounting_nonNull(const void *);
|
bool _swift_usesNativeSwiftReferenceCounting_nonNull(const void *);
|
||||||
unsigned char _swift_usesNativeSwiftReferenceCounting_class(const void *);
|
bool _swift_usesNativeSwiftReferenceCounting_class(const void *);
|
||||||
unsigned char _swift_isUniquelyReferenced_native_spareBits(__swift_uintptr_t bits);
|
bool _swift_isUniquelyReferenced_native_spareBits(__swift_uintptr_t bits);
|
||||||
unsigned char _swift_isUniquelyReferencedNonObjC_nonNull_bridgeObject(
|
bool _swift_isUniquelyReferencedNonObjC_nonNull_bridgeObject(
|
||||||
__swift_uintptr_t bits);
|
__swift_uintptr_t bits);
|
||||||
unsigned char
|
bool
|
||||||
_swift_isUniquelyReferenced_nonNull_native(const struct HeapObject *);
|
_swift_isUniquelyReferenced_nonNull_native(const struct HeapObject *);
|
||||||
unsigned char _swift_isUniquelyReferenced_native(const struct HeapObject *);
|
bool _swift_isUniquelyReferenced_native(const struct HeapObject *);
|
||||||
__swift_size_t _swift_class_getInstancePositiveExtentSize(const void *);
|
__swift_size_t _swift_class_getInstancePositiveExtentSize(const void *);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
Reference in New Issue
Block a user