Skip to content

Commit 5a55760

Browse files
committed
[Runtime] Teach BridgeObjectBox::retain() not to drop the "not native" bit.
The "not native" bit in a BridgeObject is important, because it tells us when we need to go through the Objective-C -retain method vs. swift_retain. Losing the bit means that swift_retain() will stomp on some memory within an Objective-C object, thinking its the inline reference count. Co-debugged with Arnold, who then found where this bit was getting dropped. Fixes rdar://problem/39629937.
1 parent 68c4a6b commit 5a55760

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

stdlib/public/runtime/MetadataImpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ struct BridgeObjectBox :
410410
static constexpr unsigned numExtraInhabitants = 1;
411411

412412
static void *retain(void *obj) {
413-
return swift_bridgeObjectRetain(obj);
413+
(void)swift_bridgeObjectRetain(obj);
414+
return obj;
414415
}
415416

416417
static void release(void *obj) {

test/stdlib/Mirror.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,31 @@ mirrors.test("class/ObjCCustomizedSuper/Synthesized") {
464464
}
465465
}
466466
}
467+
468+
// rdar://problem/39629937
469+
@objc class ObjCClass : NSObject {
470+
let value: Int
471+
472+
init(value: Int) { self.value = value }
473+
474+
override var description: String {
475+
return "\(value)"
476+
}
477+
}
478+
479+
struct WrapObjCClassArray {
480+
var array: [ObjCClass]
481+
}
482+
483+
mirrors.test("struct/WrapNSArray") {
484+
let nsArray: NSArray = [
485+
ObjCClass(value: 1), ObjCClass(value: 2),
486+
ObjCClass(value: 3), ObjCClass(value: 4)
487+
]
488+
let s = String(describing: WrapObjCClassArray(array: nsArray as! [ObjCClass]))
489+
expectEqual("WrapObjCClassArray(array: [1, 2, 3, 4])", s)
490+
}
491+
467492
#endif // _runtime(_ObjC)
468493

469494
//===--- Suppressed Superclass Mirrors ------------------------------------===//

0 commit comments

Comments
 (0)