@@ -495,6 +495,7 @@ intptr_t swift_TupleMirror_count(HeapObject *owner,
495
495
const OpaqueValue *value,
496
496
const Metadata *type) {
497
497
auto Tuple = static_cast <const TupleTypeMetadata *>(type);
498
+ swift_release (owner);
498
499
return Tuple->NumElements ;
499
500
}
500
501
@@ -524,9 +525,6 @@ void swift_TupleMirror_subscript(String *outString,
524
525
auto bytes = reinterpret_cast <const char *>(value);
525
526
auto eltData = reinterpret_cast <const OpaqueValue *>(bytes + elt.Offset );
526
527
527
- // This retain matches the -1 in reflect.
528
- swift_retain (owner);
529
-
530
528
// 'owner' is consumed by this call.
531
529
new (outMirror) Mirror (reflect (owner, eltData, elt.Type ));
532
530
}
@@ -551,6 +549,7 @@ intptr_t swift_StructMirror_count(HeapObject *owner,
551
549
const OpaqueValue *value,
552
550
const Metadata *type) {
553
551
auto Struct = static_cast <const StructMetadata *>(type);
552
+ swift_release (owner);
554
553
return Struct->Description ->Struct .NumFields ;
555
554
}
556
555
@@ -576,9 +575,6 @@ void swift_StructMirror_subscript(String *outString,
576
575
577
576
new (outString) String (getFieldName (Struct->Description ->Struct .FieldNames , i));
578
577
579
- // This matches the -1 in reflect.
580
- swift_retain (owner);
581
-
582
578
// 'owner' is consumed by this call.
583
579
assert (!fieldType.isIndirect () && " indirect struct fields not implemented" );
584
580
new (outMirror) Mirror (reflect (owner, fieldData, fieldType.getType ()));
@@ -635,14 +631,19 @@ static void getEnumMirrorInfo(const OpaqueValue *value,
635
631
const char *swift_EnumMirror_caseName (HeapObject *owner,
636
632
const OpaqueValue *value,
637
633
const Metadata *type) {
638
- if (!isEnumReflectable (type))
634
+ if (!isEnumReflectable (type)) {
635
+ swift_release (owner);
639
636
return nullptr ;
637
+ }
640
638
641
639
const auto Enum = static_cast <const EnumMetadata *>(type);
642
640
const auto &Description = Enum->Description ->Enum ;
643
641
644
642
unsigned tag;
645
643
getEnumMirrorInfo (value, type, &tag, nullptr , nullptr );
644
+
645
+ swift_release (owner);
646
+
646
647
return getFieldName (Description.CaseNames , tag);
647
648
}
648
649
@@ -667,6 +668,7 @@ static void getEnumMirrorInfo(const OpaqueValue *value,
667
668
668
669
MagicMirror *theMirror = reinterpret_cast <MagicMirror *>(&mirror);
669
670
MagicMirrorData data = theMirror->Data ;
671
+ swift_retain (data.Owner );
670
672
const char *result = swift_EnumMirror_caseName (data.Owner , data.Value , data.Type );
671
673
type->vw_destroy (value);
672
674
return result;
@@ -677,11 +679,14 @@ static void getEnumMirrorInfo(const OpaqueValue *value,
677
679
intptr_t swift_EnumMirror_count (HeapObject *owner,
678
680
const OpaqueValue *value,
679
681
const Metadata *type) {
680
- if (!isEnumReflectable (type))
682
+ if (!isEnumReflectable (type)) {
683
+ swift_release (owner);
681
684
return 0 ;
685
+ }
682
686
683
687
const Metadata *payloadType;
684
688
getEnumMirrorInfo (value, type, nullptr , &payloadType, nullptr );
689
+ swift_release (owner);
685
690
return (payloadType != nullptr ) ? 1 : 0 ;
686
691
}
687
692
@@ -702,23 +707,28 @@ void swift_EnumMirror_subscript(String *outString,
702
707
703
708
getEnumMirrorInfo (value, type, &tag, &payloadType, &indirect);
704
709
705
- // Copy the payload since the projection is destructive.
706
- BoxPair pair = swift_allocBox (type);
710
+ // Copy the enum payload into a box
711
+ const Metadata *boxType = (indirect ? &_TMBo.base : payloadType);
712
+ BoxPair pair = swift_allocBox (boxType);
713
+
714
+ type->vw_destructiveProjectEnumData (const_cast <OpaqueValue *>(value));
715
+ boxType->vw_initializeWithCopy (pair.second , const_cast <OpaqueValue *>(value));
716
+ type->vw_destructiveInjectEnumTag (const_cast <OpaqueValue *>(value),
717
+ (int ) (tag - Description.getNumPayloadCases ()));
718
+
719
+ swift_release (owner);
707
720
708
721
owner = pair.first ;
709
- type->vw_initializeWithTake (pair.second , const_cast <OpaqueValue *>(value));
710
- type->vw_destructiveProjectEnumData (pair.second );
711
722
value = pair.second ;
712
723
713
724
// If the payload is indirect, we need to jump through the box to get it.
714
725
if (indirect) {
715
726
owner = *reinterpret_cast <HeapObject * const *>(value);
716
727
value = swift_projectBox (const_cast <HeapObject *>(owner));
728
+ swift_retain (owner);
729
+ swift_release (pair.first );
717
730
}
718
731
719
- // This matches the -1 in reflect.
720
- swift_retain (owner);
721
-
722
732
new (outString) String (getFieldName (Description.CaseNames , tag));
723
733
new (outMirror) Mirror (reflect (owner, value, payloadType));
724
734
}
@@ -970,10 +980,10 @@ void swift_ObjCMirror_subscript(String *outString,
970
980
}
971
981
972
982
SWIFT_RUNTIME_STDLIB_INTERFACE
973
- extern " C" OptionalPlaygroundQuickLook
974
- swift_ClassMirror_quickLookObject (HeapObject *owner, const OpaqueValue *value,
983
+ extern " C" void
984
+ swift_ClassMirror_quickLookObject (OptionalPlaygroundQuickLook &result,
985
+ HeapObject *owner, const OpaqueValue *value,
975
986
const Metadata *type) {
976
- OptionalPlaygroundQuickLook result;
977
987
memset (&result, 0 , sizeof (result));
978
988
979
989
id object = [*reinterpret_cast<const id *>(value) retain ];
@@ -1013,7 +1023,7 @@ void swift_ObjCMirror_subscript(String *outString,
1013
1023
1014
1024
[object release ];
1015
1025
result.optional .isNone = false ;
1016
- return result ;
1026
+ return ;
1017
1027
}
1018
1028
1019
1029
// Various other framework types are used for rich representations.
@@ -1028,7 +1038,7 @@ void swift_ObjCMirror_subscript(String *outString,
1028
1038
initializeAnyWithTakeOfObject (result.payload .Any , object);
1029
1039
result.payload .Kind = PlaygroundQuickLook::Tag::AttributedString;
1030
1040
result.optional .isNone = false ;
1031
- return result ;
1041
+ return ;
1032
1042
} else if ([object isKindOfClass: NSClassFromString (@" NSImage" )]
1033
1043
|| [object isKindOfClass: NSClassFromString (@" UIImage" )]
1034
1044
|| [object isKindOfClass: NSClassFromString (@" NSImageView" )]
@@ -1038,31 +1048,30 @@ void swift_ObjCMirror_subscript(String *outString,
1038
1048
initializeAnyWithTakeOfObject (result.payload .Any , object);
1039
1049
result.payload .Kind = PlaygroundQuickLook::Tag::Image;
1040
1050
result.optional .isNone = false ;
1041
- return result ;
1051
+ return ;
1042
1052
} else if ([object isKindOfClass: NSClassFromString (@" NSColor" )]
1043
1053
|| [object isKindOfClass: NSClassFromString (@" UIColor" )]) {
1044
1054
initializeAnyWithTakeOfObject (result.payload .Any , object);
1045
1055
result.payload .Kind = PlaygroundQuickLook::Tag::Color;
1046
1056
result.optional .isNone = false ;
1047
- return result ;
1057
+ return ;
1048
1058
} else if ([object isKindOfClass: NSClassFromString (@" NSBezierPath" )]
1049
1059
|| [object isKindOfClass: NSClassFromString (@" UIBezierPath" )]) {
1050
1060
initializeAnyWithTakeOfObject (result.payload .Any , object);
1051
1061
result.payload .Kind = PlaygroundQuickLook::Tag::BezierPath;
1052
1062
result.optional .isNone = false ;
1053
- return result ;
1063
+ return ;
1054
1064
} else if ([object isKindOfClass: [NSString class ]]) {
1055
1065
result.payload .TextOrURL = String ((NSString *)object);
1056
1066
[object release ];
1057
1067
result.payload .Kind = PlaygroundQuickLook::Tag::Text;
1058
1068
result.optional .isNone = false ;
1059
- return result ;
1069
+ return ;
1060
1070
}
1061
1071
1062
1072
// Return none if we didn't get a suitable object.
1063
1073
[object release ];
1064
1074
result.optional .isNone = true ;
1065
- return result;
1066
1075
}
1067
1076
#endif
1068
1077
0 commit comments