[libcxxabi] r296715 - Cleanup new/delete definitions

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 1 15:59:34 PST 2017


Author: ericwf
Date: Wed Mar  1 17:59:34 2017
New Revision: 296715

URL: http://llvm.org/viewvc/llvm-project?rev=296715&view=rev
Log:
Cleanup new/delete definitions

This patch cleans up how libc++abi handles the definitions for new/delete.
It is in preperation for upcoming changes to fix how both libc++ and libc++abi
handle new/delete.

The primary changes in this patch are:

* Move the definitions for bad_array_length and bad_new_array_length
  into stdlib_exception.cpp. This way stdlib_new_delete.cpp only
  contains new/delete.

* Rename cxa_new_delete.cpp -> stdlib_new_delete.cpp for consistency
  with other files.

* Add a FIXME regarding when stdlib_new_delete.cpp is actually compiled
  as part of the dylib.

Added:
    libcxxabi/trunk/src/stdlib_new_delete.cpp
      - copied, changed from r296612, libcxxabi/trunk/src/cxa_new_delete.cpp
Removed:
    libcxxabi/trunk/src/cxa_new_delete.cpp
Modified:
    libcxxabi/trunk/src/CMakeLists.txt
    libcxxabi/trunk/src/stdlib_exception.cpp

Modified: libcxxabi/trunk/src/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/CMakeLists.txt?rev=296715&r1=296714&r2=296715&view=diff
==============================================================================
--- libcxxabi/trunk/src/CMakeLists.txt (original)
+++ libcxxabi/trunk/src/CMakeLists.txt Wed Mar  1 17:59:34 2017
@@ -7,7 +7,6 @@ set(LIBCXXABI_SOURCES
   cxa_exception_storage.cpp
   cxa_guard.cpp
   cxa_handlers.cpp
-  cxa_new_delete.cpp
   cxa_unexpected.cpp
   cxa_vector.cpp
   cxa_virtual.cpp
@@ -21,6 +20,11 @@ set(LIBCXXABI_SOURCES
   private_typeinfo.cpp
 )
 
+# FIXME: This file should only be compiled in special configurations such
+#  as building the Apple system dylib where libc++abi is expected to provide
+#  the new/delete definitions instead of libc++.
+list(APPEND LIBCXXABI_SOURCES stdlib_new_delete.cpp)
+
 if (LIBCXXABI_ENABLE_EXCEPTIONS)
   list(APPEND LIBCXXABI_SOURCES cxa_exception.cpp)
   list(APPEND LIBCXXABI_SOURCES cxa_personality.cpp)

Removed: libcxxabi/trunk/src/cxa_new_delete.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_new_delete.cpp?rev=296714&view=auto
==============================================================================
--- libcxxabi/trunk/src/cxa_new_delete.cpp (original)
+++ libcxxabi/trunk/src/cxa_new_delete.cpp (removed)
@@ -1,244 +0,0 @@
-//===------------------------ cxa_new_delete.cpp --------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//
-// This file implements the new and delete operators.
-//===----------------------------------------------------------------------===//
-
-#define _LIBCPP_BUILDING_NEW
-
-#include "__cxxabi_config.h"
-#include <new>
-#include <cstdlib>
-
-#if !defined(_THROW_BAD_ALLOC) || !defined(_NOEXCEPT)
-#error _THROW_BAD_ALLOC and _NOEXCEPT libc++ macros must already be defined \
-       by libc++.
-#endif
-
-/*
-[new.delete.single]
-
-* Executes a loop: Within the loop, the function first attempts to allocate
-  the requested storage. Whether the attempt involves a call to the Standard C
-  library function malloc is unspecified.
-
-* Returns a pointer to the allocated storage if the attempt is successful.
-  Otherwise, if the current new_handler (18.6.2.5) is a null pointer value,
-  throws bad_alloc.
-
-* Otherwise, the function calls the current new_handler function (18.6.2.3).
-  If the called function returns, the loop repeats.
-
-* The loop terminates when an attempt to allocate the requested storage is
-  successful or when a called new_handler function does not return.
-*/
-_LIBCXXABI_WEAK
-void *
-operator new(std::size_t size) _THROW_BAD_ALLOC
-{
-    if (size == 0)
-        size = 1;
-    void* p;
-    while ((p = std::malloc(size)) == 0)
-    {
-        std::new_handler nh = std::get_new_handler();
-        if (nh)
-            nh();
-        else
-#ifndef _LIBCXXABI_NO_EXCEPTIONS
-            throw std::bad_alloc();
-#else
-            break;
-#endif
-    }
-    return p;
-}
-
-/*
-Note:  The relationships among these operators is both carefully considered
-and standard in C++11.  Please do not change them without fully understanding
-the consequences of doing so.  Reference:
-http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2158.html
-*/
-/*
-[new.delete.single]
-
-Calls operator new(size). If the call returns normally, returns the result of
-that call. Otherwise, returns a null pointer.
-*/
-_LIBCXXABI_WEAK
-void*
-operator new(size_t size, const std::nothrow_t&) _NOEXCEPT
-{
-    void* p = 0;
-#ifndef _LIBCXXABI_NO_EXCEPTIONS
-    try
-    {
-#endif
-        p = ::operator new(size);
-#ifndef _LIBCXXABI_NO_EXCEPTIONS
-    }
-    catch (...)
-    {
-    }
-#endif
-    return p;
-}
-
-/*
-[new.delete.array]
-
-Returns operator new(size).
-*/
-_LIBCXXABI_WEAK
-void*
-operator new[](size_t size) _THROW_BAD_ALLOC
-{
-    return ::operator new(size);
-}
-
-/*
-[new.delete.array]
-
-Calls operator new[](size). If the call returns normally, returns the result
-of that call. Otherwise, returns a null pointer.
-*/
-_LIBCXXABI_WEAK
-void*
-operator new[](size_t size, const std::nothrow_t&) _NOEXCEPT
-{
-    void* p = 0;
-#ifndef _LIBCXXABI_NO_EXCEPTIONS
-    try
-    {
-#endif
-        p = ::operator new[](size);
-#ifndef _LIBCXXABI_NO_EXCEPTIONS
-    }
-    catch (...)
-    {
-    }
-#endif
-    return p;
-}
-
-/*
-[new.delete.single]
-
-If ptr is null, does nothing. Otherwise, reclaims the storage allocated by the
-earlier call to operator new.
-*/
-_LIBCXXABI_WEAK
-void
-operator delete(void* ptr) _NOEXCEPT
-{
-    if (ptr)
-        std::free(ptr);
-}
-
-/*
-[new.delete.single]
-
-calls operator delete(ptr)
-*/
-_LIBCXXABI_WEAK
-void
-operator delete(void* ptr, const std::nothrow_t&) _NOEXCEPT
-{
-    ::operator delete(ptr);
-}
-
-/*
-[new.delete.array]
-
-Calls operator delete(ptr)
-*/
-_LIBCXXABI_WEAK
-void
-operator delete[] (void* ptr) _NOEXCEPT
-{
-    ::operator delete(ptr);
-}
-
-/*
-[new.delete.array]
-
-calls operator delete[](ptr)
-*/
-_LIBCXXABI_WEAK
-void
-operator delete[] (void* ptr, const std::nothrow_t&) _NOEXCEPT
-{
-    ::operator delete[](ptr);
-}
-
-namespace std
-{
-
-//  bad_alloc
-
-bad_alloc::bad_alloc() _NOEXCEPT
-{
-}
-
-bad_alloc::~bad_alloc() _NOEXCEPT
-{
-}
-
-const char*
-bad_alloc::what() const _NOEXCEPT
-{
-    return "std::bad_alloc";
-}
-
-// bad_array_new_length
-
-bad_array_new_length::bad_array_new_length() _NOEXCEPT
-{
-}
-
-bad_array_new_length::~bad_array_new_length() _NOEXCEPT
-{
-}
-
-const char*
-bad_array_new_length::what() const _NOEXCEPT
-{
-    return "bad_array_new_length";
-}
-
-// bad_array_length
-
-#ifndef _LIBCPP_BAD_ARRAY_LENGTH_DEFINED
-
-class _LIBCPP_EXCEPTION_ABI bad_array_length
-    : public bad_alloc
-{
-public:
-    bad_array_length() _NOEXCEPT;
-    virtual ~bad_array_length() _NOEXCEPT;
-    virtual const char* what() const _NOEXCEPT;
-};
-
-#endif  // _LIBCPP_BAD_ARRAY_LENGTH_DEFINED
-
-bad_array_length::bad_array_length() _NOEXCEPT
-{
-}
-
-bad_array_length::~bad_array_length() _NOEXCEPT
-{
-}
-
-const char*
-bad_array_length::what() const _NOEXCEPT
-{
-    return "bad_array_length";
-}
-
-}  // std

Modified: libcxxabi/trunk/src/stdlib_exception.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/stdlib_exception.cpp?rev=296715&r1=296714&r2=296715&view=diff
==============================================================================
--- libcxxabi/trunk/src/stdlib_exception.cpp (original)
+++ libcxxabi/trunk/src/stdlib_exception.cpp Wed Mar  1 17:59:34 2017
@@ -7,6 +7,9 @@
 //
 //===----------------------------------------------------------------------===//
 
+#define _LIBCPP_BUILDING_LIBRARY
+#define _LIBCPP_BUILDING_NEW
+#include <new>
 #include <exception>
 
 namespace std
@@ -34,4 +37,67 @@ const char* bad_exception::what() const
   return "std::bad_exception";
 }
 
