Skip to content

Commit 0808744

Browse files
Merge pull request #16213 from aschwaighofer/fix_swift_bridgeObjectRetain
Runtime: Fix swift_bridgeObjectRetain family of functions to return the input object
2 parents db93b05 + dab3b0b commit 0808744

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

stdlib/public/runtime/MetadataImpl.h

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

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

417416
static void release(void *obj) {

stdlib/public/runtime/SwiftObject.mm

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -603,12 +603,13 @@ static bool isNonNative_unTagged_bridgeObject(void *object) {
603603
#if SWIFT_OBJC_INTEROP
604604
if (!isNonNative_unTagged_bridgeObject(object)) {
605605
swift_retain(static_cast<HeapObject *>(objectRef));
606-
return static_cast<HeapObject *>(objectRef);
606+
return object;
607607
}
608-
return objc_retain(static_cast<id>(objectRef));
608+
objc_retain(static_cast<id>(objectRef));
609+
return object;
609610
#else
610611
swift_retain(static_cast<HeapObject *>(objectRef));
611-
return static_cast<HeapObject *>(objectRef);
612+
return object;
612613
#endif
613614
}
614615

@@ -624,12 +625,13 @@ static bool isNonNative_unTagged_bridgeObject(void *object) {
624625
#if SWIFT_OBJC_INTEROP
625626
if (!isNonNative_unTagged_bridgeObject(object)) {
626627
swift_nonatomic_retain(static_cast<HeapObject *>(objectRef));
627-
return static_cast<HeapObject *>(objectRef);
628+
return object;
628629
}
629-
return objc_retain(static_cast<id>(objectRef));
630+
objc_retain(static_cast<id>(objectRef));
631+
return object;
630632
#else
631633
swift_nonatomic_retain(static_cast<HeapObject *>(objectRef));
632-
return static_cast<HeapObject *>(objectRef);
634+
return object;
633635
#endif
634636
}
635637

@@ -680,14 +682,14 @@ static bool isNonNative_unTagged_bridgeObject(void *object) {
680682
void *objc_ret = nullptr;
681683
if (!isNonNative_unTagged_bridgeObject(object)) {
682684
swift_retain_n(static_cast<HeapObject *>(objectRef), n);
683-
return static_cast<HeapObject *>(objectRef);
685+
return object;
684686
}
685687
for (int i = 0;i < n; ++i)
686688
objc_ret = objc_retain(static_cast<id>(objectRef));
687-
return objc_ret;
689+
return object;
688690
#else
689691
swift_retain_n(static_cast<HeapObject *>(objectRef), n);
690-
return static_cast<HeapObject *>(objectRef);
692+
return object;
691693
#endif
692694
}
693695

@@ -721,14 +723,14 @@ static bool isNonNative_unTagged_bridgeObject(void *object) {
721723
void *objc_ret = nullptr;
722724
if (!isNonNative_unTagged_bridgeObject(object)) {
723725
swift_nonatomic_retain_n(static_cast<HeapObject *>(objectRef), n);
724-
return static_cast<HeapObject *>(objectRef);
726+
return object;
725727
}
726728
for (int i = 0;i < n; ++i)
727729
objc_ret = objc_retain(static_cast<id>(objectRef));
728-
return objc_ret;
730+
return object;
729731
#else
730732
swift_nonatomic_retain_n(static_cast<HeapObject *>(objectRef), n);
731-
return static_cast<HeapObject *>(objectRef);
733+
return object;
732734
#endif
733735
}
734736

0 commit comments

Comments
 (0)