[libcxx-commits] [libcxxabi] r373381 - [libc++abi] Remove uses of C++ headers when possible

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 1 11:43:02 PDT 2019


Author: ldionne
Date: Tue Oct  1 11:43:02 2019
New Revision: 373381

URL: http://llvm.org/viewvc/llvm-project?rev=373381&view=rev
Log:
[libc++abi] Remove uses of C++ headers when possible

This reduces the (circular) dependency of libc++abi on a C++ standard
library. Outside of the demangler which uses fancier C++ features, the
only C++ headers now required by libc++abi are pretty much <new> and
<exception>, and that's because libc++abi defines some types that are
declared in those headers.

Modified:
    libcxxabi/trunk/src/cxa_default_handlers.cpp
    libcxxabi/trunk/src/cxa_exception.cpp
    libcxxabi/trunk/src/cxa_thread_atexit.cpp
    libcxxabi/trunk/src/cxa_vector.cpp
    libcxxabi/trunk/src/fallback_malloc.cpp
    libcxxabi/trunk/src/fallback_malloc.h
    libcxxabi/trunk/src/private_typeinfo.h

Modified: libcxxabi/trunk/src/cxa_default_handlers.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_default_handlers.cpp?rev=373381&r1=373380&r2=373381&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_default_handlers.cpp (original)
+++ libcxxabi/trunk/src/cxa_default_handlers.cpp Tue Oct  1 11:43:02 2019
@@ -8,10 +8,8 @@
 // This file implements the default terminate_handler and unexpected_handler.
 //===----------------------------------------------------------------------===//
 
-#include <stdexcept>
-#include <new>
 #include <exception>
-#include <cstdlib>
+#include <stdlib.h>
 #include "abort_message.h"
 #include "cxxabi.h"
 #include "cxa_handlers.h"
@@ -87,7 +85,7 @@ static void demangling_unexpected_handle
 static std::terminate_handler default_terminate_handler = demangling_terminate_handler;
 static std::terminate_handler default_unexpected_handler = demangling_unexpected_handler;
 #else
-static std::terminate_handler default_terminate_handler = std::abort;
+static std::terminate_handler default_terminate_handler = ::abort;
 static std::terminate_handler default_unexpected_handler = std::terminate;
 #endif
 

Modified: libcxxabi/trunk/src/cxa_exception.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception.cpp?rev=373381&r1=373380&r2=373381&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_exception.cpp (original)
+++ libcxxabi/trunk/src/cxa_exception.cpp Tue Oct  1 11:43:02 2019
@@ -13,7 +13,7 @@
 #include "cxxabi.h"
 
 #include <exception>        // for std::terminate
-#include <cstring>          // for memset
+#include <string.h>         // for memset
 #include "cxa_exception.h"
 #include "cxa_handlers.h"
 #include "fallback_malloc.h"
@@ -163,13 +163,12 @@ static size_t get_cxa_exception_offset()
   } __attribute__((aligned));
 
   // Compute the maximum alignment for the target machine.
-  constexpr size_t alignment = std::alignment_of<S>::value;
+  constexpr size_t alignment = alignof(S);
   constexpr size_t excp_size = sizeof(__cxa_exception);
   constexpr size_t aligned_size =
       (excp_size + alignment - 1) / alignment * alignment;
   constexpr size_t offset = aligned_size - excp_size;
-  static_assert((offset == 0 ||
-                 std::alignment_of<_Unwind_Exception>::value < alignment),
+  static_assert((offset == 0 || alignof(_Unwind_Exception) < alignment),
                 "offset is non-zero only if _Unwind_Exception isn't aligned");
   return offset;
 }
@@ -193,7 +192,7 @@ void *__cxa_allocate_exception(size_t th
         std::terminate();
     __cxa_exception *exception_header =
         static_cast<__cxa_exception *>((void *)(raw_buffer + header_offset));
-    std::memset(exception_header, 0, actual_size);
+    ::memset(exception_header, 0, actual_size);
     return thrown_object_from_cxa_exception(exception_header);
 }
 
@@ -216,7 +215,7 @@ void * __cxa_allocate_dependent_exceptio
     void *ptr = __aligned_malloc_with_fallback(actual_size);
     if (NULL == ptr)
         std::terminate();
-    std::memset(ptr, 0, actual_size);
+    ::memset(ptr, 0, actual_size);
     return ptr;
 }
 

Modified: libcxxabi/trunk/src/cxa_thread_atexit.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_thread_atexit.cpp?rev=373381&r1=373380&r2=373381&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_thread_atexit.cpp (original)
+++ libcxxabi/trunk/src/cxa_thread_atexit.cpp Tue Oct  1 11:43:02 2019
@@ -15,7 +15,7 @@
 #endif
 #endif
 