+
+//  bad_alloc
+
+bad_alloc::bad_alloc() _NOEXCEPT
+{
+}
+
+bad_alloc::~bad_alloc() _NOEXCEPT
+{
+}
+
+const char*
+bad_alloc::what() const _NOEXCEPT
+{
+    return "std::bad_alloc";
+}
+
+// bad_array_new_length
+
+bad_array_new_length::bad_array_new_length() _NOEXCEPT
+{
+}
+
+bad_array_new_length::~bad_array_new_length() _NOEXCEPT
+{
+}
+
+const char*
+bad_array_new_length::what() const _NOEXCEPT
+{
+    return "bad_array_new_length";
+}
+
+// bad_array_length
+
+#ifndef _LIBCPP_BAD_ARRAY_LENGTH_DEFINED
+
+class _LIBCPP_EXCEPTION_ABI bad_array_length
+    : public bad_alloc
+{
+public:
+    bad_array_length() _NOEXCEPT;
+    virtual ~bad_array_length() _NOEXCEPT;
+    virtual const char* what() const _NOEXCEPT;
+};
+
+#endif  // _LIBCPP_BAD_ARRAY_LENGTH_DEFINED
+
+bad_array_length::bad_array_length() _NOEXCEPT
+{
+}
+
+bad_array_length::~bad_array_length() _NOEXCEPT
+{
+}
+
+const char*
+bad_array_length::what() const _NOEXCEPT
+{
+    return "bad_array_length";
+}
+
+
 }  // std

