Skip to content

Commit

Permalink
[libc++][NFC] Replace uses of NULL by nullptr (llvm#108847)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldionne authored and tmsri committed Sep 19, 2024
1 parent 6bbc226 commit 7fd59f0
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions libcxx/include/__locale_dir/locale_base_api/ibm.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ strtoull_l(const char* __nptr, char** __endptr, int __base, locale_t locale) {
inline _LIBCPP_HIDE_FROM_ABI
_LIBCPP_ATTRIBUTE_FORMAT(__printf__, 2, 0) int vasprintf(char** strp, const char* fmt, va_list ap) {
const size_t buff_size = 256;
if ((*strp = (char*)malloc(buff_size)) == NULL) {
if ((*strp = (char*)malloc(buff_size)) == nullptr) {
return -1;
}

Expand All @@ -97,7 +97,7 @@ _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 2, 0) int vasprintf(char** strp, const char
va_end(ap_copy);

if ((size_t)str_size >= buff_size) {
if ((*strp = (char*)realloc(*strp, str_size + 1)) == NULL) {
if ((*strp = (char*)realloc(*strp, str_size + 1)) == nullptr) {
return -1;
}
str_size = vsnprintf(*strp, str_size + 1, fmt, ap);
Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/__support/xlocale/__nop_locale_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
// Patch over lack of extended locale support
typedef void* locale_t;

inline _LIBCPP_HIDE_FROM_ABI locale_t duplocale(locale_t) { return NULL; }
inline _LIBCPP_HIDE_FROM_ABI locale_t duplocale(locale_t) { return nullptr; }

inline _LIBCPP_HIDE_FROM_ABI void freelocale(locale_t) {}

inline _LIBCPP_HIDE_FROM_ABI locale_t newlocale(int, const char*, locale_t) { return NULL; }
inline _LIBCPP_HIDE_FROM_ABI locale_t newlocale(int, const char*, locale_t) { return nullptr; }

inline _LIBCPP_HIDE_FROM_ABI locale_t uselocale(locale_t) { return NULL; }
inline _LIBCPP_HIDE_FROM_ABI locale_t uselocale(locale_t) { return nullptr; }

#define LC_COLLATE_MASK (1 << LC_COLLATE)
#define LC_CTYPE_MASK (1 << LC_CTYPE)
Expand Down
4 changes: 2 additions & 2 deletions libcxx/src/atomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const vo

static void
__libcpp_platform_wait_on_address(__cxx_atomic_contention_t const volatile* __ptr, __cxx_contention_t __val) {
_umtx_op(const_cast<__cxx_atomic_contention_t*>(__ptr), UMTX_OP_WAIT, __val, NULL, NULL);
_umtx_op(const_cast<__cxx_atomic_contention_t*>(__ptr), UMTX_OP_WAIT, __val, nullptr, nullptr);
}

static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile* __ptr, bool __notify_one) {
_umtx_op(const_cast<__cxx_atomic_contention_t*>(__ptr), UMTX_OP_WAKE, __notify_one ? 1 : INT_MAX, NULL, NULL);
_umtx_op(const_cast<__cxx_atomic_contention_t*>(__ptr), UMTX_OP_WAKE, __notify_one ? 1 : INT_MAX, nullptr, nullptr);
}

#else // <- Add other operating systems here
Expand Down
2 changes: 1 addition & 1 deletion libcxx/src/locale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ const ctype<char>::mask* ctype<char>::classic_table() noexcept {
# warning ctype<char>::classic_table() is not implemented
printf("ctype<char>::classic_table() is not implemented\n");
abort();
return NULL;
return nullptr;
# endif
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions libcxx/src/support/ibm/mbsnrtowcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ _LIBCPP_EXPORTED_FROM_ABI size_t mbsnrtowcs(
size_t dest_remaining = max_dest_chars - dest_converted;

if (dst == nullptr) {
result = mbrtowc(NULL, *src + source_converted, source_remaining, ps);
result = mbrtowc(nullptr, *src + source_converted, source_remaining, ps);
} else if (dest_remaining >= source_remaining) {
// dst has enough space to translate in-place.
result = mbrtowc(dst + dest_converted, *src + source_converted, source_remaining, ps);
Expand Down Expand Up @@ -86,7 +86,7 @@ _LIBCPP_EXPORTED_FROM_ABI size_t mbsnrtowcs(

if (dst) {
if (result == terminated_sequence)
*src = NULL;
*src = nullptr;
else
*src += source_converted;
}
Expand Down
4 changes: 2 additions & 2 deletions libcxx/src/support/ibm/wcsnrtombs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ _LIBCPP_EXPORTED_FROM_ABI size_t wcsnrtombs(
size_t dest_remaining = dst_size_bytes - dest_converted;

if (dst == nullptr) {
result = wcrtomb(NULL, c, ps);
result = wcrtomb(nullptr, c, ps);
} else if (dest_remaining >= static_cast<size_t>(MB_CUR_MAX)) {
// dst has enough space to translate in-place.
result = wcrtomb(dst + dest_converted, c, ps);
Expand Down Expand Up @@ -82,7 +82,7 @@ _LIBCPP_EXPORTED_FROM_ABI size_t wcsnrtombs(

if (c == L'\0') {
if (dst)
*src = NULL;
*src = nullptr;
return dest_converted;
}
}
Expand Down
16 changes: 8 additions & 8 deletions libcxx/src/support/ibm/xlocale_zos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ locale_t newlocale(int category_mask, const char* locale, locale_t base) {
std::string current_loc_name(setlocale(LC_ALL, 0));

// Check for errors.
if (category_mask == LC_ALL_MASK && setlocale(LC_ALL, locale) == NULL) {
if (category_mask == LC_ALL_MASK && setlocale(LC_ALL, locale) == nullptr) {
errno = EINVAL;
return (locale_t)0;
} else {
for (int _Cat = 0; _Cat <= _LC_MAX; ++_Cat) {
if ((_CATMASK(_Cat) & category_mask) != 0 && setlocale(_Cat, locale) == NULL) {
if ((_CATMASK(_Cat) & category_mask) != 0 && setlocale(_Cat, locale) == nullptr) {
setlocale(LC_ALL, current_loc_name.c_str());
errno = EINVAL;
return (locale_t)0;
Expand Down Expand Up @@ -74,12 +74,12 @@ locale_t uselocale(locale_t newloc) {
if (newloc) {
// Set locales and check for errors.
bool is_error =
(newloc->category_mask & LC_COLLATE_MASK && setlocale(LC_COLLATE, newloc->lc_collate.c_str()) == NULL) ||
(newloc->category_mask & LC_CTYPE_MASK && setlocale(LC_CTYPE, newloc->lc_ctype.c_str()) == NULL) ||
(newloc->category_mask & LC_MONETARY_MASK && setlocale(LC_MONETARY, newloc->lc_monetary.c_str()) == NULL) ||
(newloc->category_mask & LC_NUMERIC_MASK && setlocale(LC_NUMERIC, newloc->lc_numeric.c_str()) == NULL) ||
(newloc->category_mask & LC_TIME_MASK && setlocale(LC_TIME, newloc->lc_time.c_str()) == NULL) ||
(newloc->category_mask & LC_MESSAGES_MASK && setlocale(LC_MESSAGES, newloc->lc_messages.c_str()) == NULL);
(newloc->category_mask & LC_COLLATE_MASK && setlocale(LC_COLLATE, newloc->lc_collate.c_str()) == nullptr) ||
(newloc->category_mask & LC_CTYPE_MASK && setlocale(LC_CTYPE, newloc->lc_ctype.c_str()) == nullptr) ||
(newloc->category_mask & LC_MONETARY_MASK && setlocale(LC_MONETARY, newloc->lc_monetary.c_str()) == nullptr) ||
(newloc->category_mask & LC_NUMERIC_MASK && setlocale(LC_NUMERIC, newloc->lc_numeric.c_str()) == nullptr) ||
(newloc->category_mask & LC_TIME_MASK && setlocale(LC_TIME, newloc->lc_time.c_str()) == nullptr) ||
(newloc->category_mask & LC_MESSAGES_MASK && setlocale(LC_MESSAGES, newloc->lc_messages.c_str()) == nullptr);

if (is_error) {
setlocale(LC_ALL, current_loc_name.c_str());
Expand Down
12 changes: 6 additions & 6 deletions libcxx/src/support/win32/support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
// a pointer to a malloc'd string in *sptr.
// If return >= 0, use free to delete *sptr.
int __libcpp_vasprintf(char** sptr, const char* __restrict format, va_list ap) {
*sptr = NULL;
*sptr = nullptr;
// Query the count required.
va_list ap_copy;
va_copy(ap_copy, ap);
_LIBCPP_DIAGNOSTIC_PUSH
_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
int count = vsnprintf(NULL, 0, format, ap_copy);
int count = vsnprintf(nullptr, 0, format, ap_copy);
_LIBCPP_DIAGNOSTIC_POP
va_end(ap_copy);
if (count < 0)
Expand Down Expand Up @@ -81,7 +81,7 @@ size_t mbsnrtowcs(wchar_t* __restrict dst,
// if result > 0, it's the size in bytes of that character.
// othewise if result is zero it indicates the null character has been found.
// otherwise it's an error and errno may be set.
size_t char_size = mbrtowc(dst ? dst + dest_converted : NULL, *src + source_converted, source_remaining, ps);
size_t char_size = mbrtowc(dst ? dst + dest_converted : nullptr, *src + source_converted, source_remaining, ps);
// Don't do anything to change errno from here on.
if (char_size > 0) {
source_remaining -= char_size;
Expand All @@ -95,7 +95,7 @@ size_t mbsnrtowcs(wchar_t* __restrict dst,
}
if (dst) {
if (have_result && result == terminated_sequence)
*src = NULL;
*src = nullptr;
else
*src += source_converted;
}
Expand Down Expand Up @@ -141,7 +141,7 @@ size_t wcsnrtombs(char* __restrict dst,
if (dst)
result = wcrtomb_s(&char_size, dst + dest_converted, dest_remaining, c, ps);
else
result = wcrtomb_s(&char_size, NULL, 0, c, ps);
result = wcrtomb_s(&char_size, nullptr, 0, c, ps);
// If result is zero there is no error and char_size contains the
// size of the multi-byte-sequence converted.
// Otherwise result indicates an errno type error.
Expand All @@ -161,7 +161,7 @@ size_t wcsnrtombs(char* __restrict dst,
}
if (dst) {
if (terminator_found)
*src = NULL;
*src = nullptr;
else
*src = *src + source_converted;
}
Expand Down
2 changes: 1 addition & 1 deletion libcxx/src/support/win32/thread_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ __libcpp_init_once_execute_once_thunk(PINIT_ONCE __init_once, PVOID __parameter,

int __libcpp_execute_once(__libcpp_exec_once_flag* __flag, void (*__init_routine)(void)) {
if (!InitOnceExecuteOnce(
(PINIT_ONCE)__flag, __libcpp_init_once_execute_once_thunk, reinterpret_cast<void*>(__init_routine), NULL))
(PINIT_ONCE)__flag, __libcpp_init_once_execute_once_thunk, reinterpret_cast<void*>(__init_routine), nullptr))
return GetLastError();
return 0;
}
Expand Down

0 comments on commit 7fd59f0

Please sign in to comment.