@@ -101,6 +101,11 @@ swift_reflection_interop_typeRefForMangledTypeName(
101
101
const char *MangledName,
102
102
uint64_t Length);
103
103
104
+ static inline char *
105
+ swift_reflection_interop_copyDemangledNameForTypeRef (
106
+ SwiftReflectionInteropContextRef ContextRef,
107
+ swift_typeref_interop_t OpaqueTypeRef);
108
+
104
109
static inline swift_typeinfo_t
105
110
swift_reflection_interop_infoForTypeRef (SwiftReflectionInteropContextRef ContextRef,
106
111
swift_typeref_interop_t OpaqueTypeRef);
@@ -250,6 +255,9 @@ struct SwiftReflectionFunctions {
250
255
const char *MangledName,
251
256
uint64_t Length);
252
257
258
+ char * (*copyDemangledNameForTypeRef)(
259
+ SwiftReflectionContextRef ContextRef, swift_typeref_t OpaqueTypeRef);
260
+
253
261
swift_typeinfo_t (*infoForTypeRef)(SwiftReflectionContextRef ContextRef,
254
262
swift_typeref_t OpaqueTypeRef);
255
263
@@ -354,7 +362,7 @@ swift_reflection_interop_libraryOwnsAddress(
354
362
// Search the images list to see if the address is in one of them.
355
363
struct SwiftReflectionInteropContextLegacyImageRangeList *Node =
356
364
ContextRef->LegacyImageRangeList ;
357
- while (Node != nullptr ) {
365
+ while (Node != NULL ) {
358
366
if (Node->Start <= Address && Address < Node->End )
359
367
return 1 ;
360
368
Node = Node->Next ;
@@ -381,7 +389,7 @@ swift_reflection_interop_libraryForAddress(
381
389
return Library;
382
390
}
383
391
}
384
- return nullptr ;
392
+ return NULL ;
385
393
}
386
394
387
395
static inline uintptr_t
@@ -409,7 +417,7 @@ swift_reflection_interop_libraryForObject(
409
417
if (Library->IsLegacy )
410
418
return Library;
411
419
}
412
- return nullptr ;
420
+ return NULL ;
413
421
}
414
422
415
423
return swift_reflection_interop_libraryForAddress (ContextRef, Metadata);
@@ -418,7 +426,7 @@ swift_reflection_interop_libraryForObject(
418
426
static inline int
419
427
swift_reflection_interop_loadFunctions (struct SwiftReflectionInteropContext *Context,
420
428
void *Handle) {
421
- if (Handle == nullptr )
429
+ if (Handle == NULL )
422
430
return 0 ;
423
431
424
432
struct SwiftReflectionInteropContextLibrary *Library = &Context
@@ -430,7 +438,7 @@ swift_reflection_interop_loadFunctions(struct SwiftReflectionInteropContext *Con
430
438
#endif
431
439
#define LOAD_NAMED (field, symbol, required ) do { \
432
440
Functions->field = (decltype (Functions->field ))dlsym (Handle, symbol); \
433
- if (required && Functions->field == nullptr ) return 0 ; \
441
+ if (required && Functions->field == NULL ) return 0 ; \
434
442
} while (0 )
435
443
#define LOAD (name ) LOAD_NAMED(name, " swift_reflection_" #name, 1 )
436
444
#define LOAD_OPT (name ) LOAD_NAMED(name, " swift_reflection_" #name, 0 )
@@ -442,7 +450,7 @@ swift_reflection_interop_loadFunctions(struct SwiftReflectionInteropContext *Con
442
450
if (version < SWIFT_LEGACY_METADATA_MIN_VERSION)
443
451
return 0 ;
444
452
445
- int IsLegacy = dlsym (Handle, " swift_reflection_addImage" ) == nullptr ;
453
+ int IsLegacy = dlsym (Handle, " swift_reflection_addImage" ) == NULL ;
446
454
447
455
if (IsLegacy) {
448
456
LOAD_NAMED (createReflectionContextLegacy, " swift_reflection_createReflectionContext" , 1 );
@@ -464,6 +472,7 @@ swift_reflection_interop_loadFunctions(struct SwiftReflectionInteropContext *Con
464
472
LOAD (typeRefForMetadata);
465
473
LOAD (typeRefForInstance);
466
474
LOAD (typeRefForMangledTypeName);
475
+ LOAD_OPT (copyDemangledNameForTypeRef);
467
476
LOAD (infoForTypeRef);
468
477
LOAD (childOfTypeRef);
469
478
LOAD (infoForMetadata);
@@ -499,11 +508,11 @@ swift_reflection_interop_readBytesAdapter(void *reader_context,
499
508
void *FreeContext;
500
509
const void *ptr = Context->ReadBytes (Context->ReaderContext , address, size,
501
510
&FreeContext);
502
- if (ptr == nullptr )
511
+ if (ptr == NULL )
503
512
return 0 ;
504
513
505
514
memcpy (dest, ptr, size);
506
- if (Context->FreeBytes != nullptr )
515
+ if (Context->FreeBytes != NULL )
507
516
Context->FreeBytes (Context->ReaderContext , ptr, FreeContext);
508
517
return 1 ;
509
518
}
@@ -536,6 +545,8 @@ swift_reflection_interop_minimalDataLayoutQueryFunction4(
536
545
void *ReaderContext,
537
546
DataLayoutQueryType type,
538
547
void *inBuffer, void *outBuffer) {
548
+ (void )ReaderContext;
549
+ (void )inBuffer;
539
550
switch (type) {
540
551
case DLQ_GetPointerSize:
541
552
case DLQ_GetSizeSize: {
@@ -565,17 +576,19 @@ swift_reflection_interop_minimalDataLayoutQueryFunction8(
565
576
void *ReaderContext,
566
577
DataLayoutQueryType type,
567
578
void *inBuffer, void *outBuffer) {
579
+ (void )ReaderContext;
580
+ (void )inBuffer;
568
581
// Caveat: This assumes the process being examined is
569
582
// running in the same kind of environment as this host code.
570
583
#if defined(__APPLE__) && __APPLE__
571
- auto applePlatform = true ;
584
+ int applePlatform = 1 ;
572
585
#else
573
- auto applePlatform = false ;
586
+ int applePlatform = 0 ;
574
587
#endif
575
588
#if defined(__APPLE__) && __APPLE__ && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_IOS) && TARGET_OS_WATCH) || (defined(TARGET_OS_TV) && TARGET_OS_TV))
576
- auto iosDerivedPlatform = true ;
589
+ int iosDerivedPlatform = 1 ;
577
590
#else
578
- auto iosDerivedPlatform = false ;
591
+ int iosDerivedPlatform = 0 ;
579
592
#endif
580
593
581
594
switch (type) {
@@ -628,7 +641,7 @@ swift_reflection_interop_createReflectionContext(
628
641
629
642
return swift_reflection_interop_createReflectionContextWithDataLayout (
630
643
ReaderContext,
631
- nullptr ,
644
+ DataLayout ,
632
645
FreeBytes,
633
646
ReadBytes,
634
647
GetStringLength,
@@ -654,7 +667,7 @@ swift_reflection_interop_createReflectionContextWithDataLayout(
654
667
ContextRef->GetStringLength = GetStringLength;
655
668
ContextRef->GetSymbolAddress = GetSymbolAddress;
656
669
657
- ContextRef->AddressToLibraryCache = CFDictionaryCreateMutable (nullptr , 0 , nullptr , nullptr );
670
+ ContextRef->AddressToLibraryCache = CFDictionaryCreateMutable (NULL , 0 , NULL , NULL );
658
671
659
672
return ContextRef;
660
673
}
@@ -687,7 +700,7 @@ swift_reflection_interop_addLibrary(
687
700
} else {
688
701
uint8_t PointerSize;
689
702
int result = ContextRef->DataLayout (
690
- ContextRef->ReaderContext , DLQ_GetPointerSize, nullptr , &PointerSize);
703
+ ContextRef->ReaderContext , DLQ_GetPointerSize, NULL , &PointerSize);
691
704
if (!result)
692
705
abort (); // We need the pointer size, can't proceed without it.
693
706
@@ -712,14 +725,14 @@ swift_reflection_interop_destroyReflectionContext(
712
725
free (ContextRef->Libraries );
713
726
struct SwiftReflectionInteropContextLegacyImageRangeList *LegacyImageRangeList
714
727
= ContextRef->LegacyImageRangeList ;
715
- while (LegacyImageRangeList != nullptr ) {
728
+ while (LegacyImageRangeList != NULL ) {
716
729
struct SwiftReflectionInteropContextLegacyImageRangeList *Next
717
730
= LegacyImageRangeList->Next ;
718
731
free (LegacyImageRangeList);
719
732
LegacyImageRangeList = Next;
720
733
}
721
734
struct SwiftReflectionInteropContextFreeList *FreeList = ContextRef->FreeList ;
722
- while (FreeList != nullptr ) {
735
+ while (FreeList != NULL ) {
723
736
ContextRef->FreeBytes (ContextRef->ReaderContext ,
724
737
FreeList->Pointer , FreeList->Context );
725
738
struct SwiftReflectionInteropContextFreeList *Next = FreeList->Next ;
@@ -771,37 +784,37 @@ swift_reflection_interop_addImageLegacy(
771
784
ImageStart,
772
785
sizeof (MachHeader),
773
786
&FreeContext);
774
- if (Buf == nullptr )
787
+ if (Buf == NULL )
775
788
return 0 ;
776
789
777
790
MachHeader *Header = (MachHeader *)Buf;
778
791
779
792
if (Header->magic != MH_MAGIC && Header->magic != MH_MAGIC_64) {
780
- if (ContextRef->FreeBytes != nullptr )
793
+ if (ContextRef->FreeBytes != NULL )
781
794
ContextRef->FreeBytes (ContextRef->ReaderContext , Buf, FreeContext);
782
795
return 0 ;
783
796
}
784
797
785
798
// Read the commands.
786
799
uint32_t Length = Header->sizeofcmds ;
787
- if (ContextRef->FreeBytes != nullptr )
800
+ if (ContextRef->FreeBytes != NULL )
788
801
ContextRef->FreeBytes (ContextRef->ReaderContext , Buf, FreeContext);
789
802
790
803
Buf = ContextRef->ReadBytes (ContextRef->ReaderContext ,
791
804
ImageStart,
792
805
Length,
793
806
&FreeContext);
794
- if (Buf == nullptr )
807
+ if (Buf == NULL )
795
808
return 0 ;
796
809
Header = (MachHeader *)Buf;
797
810
798
811
// Find the TEXT segment and figure out where the end is.
799
812
unsigned long TextSize;
800
813
uint8_t *TextSegment = getsegmentdata (Header, " __TEXT" , &TextSize);
801
- if (ContextRef->FreeBytes != nullptr )
814
+ if (ContextRef->FreeBytes != NULL )
802
815
ContextRef->FreeBytes (ContextRef->ReaderContext , Buf, FreeContext);
803
816
804
- if (TextSegment == nullptr ) {
817
+ if (TextSegment == NULL ) {
805
818
return 0 ;
806
819
}
807
820
unsigned long TextEnd = TextSegment - (uint8_t *)Buf + TextSize;
@@ -811,7 +824,7 @@ swift_reflection_interop_addImageLegacy(
811
824
ImageStart,
812
825
TextEnd,
813
826
&FreeContext);
814
- if (Buf == nullptr )
827
+ if (Buf == NULL )
815
828
return 0 ;
816
829
Header = (MachHeader *)Buf;
817
830
@@ -839,7 +852,7 @@ swift_reflection_interop_addImageLegacy(
839
852
&info.reflstr ) || success;
840
853
841
854
if (!success) {
842
- if (ContextRef->FreeBytes != nullptr )
855
+ if (ContextRef->FreeBytes != NULL )
843
856
ContextRef->FreeBytes (ContextRef->ReaderContext , Buf, FreeContext);
844
857
return 0 ;
845
858
}
@@ -863,7 +876,7 @@ swift_reflection_interop_addImageLegacy(
863
876
864
877
// If the buffer needs to be freed, save buffer and free context to free it when the
865
878
// reflection context is destroyed.
866
- if (ContextRef->FreeBytes != nullptr ) {
879
+ if (ContextRef->FreeBytes != NULL ) {
867
880
struct SwiftReflectionInteropContextFreeList *FreeListNode =
868
881
(struct SwiftReflectionInteropContextFreeList *)malloc (sizeof (*FreeListNode));
869
882
FreeListNode->Next = ContextRef->FreeList ;
@@ -911,7 +924,7 @@ swift_reflection_interop_lookupMetadata(SwiftReflectionInteropContextRef Context
911
924
swift_metadata_interop_t Result = {};
912
925
struct SwiftReflectionInteropContextLibrary *Library =
913
926
swift_reflection_interop_libraryForAddress (ContextRef, Metadata);
914
- if (Library != nullptr ) {
927
+ if (Library != NULL ) {
915
928
Result.Metadata = Metadata;
916
929
Result.Library = (int )LIBRARY_INDEX;
917
930
}
@@ -935,7 +948,7 @@ swift_reflection_interop_typeRefForInstance(SwiftReflectionInteropContextRef Con
935
948
swift_typeref_interop_t Result = {};
936
949
struct SwiftReflectionInteropContextLibrary *Library
937
950
= swift_reflection_interop_libraryForObject (ContextRef, Object);
938
- if (Library != nullptr ) {
951
+ if (Library != NULL ) {
939
952
swift_typeref_t Typeref = Library->Functions .typeRefForInstance (Library->Context ,
940
953
Object);
941
954
Result.Typeref = Typeref;
@@ -966,6 +979,17 @@ swift_reflection_interop_typeRefForMangledTypeName(
966
979
return Result;
967
980
}
968
981
982
+ static inline char *
983
+ swift_reflection_interop_copyDemangledNameForTypeRef (
984
+ SwiftReflectionInteropContextRef ContextRef,
985
+ swift_typeref_interop_t OpaqueTypeRef) {
986
+ DECLARE_LIBRARY (OpaqueTypeRef.Library );
987
+ if (Library->Functions .copyDemangledNameForTypeRef )
988
+ return Library->Functions .copyDemangledNameForTypeRef (Library->Context ,
989
+ OpaqueTypeRef.Typeref );
990
+ return NULL ;
991
+ }
992
+
969
993
static inline swift_typeinfo_t
970
994
swift_reflection_interop_infoForTypeRef (SwiftReflectionInteropContextRef ContextRef,
971
995
swift_typeref_interop_t OpaqueTypeRef) {
@@ -1021,7 +1045,7 @@ swift_reflection_interop_infoForInstance(SwiftReflectionInteropContextRef Contex
1021
1045
struct SwiftReflectionInteropContextLibrary *Library
1022
1046
= swift_reflection_interop_libraryForObject (ContextRef, Object);
1023
1047
1024
- if (Library != nullptr ) {
1048
+ if (Library != NULL ) {
1025
1049
Result = Library->Functions .infoForInstance (Library->Context , Object);
1026
1050
} else {
1027
1051
Result.Kind = SWIFT_UNKNOWN;
@@ -1037,7 +1061,7 @@ swift_reflection_interop_childOfInstance(SwiftReflectionInteropContextRef Contex
1037
1061
swift_childinfo_interop_t Result = {};
1038
1062
struct SwiftReflectionInteropContextLibrary *Library
1039
1063
= swift_reflection_interop_libraryForObject (ContextRef, Object);
1040
- if (Library != nullptr ) {
1064
+ if (Library != NULL ) {
1041
1065
swift_childinfo_t LibResult = Library->Functions .childOfInstance (Library->Context ,
1042
1066
Object, Index);
1043
1067
Result.Name = LibResult.Name ;
@@ -1115,7 +1139,7 @@ swift_reflection_interop_dumpInfoForInstance(SwiftReflectionInteropContextRef Co
1115
1139
uintptr_t Object) {
1116
1140
struct SwiftReflectionInteropContextLibrary *Library
1117
1141
= swift_reflection_interop_libraryForObject (ContextRef, Object);
1118
- if (Library != nullptr ) {
1142
+ if (Library != NULL ) {
1119
1143
Library->Functions .dumpInfoForInstance (Library->Context , Object);
1120
1144
}
1121
1145
}
0 commit comments