Copied: libcxxabi/trunk/src/stdlib_new_delete.cpp (from r296612, libcxxabi/trunk/src/cxa_new_delete.cpp)
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/stdlib_new_delete.cpp?p2=libcxxabi/trunk/src/stdlib_new_delete.cpp&p1=libcxxabi/trunk/src/cxa_new_delete.cpp&r1=296612&r2=296715&rev=296715&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_new_delete.cpp (original)
+++ libcxxabi/trunk/src/stdlib_new_delete.cpp Wed Mar  1 17:59:34 2017
@@ -176,69 +176,3 @@ operator delete[] (void* ptr, const std:
 {
     ::operator delete[](ptr);
 }
-
-namespace std
-{
-
-//  bad_alloc
-
-bad_alloc::bad_alloc() _NOEXCEPT
-{
-}
-
-bad_alloc::~bad_alloc() _NOEXCEPT
-{
-}
-
-const char*
-bad_alloc::what() const _NOEXCEPT
-{
-    return "std::bad_alloc";
-}
-
-// bad_array_new_length
-
-bad_array_new_length::bad_array_new_length() _NOEXCEPT
-{
-}
-
-bad_array_new_length::~bad_array_new_length() _NOEXCEPT
-{
-}
-
-const char*
-bad_array_new_length::what() const _NOEXCEPT
-{
-    return "bad_array_new_length";
-}
-
-// bad_array_length
-
-#ifndef _LIBCPP_BAD_ARRAY_LENGTH_DEFINED
-
-class _LIBCPP_EXCEPTION_ABI bad_array_length
-    : public bad_alloc
-{
-public:
-    bad_array_length() _NOEXCEPT;
-    virtual ~bad_array_length() _NOEXCEPT;
-    virtual const char* what() const _NOEXCEPT;
-};
-
-#endif  // _LIBCPP_BAD_ARRAY_LENGTH_DEFINED
-
-bad_array_length::bad_array_length() _NOEXCEPT
-{
-}
-
-bad_array_length::~bad_array_length() _NOEXCEPT
-{
-}
-
-const char*
-bad_array_length::what() const _NOEXCEPT
-{
-    return "bad_array_length";
-}
-
-}  // std




More information about the cfe-commits mailing list