@@ -332,6 +332,10 @@ static Mirror reflect(HeapObject *owner,
332
332
const OpaqueValue *mirrorValue;
333
333
std::tie (mirrorType, mirrorValue) = unwrapExistential (T, value);
334
334
335
+ #ifdef SWIFT_RUNTIME_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
336
+ swift_retain (owner);
337
+ #endif
338
+
335
339
// Use MagicMirror.
336
340
// Consumes 'owner'.
337
341
Mirror result;
@@ -346,7 +350,9 @@ intptr_t swift_TupleMirror_count(HeapObject *owner,
346
350
const OpaqueValue *value,
347
351
const Metadata *type) {
348
352
auto Tuple = static_cast <const TupleTypeMetadata *>(type);
353
+ #ifndef SWIFT_RUNTIME_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
349
354
swift_release (owner);
355
+ #endif
350
356
return Tuple->NumElements ;
351
357
}
352
358
@@ -392,6 +398,10 @@ void swift_TupleMirror_subscript(String *outString,
392
398
auto bytes = reinterpret_cast <const char *>(value);
393
399
auto eltData = reinterpret_cast <const OpaqueValue *>(bytes + elt.Offset );
394
400
401
+ #ifdef SWIFT_RUNTIME_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
402
+ swift_retain (owner);
403
+ #endif
404
+
395
405
// 'owner' is consumed by this call.
396
406
new (outMirror) Mirror (reflect (owner, eltData, elt.Type ));
397
407
}
@@ -460,13 +470,15 @@ static bool loadSpecialReferenceStorage(HeapObject *owner,
460
470
461
471
type->deallocateBufferIn (&temporaryBuffer);
462
472
473
+ #ifndef SWIFT_RUNTIME_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
463
474
// swift_StructMirror_subscript and swift_ClassMirror_subscript
464
475
// requires that the owner be consumed. Since we have the new heap box as the
465
476
// owner now, we need to release the old owner to maintain the contract.
466
477
if (owner->metadata ->isAnyClass ())
467
478
swift_unknownRelease (owner);
468
479
else
469
480
swift_release (owner);
481
+ #endif
470
482
471
483
return true ;
472
484
}
@@ -478,7 +490,9 @@ intptr_t swift_StructMirror_count(HeapObject *owner,
478
490
const OpaqueValue *value,
479
491
const Metadata *type) {
480
492
auto Struct = static_cast <const StructMetadata *>(type);
493
+ #ifndef SWIFT_RUNTIME_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
481
494
swift_release (owner);
495
+ #endif
482
496
return Struct->Description ->Struct .NumFields ;
483
497
}
484
498
@@ -563,7 +577,9 @@ static void getEnumMirrorInfo(const OpaqueValue *value,
563
577
const OpaqueValue *value,
564
578
const Metadata *type) {
565
579
if (!isEnumReflectable (type)) {
580
+ #ifndef SWIFT_RUNTIME_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
566
581
swift_release (owner);
582
+ #endif
567
583
return nullptr ;
568
584
}
569
585
@@ -573,7 +589,9 @@ static void getEnumMirrorInfo(const OpaqueValue *value,
573
589
unsigned tag;
574
590
getEnumMirrorInfo (value, type, &tag, nullptr , nullptr );
575
591
592
+ #ifndef SWIFT_RUNTIME_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
576
593
swift_release (owner);
594
+ #endif
577
595
578
596
return getFieldName (Description.CaseNames , tag);
579
597
}
@@ -588,7 +606,12 @@ static void getEnumMirrorInfo(const OpaqueValue *value,
588
606
OpaqueValue *mirrorValue = const_cast <OpaqueValue*>(cMirrorValue);
589
607
Mirror mirror;
590
608
591
- bool take = mirrorValue == value;
609
+ bool take =
610
+ #ifndef SWIFT_RUNTIME_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
611
+ mirrorValue == value;
612
+ #else
613
+ false ;
614
+ #endif
592
615
::new (&mirror) MagicMirror (mirrorValue, mirrorType, take);
593
616
594
617
MagicMirror *theMirror = reinterpret_cast <MagicMirror *>(&mirror);
@@ -602,13 +625,17 @@ intptr_t swift_EnumMirror_count(HeapObject *owner,
602
625
const OpaqueValue *value,
603
626
const Metadata *type) {
604
627
if (!isEnumReflectable (type)) {
628
+ #ifndef SWIFT_RUNTIME_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
605
629
swift_release (owner);
630
+ #endif
606
631
return 0 ;
607
632
}
608
633
609
634
const Metadata *payloadType;
610
635
getEnumMirrorInfo (value, type, nullptr , &payloadType, nullptr );
636
+ #ifndef SWIFT_RUNTIME_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
611
637
swift_release (owner);
638
+ #endif
612
639
return (payloadType != nullptr ) ? 1 : 0 ;
613
640
}
614
641
@@ -637,7 +664,9 @@ void swift_EnumMirror_subscript(String *outString,
637
664
type->vw_destructiveInjectEnumTag (const_cast <OpaqueValue *>(value),
638
665
(int ) (tag - Description.getNumPayloadCases ()));
639
666
667
+ #ifndef SWIFT_RUNTIME_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
640
668
swift_release (owner);
669
+ #endif
641
670
642
671
owner = pair.object ;
643
672
value = pair.buffer ;
@@ -665,7 +694,9 @@ intptr_t swift_ClassMirror_count(HeapObject *owner,
665
694
const OpaqueValue *value,
666
695
const Metadata *type) {
667
696
auto Clas = static_cast <const ClassMetadata*>(type);
697
+ #ifndef SWIFT_RUNTIME_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
668
698
swift_release (owner);
699
+ #endif
669
700
auto count = Clas->getDescription ()->Class .NumFields ;
670
701
671
702
// If the class has a superclass, the superclass instance is treated as the
@@ -771,7 +802,9 @@ intptr_t swift_ObjCMirror_count(HeapObject *owner,
771
802
if (isa->SuperClass )
772
803
count += 1 ;
773
804
805
+ #ifndef SWIFT_RUNTIME_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
774
806
swift_release (owner);
807
+ #endif
775
808
return count;
776
809
}
777
810
@@ -810,7 +843,9 @@ void swift_ObjCMirror_subscript(String *outString,
810
843
swift_ClassMirror_quickLookObject(HeapObject *owner, const OpaqueValue *value,
811
844
const Metadata *type) {
812
845
id object = [*reinterpret_cast<const id *>(value) retain ];
846
+ #ifndef SWIFT_RUNTIME_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
813
847
swift_release (owner);
848
+ #endif
814
849
if ([object respondsToSelector: @selector (debugQuickLookObject )]) {
815
850
id quickLookObject = [object debugQuickLookObject ];
816
851
[quickLookObject retain ];
@@ -906,6 +941,10 @@ static Mirror getMirrorForSuperclass(const ClassMetadata *sup,
906
941
Mirror resultBuf;
907
942
MagicMirror *result = ::new (&resultBuf) MagicMirror;
908
943
944
+ #ifdef SWIFT_RUNTIME_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
945
+ swift_retain (owner);
946
+ #endif
947
+
909
948
result->Self = ClassSuperMirrorMetadata ();
910
949
result->MirrorWitness = &ClassSuperMirrorWitnessTable;
911
950
result->Data .Owner = owner;
@@ -925,6 +964,10 @@ static Mirror ObjC_getMirrorForSuperclass(Class sup,
925
964
Mirror resultBuf;
926
965
MagicMirror *result = ::new (&resultBuf) MagicMirror;
927
966
967
+ #ifdef SWIFT_RUNTIME_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
968
+ swift_retain (owner);
969
+ #endif
970
+
928
971
result->Self = ObjCSuperMirrorMetadata ();
929
972
result->MirrorWitness = &ObjCSuperMirrorWitnessTable;
930
973
result->Data .Owner = owner;
@@ -1073,11 +1116,19 @@ static Mirror ObjC_getMirrorForSuperclass(Class sup,
1073
1116
Mirror result;
1074
1117
// Take the value, unless we projected a subvalue from it. We don't want to
1075
1118
// deal with partial value deinitialization.
1076
- bool take = mirrorValue == value;
1119
+ bool take =
1120
+ #ifndef SWIFT_RUNTIME_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
1121
+ mirrorValue == value;
1122
+ #else
1123
+ false ;
1124
+ #endif
1077
1125
::new (&result) MagicMirror (mirrorValue, mirrorType, take);
1126
+
1127
+ #ifndef SWIFT_RUNTIME_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
1078
1128
// Destroy the whole original value if we couldn't take it.
1079
1129
if (!take)
1080
1130
T->vw_destroy (value);
1131
+ #endif
1081
1132
return MirrorReturn (result);
1082
1133
}
1083
1134
0 commit comments