Runtime: Add ObjC weak referencing support to SwiftObject.

We were missing -_tryRetain, -_isDeallocating, -allowsWeakReference and -retainWeakReference implementations on SwiftObject, so forming an ObjC weak reference to a pure Swift object always failed and produced a nil reference. Fixes rdar://problem/18637774.

Swift SVN r22710
This commit is contained in:
Joe Groff
2014-10-13 22:12:39 +00:00
parent f2a046a64c
commit 82f6260c64
9 changed files with 118 additions and 6 deletions

View File

@@ -32,11 +32,6 @@
using namespace swift;
namespace swift {
extern "C" HeapObject *swift_tryRetain(HeapObject *object);
};
HeapObject *
swift::swift_allocObject(HeapMetadata const *metadata,
size_t requiredSize,
@@ -331,6 +326,17 @@ static HeapObject *_swift_tryRetain_(HeapObject *object) {
}
auto swift::_swift_tryRetain = _swift_tryRetain_;
bool swift::swift_isDeallocating(HeapObject *object) {
return _swift_isDeallocating(object);
}
static bool _swift_isDeallocating_(HeapObject *object) {
if (!object) return false;
uint32_t count
= reinterpret_cast<std::atomic<uint32_t>*>(&object->refCount)->load();
return count & RC_DEALLOCATING_BIT;
}
auto swift::_swift_isDeallocating = _swift_isDeallocating_;
#endif
void swift::swift_retainUnowned(HeapObject *object) {