Skip to content

Commit ff4ecd2

Browse files
authored
[include] Use nullptr instead of NULL (swiftlang#28509)
NFC, gardening.
1 parent 2e20f7f commit ff4ecd2

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

include/swift/Basic/Diff.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,19 +1242,19 @@ class diff_match_patch {
12421242
int count_insert = 0;
12431243
string_t text_delete;
12441244
string_t text_insert;
1245-
Diff *prevEqual = NULL;
1245+
Diff *prevEqual = nullptr;
12461246
int commonlength;
12471247
for (cur_diff = diffs.begin(); cur_diff != diffs.end(); ++cur_diff) {
12481248
switch ((*cur_diff).operation) {
12491249
case INSERT:
12501250
count_insert++;
12511251
text_insert += (*cur_diff).text;
1252-
prevEqual = NULL;
1252+
prevEqual = nullptr;
12531253
break;
12541254
case DELETE:
12551255
count_delete++;
12561256
text_delete += (*cur_diff).text;
1257-
prevEqual = NULL;
1257+
prevEqual = nullptr;
12581258
break;
12591259
case EQUAL:
12601260
if (count_delete + count_insert > 1) {
@@ -1296,7 +1296,7 @@ class diff_match_patch {
12961296
if (!text_insert.empty()) {
12971297
diffs.insert(cur_diff, Diff(INSERT, text_insert));
12981298
}
1299-
} else if (prevEqual != NULL) {
1299+
} else if (prevEqual != nullptr) {
13001300
// Merge this equality with the previous one.
13011301
prevEqual->text += (*cur_diff).text;
13021302
diffs.erase(cur_diff--);
@@ -1672,7 +1672,7 @@ class diff_match_patch {
16721672
int bin_min, bin_mid;
16731673
int bin_max = pattern.length() + text.length();
16741674
int *rd;
1675-
int *last_rd = NULL;
1675+
int *last_rd = nullptr;
16761676
for (int d = 0; d < (int)pattern.length(); d++) {
16771677
// Scan for the best match; each iteration allows for one more error.
16781678
// Run a binary search to determine how far from 'loc' we can stray at
@@ -2571,7 +2571,7 @@ template <> struct diff_match_patch_traits<wchar_t> : diff_match_patch_utf32_fro
25712571
static bool is_alnum(wchar_t c) { return std::iswalnum(c)? true : false; }
25722572
static bool is_digit(wchar_t c) { return std::iswdigit(c)? true : false; }
25732573
static bool is_space(wchar_t c) { return std::iswspace(c)? true : false; }
2574-
static int to_int(const wchar_t* s) { return static_cast<int>(std::wcstol(s, NULL, 10)); }
2574+
static int to_int(const wchar_t* s) { return static_cast<int>(std::wcstol(s, nullptr, 10)); }
25752575
static wchar_t from_wchar(wchar_t c) { return c; }
25762576
static wchar_t to_wchar(wchar_t c) { return c; }
25772577
static const wchar_t* cs(const wchar_t* s) { return s; }

include/swift/SwiftRemoteMirror/SwiftRemoteMirrorLegacyInterop.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ swift_reflection_interop_libraryOwnsAddress(
353353
// Search the images list to see if the address is in one of them.
354354
struct SwiftReflectionInteropContextLegacyImageRangeList *Node =
355355
ContextRef->LegacyImageRangeList;
356-
while (Node != NULL) {
356+
while (Node != nullptr) {
357357
if (Node->Start <= Address && Address < Node->End)
358358
return 1;
359359
Node = Node->Next;
@@ -380,7 +380,7 @@ swift_reflection_interop_libraryForAddress(
380380
return Library;
381381
}
382382
}
383-
return NULL;
383+
return nullptr;
384384
}
385385

386386
static inline uintptr_t
@@ -408,7 +408,7 @@ swift_reflection_interop_libraryForObject(
408408
if (Library->IsLegacy)
409409
return Library;
410410
}
411-
return NULL;
411+
return nullptr;
412412
}
413413

414414
return swift_reflection_interop_libraryForAddress(ContextRef, Metadata);
@@ -417,7 +417,7 @@ swift_reflection_interop_libraryForObject(
417417
static inline int
418418
swift_reflection_interop_loadFunctions(struct SwiftReflectionInteropContext *Context,
419419
void *Handle) {
420-
if (Handle == NULL)
420+
if (Handle == nullptr)
421421
return 0;
422422

423423
struct SwiftReflectionInteropContextLibrary *Library = &Context
@@ -429,7 +429,7 @@ swift_reflection_interop_loadFunctions(struct SwiftReflectionInteropContext *Con
429429
#endif
430430
#define LOAD_NAMED(field, symbol, required) do { \
431431
Functions->field = (decltype(Functions->field))dlsym(Handle, symbol); \
432-
if (required && Functions->field == NULL) return 0; \
432+
if (required && Functions->field == nullptr) return 0; \
433433
} while (0)
434434
#define LOAD(name) LOAD_NAMED(name, "swift_reflection_" #name, 1)
435435
#define LOAD_OPT(name) LOAD_NAMED(name, "swift_reflection_" #name, 0)
@@ -441,7 +441,7 @@ swift_reflection_interop_loadFunctions(struct SwiftReflectionInteropContext *Con
441441
if (version < SWIFT_LEGACY_METADATA_MIN_VERSION)
442442
return 0;
443443

444-
int IsLegacy = dlsym(Handle, "swift_reflection_addImage") == NULL;
444+
int IsLegacy = dlsym(Handle, "swift_reflection_addImage") == nullptr;
445445

446446
if (IsLegacy) {
447447
LOAD_NAMED(createReflectionContextLegacy, "swift_reflection_createReflectionContext", 1);
@@ -498,11 +498,11 @@ swift_reflection_interop_readBytesAdapter(void *reader_context,
498498
void *FreeContext;
499499
const void *ptr = Context->ReadBytes(Context->ReaderContext, address, size,
500500
&FreeContext);
501-
if (ptr == NULL)
501+
if (ptr == nullptr)
502502
return 0;
503503

504504
memcpy(dest, ptr, size);
505-
if (Context->FreeBytes != NULL)
505+
if (Context->FreeBytes != nullptr)
506506
Context->FreeBytes(Context->ReaderContext, ptr, FreeContext);
507507
return 1;
508508
}
@@ -574,7 +574,7 @@ swift_reflection_interop_createReflectionContext(
574574

575575
return swift_reflection_interop_createReflectionContextWithDataLayout(
576576
ReaderContext,
577-
NULL,
577+
nullptr,
578578
FreeBytes,
579579
ReadBytes,
580580
GetStringLength,
@@ -600,7 +600,7 @@ swift_reflection_interop_createReflectionContextWithDataLayout(
600600
ContextRef->GetStringLength = GetStringLength;
601601
ContextRef->GetSymbolAddress = GetSymbolAddress;
602602

603-
ContextRef->AddressToLibraryCache = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);
603+
ContextRef->AddressToLibraryCache = CFDictionaryCreateMutable(nullptr, 0, nullptr, nullptr);
604604

605605
return ContextRef;
606606
}
@@ -633,7 +633,7 @@ swift_reflection_interop_addLibrary(
633633
} else {
634634
uint8_t PointerSize;
635635
int result = ContextRef->DataLayout(
636-
ContextRef->ReaderContext, DLQ_GetPointerSize, NULL, &PointerSize);
636+
ContextRef->ReaderContext, DLQ_GetPointerSize, nullptr, &PointerSize);
637637
if (!result)
638638
abort(); // We need the pointer size, can't proceed without it.
639639

@@ -658,14 +658,14 @@ swift_reflection_interop_destroyReflectionContext(
658658
free(ContextRef->Libraries);
659659
struct SwiftReflectionInteropContextLegacyImageRangeList *LegacyImageRangeList
660660
= ContextRef->LegacyImageRangeList;
661-
while (LegacyImageRangeList != NULL) {
661+
while (LegacyImageRangeList != nullptr) {
662662
struct SwiftReflectionInteropContextLegacyImageRangeList *Next
663663
= LegacyImageRangeList->Next;
664664
free(LegacyImageRangeList);
665665
LegacyImageRangeList = Next;
666666
}
667667
struct SwiftReflectionInteropContextFreeList *FreeList = ContextRef->FreeList;
668-
while (FreeList != NULL) {
668+
while (FreeList != nullptr) {
669669
ContextRef->FreeBytes(ContextRef->ReaderContext,
670670
FreeList->Pointer, FreeList->Context);
671671
struct SwiftReflectionInteropContextFreeList *Next = FreeList->Next;
@@ -717,37 +717,37 @@ swift_reflection_interop_addImageLegacy(
717717
ImageStart,
718718
sizeof(MachHeader),
719719
&FreeContext);
720-
if (Buf == NULL)
720+
if (Buf == nullptr)
721721
return 0;
722722

723723
MachHeader *Header = (MachHeader *)Buf;
724724

725725
if (Header->magic != MH_MAGIC && Header->magic != MH_MAGIC_64) {
726-
if (ContextRef->FreeBytes != NULL)
726+
if (ContextRef->FreeBytes != nullptr)
727727
ContextRef->FreeBytes(ContextRef->ReaderContext, Buf, FreeContext);
728728
return 0;
729729
}
730730

731731
// Read the commands.
732732
uint32_t Length = Header->sizeofcmds;
733-
if (ContextRef->FreeBytes != NULL)
733+
if (ContextRef->FreeBytes != nullptr)
734734
ContextRef->FreeBytes(ContextRef->ReaderContext, Buf, FreeContext);
735735

736736
Buf = ContextRef->ReadBytes(ContextRef->ReaderContext,
737737
ImageStart,
738738
Length,
739739
&FreeContext);
740-
if (Buf == NULL)
740+
if (Buf == nullptr)
741741
return 0;
742742
Header = (MachHeader *)Buf;
743743

744744
// Find the TEXT segment and figure out where the end is.
745745
unsigned long TextSize;
746746
uint8_t *TextSegment = getsegmentdata(Header, "__TEXT", &TextSize);
747-
if (ContextRef->FreeBytes != NULL)
747+
if (ContextRef->FreeBytes != nullptr)
748748
ContextRef->FreeBytes(ContextRef->ReaderContext, Buf, FreeContext);
749749

750-
if (TextSegment == NULL) {
750+
if (TextSegment == nullptr) {
751751
return 0;
752752
}
753753
unsigned long TextEnd = TextSegment - (uint8_t *)Buf + TextSize;
@@ -757,7 +757,7 @@ swift_reflection_interop_addImageLegacy(
757757
ImageStart,
758758
TextEnd,
759759
&FreeContext);
760-
if (Buf == NULL)
760+
if (Buf == nullptr)
761761
return 0;
762762
Header = (MachHeader *)Buf;
763763

@@ -785,7 +785,7 @@ swift_reflection_interop_addImageLegacy(
785785
&info.reflstr) || success;
786786

787787
if (!success) {
788-
if (ContextRef->FreeBytes != NULL)
788+
if (ContextRef->FreeBytes != nullptr)
789789
ContextRef->FreeBytes(ContextRef->ReaderContext, Buf, FreeContext);
790790
return 0;
791791
}
@@ -809,7 +809,7 @@ swift_reflection_interop_addImageLegacy(
809809

810810
// If the buffer needs to be freed, save buffer and free context to free it when the
811811
// reflection context is destroyed.
812-
if (ContextRef->FreeBytes != NULL) {
812+
if (ContextRef->FreeBytes != nullptr) {
813813
struct SwiftReflectionInteropContextFreeList *FreeListNode =
814814
(struct SwiftReflectionInteropContextFreeList *)malloc(sizeof(*FreeListNode));
815815
FreeListNode->Next = ContextRef->FreeList;
@@ -857,7 +857,7 @@ swift_reflection_interop_lookupMetadata(SwiftReflectionInteropContextRef Context
857857
swift_metadata_interop_t Result = {};
858858
struct SwiftReflectionInteropContextLibrary *Library =
859859
swift_reflection_interop_libraryForAddress(ContextRef, Metadata);
860-
if (Library != NULL) {
860+
if (Library != nullptr) {
861861
Result.Metadata = Metadata;
862862
Result.Library = (int)LIBRARY_INDEX;
863863
}
@@ -881,7 +881,7 @@ swift_reflection_interop_typeRefForInstance(SwiftReflectionInteropContextRef Con
881881
swift_typeref_interop_t Result = {};
882882
struct SwiftReflectionInteropContextLibrary *Library
883883
= swift_reflection_interop_libraryForObject(ContextRef, Object);
884-
if (Library != NULL) {
884+
if (Library != nullptr) {
885885
swift_typeref_t Typeref = Library->Functions.typeRefForInstance(Library->Context,
886886
Object);
887887
Result.Typeref = Typeref;
@@ -967,7 +967,7 @@ swift_reflection_interop_infoForInstance(SwiftReflectionInteropContextRef Contex
967967
struct SwiftReflectionInteropContextLibrary *Library
968968
= swift_reflection_interop_libraryForObject(ContextRef, Object);
969969

970-
if (Library != NULL) {
970+
if (Library != nullptr) {
971971
Result = Library->Functions.infoForInstance(Library->Context, Object);
972972
} else {
973973
Result.Kind = SWIFT_UNKNOWN;
@@ -983,7 +983,7 @@ swift_reflection_interop_childOfInstance(SwiftReflectionInteropContextRef Contex
983983
swift_childinfo_interop_t Result = {};
984984
struct SwiftReflectionInteropContextLibrary *Library
985985
= swift_reflection_interop_libraryForObject(ContextRef, Object);
986-
if (Library != NULL) {
986+
if (Library != nullptr) {
987987
swift_childinfo_t LibResult = Library->Functions.childOfInstance(Library->Context,
988988
Object, Index);
989989
Result.Name = LibResult.Name;
@@ -1061,7 +1061,7 @@ swift_reflection_interop_dumpInfoForInstance(SwiftReflectionInteropContextRef Co
10611061
uintptr_t Object) {
10621062
struct SwiftReflectionInteropContextLibrary *Library
10631063
= swift_reflection_interop_libraryForObject(ContextRef, Object);
1064-
if (Library != NULL) {
1064+
if (Library != nullptr) {
10651065
Library->Functions.dumpInfoForInstance(Library->Context, Object);
10661066
}
10671067
}

0 commit comments

Comments
 (0)