Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc++][NFC] Replace uses of NULL by nullptr #108847

Merged
merged 1 commit into from
Sep 17, 2024

Conversation

ldionne
Copy link
Member

@ldionne ldionne commented Sep 16, 2024

Closes #108741

@ldionne ldionne requested a review from a team as a code owner September 16, 2024 15:43
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Sep 16, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 16, 2024

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

Changes

Closes #108741


Full diff: https://github.com/llvm/llvm-project/pull/108847.diff

9 Files Affected:

  • (modified) libcxx/include/__locale_dir/locale_base_api/ibm.h (+2-2)
  • (modified) libcxx/include/__support/xlocale/__nop_locale_mgmt.h (+3-3)
  • (modified) libcxx/src/atomic.cpp (+2-2)
  • (modified) libcxx/src/locale.cpp (+1-1)
  • (modified) libcxx/src/support/ibm/mbsnrtowcs.cpp (+2-2)
  • (modified) libcxx/src/support/ibm/wcsnrtombs.cpp (+2-2)
  • (modified) libcxx/src/support/ibm/xlocale_zos.cpp (+8-8)
  • (modified) libcxx/src/support/win32/support.cpp (+6-6)
  • (modified) libcxx/src/support/win32/thread_win32.cpp (+1-1)
diff --git a/libcxx/include/__locale_dir/locale_base_api/ibm.h b/libcxx/include/__locale_dir/locale_base_api/ibm.h
index 01af20194428b9..fa3bc1c3633f5d 100644
--- a/libcxx/include/__locale_dir/locale_base_api/ibm.h
+++ b/libcxx/include/__locale_dir/locale_base_api/ibm.h
@@ -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;
   }
 
@@ -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);
diff --git a/libcxx/include/__support/xlocale/__nop_locale_mgmt.h b/libcxx/include/__support/xlocale/__nop_locale_mgmt.h
index b9ffcbe1622d51..5aaf3eaa6441d9 100644
--- a/libcxx/include/__support/xlocale/__nop_locale_mgmt.h
+++ b/libcxx/include/__support/xlocale/__nop_locale_mgmt.h
@@ -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)
diff --git a/libcxx/src/atomic.cpp b/libcxx/src/atomic.cpp
index ae062155661e2f..c1af8d6f95aaef 100644
--- a/libcxx/src/atomic.cpp
+++ b/libcxx/src/atomic.cpp
@@ -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
diff --git a/libcxx/src/locale.cpp b/libcxx/src/locale.cpp
index 0f87c7099fe37e..484963dcede9d5 100644
--- a/libcxx/src/locale.cpp
+++ b/libcxx/src/locale.cpp
@@ -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
diff --git a/libcxx/src/support/ibm/mbsnrtowcs.cpp b/libcxx/src/support/ibm/mbsnrtowcs.cpp
index 122dc5ed892f35..d0006a8468aad5 100644
--- a/libcxx/src/support/ibm/mbsnrtowcs.cpp
+++ b/libcxx/src/support/ibm/mbsnrtowcs.cpp
@@ -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);
@@ -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;
   }
diff --git a/libcxx/src/support/ibm/wcsnrtombs.cpp b/libcxx/src/support/ibm/wcsnrtombs.cpp
index f0372152339fc2..df87b9ea07f85f 100644
--- a/libcxx/src/support/ibm/wcsnrtombs.cpp
+++ b/libcxx/src/support/ibm/wcsnrtombs.cpp
@@ -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);
@@ -82,7 +82,7 @@ _LIBCPP_EXPORTED_FROM_ABI size_t wcsnrtombs(
 
     if (c == L'\0') {
       if (dst)
-        *src = NULL;
+        *src = nullptr;
       return dest_converted;
     }
   }
diff --git a/libcxx/src/support/ibm/xlocale_zos.cpp b/libcxx/src/support/ibm/xlocale_zos.cpp
index 9a90e08e11cf9c..136999ec0b02f8 100644
--- a/libcxx/src/support/ibm/xlocale_zos.cpp
+++ b/libcxx/src/support/ibm/xlocale_zos.cpp
@@ -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;
@@ -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());
diff --git a/libcxx/src/support/win32/support.cpp b/libcxx/src/support/win32/support.cpp
index fed51d8b0bede9..ccf5ff5acb4581 100644
--- a/libcxx/src/support/win32/support.cpp
+++ b/libcxx/src/support/win32/support.cpp
@@ -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)
@@ -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;
@@ -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;
   }
@@ -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.
@@ -161,7 +161,7 @@ size_t wcsnrtombs(char* __restrict dst,
   }
   if (dst) {
     if (terminator_found)
-      *src = NULL;
+      *src = nullptr;
     else
       *src = *src + source_converted;
   }
diff --git a/libcxx/src/support/win32/thread_win32.cpp b/libcxx/src/support/win32/thread_win32.cpp
index a2585c0b89f287..3a67d759f0f5e8 100644
--- a/libcxx/src/support/win32/thread_win32.cpp
+++ b/libcxx/src/support/win32/thread_win32.cpp
@@ -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;
 }

@ldionne ldionne merged commit d0438d2 into llvm:main Sep 17, 2024
64 checks passed
@ldionne ldionne deleted the review/replace-null-in-locale branch September 17, 2024 12:10
tmsri pushed a commit to tmsri/llvm-project that referenced this pull request Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[libc++] Two internal headers are still using NULL
3 participants