-#include <cstdlib>
+#include <stdlib.h>
 
 namespace __cxxabiv1 {
 
@@ -77,7 +77,7 @@ namespace {
     while (auto head = dtors) {
       dtors = head->next;
       head->dtor(head->obj);
-      std::free(head);
+      ::free(head);
     }
 
     dtors_alive = false;
@@ -126,7 +126,7 @@ extern "C" {
         dtors_alive = true;
       }
 
-      auto head = static_cast<DtorList*>(std::malloc(sizeof(DtorList)));
+      auto head = static_cast<DtorList*>(::malloc(sizeof(DtorList)));
       if (!head) {
         return -1;
       }

Modified: libcxxabi/trunk/src/cxa_vector.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_vector.cpp?rev=373381&r1=373380&r2=373381&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_vector.cpp (original)
+++ libcxxabi/trunk/src/cxa_vector.cpp Tue Oct  1 11:43:02 2019
@@ -14,7 +14,7 @@
 #include "__cxxabi_config.h"
 
 #include <exception>        // for std::terminate
-#include <new>              // for std::bad_alloc
+#include <new>              // for std::bad_array_new_length
 
 #include "abort_message.h"
 

Modified: libcxxabi/trunk/src/fallback_malloc.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/fallback_malloc.cpp?rev=373381&r1=373380&r2=373381&view=diff
==============================================================================
--- libcxxabi/trunk/src/fallback_malloc.cpp (original)
+++ libcxxabi/trunk/src/fallback_malloc.cpp Tue Oct  1 11:43:02 2019
@@ -18,8 +18,8 @@
 #endif
 #endif
 
-#include <cstdlib> // for malloc, calloc, free
-#include <cstring> // for memset
+#include <stdlib.h> // for malloc, calloc, free
+#include <string.h> // for memset
 
 //  A small, simple heap manager based (loosely) on
 //  the startup heap manager from FreeBSD, optimized for space.
@@ -214,7 +214,7 @@ void* __aligned_malloc_with_fallback(siz
   if (void* dest = _aligned_malloc(size, alignof(__aligned_type)))
     return dest;
 #elif defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION)
-  if (void* dest = std::malloc(size))
+  if (void* dest = ::malloc(size))
     return dest;
 #else
   if (size == 0)
@@ -227,13 +227,13 @@ void* __aligned_malloc_with_fallback(siz
 }
 
 void* __calloc_with_fallback(size_t count, size_t size) {
-  void* ptr = std::calloc(count, size);
+  void* ptr = ::calloc(count, size);
   if (NULL != ptr)
     return ptr;
   // if calloc fails, fall back to emergency stash
   ptr = fallback_malloc(size * count);
   if (NULL != ptr)
-    std::memset(ptr, 0, size * count);
+    ::memset(ptr, 0, size * count);
   return ptr;
 }
 
@@ -244,7 +244,7 @@ void __aligned_free_with_fallback(void*
 #if defined(_WIN32)
     ::_aligned_free(ptr);
 #else
-    std::free(ptr);
+    ::free(ptr);
 #endif
   }
 }
@@ -253,7 +253,7 @@ void __free_with_fallback(void* ptr) {
   if (is_fallback_ptr(ptr))
     fallback_free(ptr);
   else
-    std::free(ptr);
+    ::free(ptr);
 }
 
 } // namespace __cxxabiv1

Modified: libcxxabi/trunk/src/fallback_malloc.h
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/fallback_malloc.h?rev=373381&r1=373380&r2=373381&view=diff
==============================================================================
--- libcxxabi/trunk/src/fallback_malloc.h (original)
+++ libcxxabi/trunk/src/fallback_malloc.h Tue Oct  1 11:43:02 2019
@@ -10,7 +10,7 @@
 #define _FALLBACK_MALLOC_H
 
 #include "__cxxabi_config.h"
-#include <cstddef> // for size_t
+#include <stddef.h> // for size_t
 
 namespace __cxxabiv1 {
 

Modified: libcxxabi/trunk/src/private_typeinfo.h
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/private_typeinfo.h?rev=373381&r1=373380&r2=373381&view=diff
==============================================================================
--- libcxxabi/trunk/src/private_typeinfo.h (original)
+++ libcxxabi/trunk/src/private_typeinfo.h Tue Oct  1 11:43:02 2019
@@ -12,7 +12,7 @@
 #include "__cxxabi_config.h"
 
 #include <typeinfo>
-#include <cstddef>
+#include <stddef.h>
 
 namespace __cxxabiv1 {
 
@@ -72,7 +72,7 @@ struct _LIBCXXABI_HIDDEN __dynamic_cast_
     const __class_type_info* dst_type;
     const void* static_ptr;
     const __class_type_info* static_type;
-    std::ptrdiff_t src2dst_offset;
+    ptrdiff_t src2dst_offset;
 
 // Data that represents the answer:
 




More information about the libcxx-commits mailing list