[libcxx-commits] [libcxx] 7f1963d - [libc++] Move pointer safety related utilities out of <memory>

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Apr 13 05:22:39 PDT 2021


Author: Louis Dionne
Date: 2021-04-13T08:21:46-04:00
New Revision: 7f1963dc8e233fb28332b0e797372e63d5a9598e

URL: https://github.com/llvm/llvm-project/commit/7f1963dc8e233fb28332b0e797372e63d5a9598e
DIFF: https://github.com/llvm/llvm-project/commit/7f1963dc8e233fb28332b0e797372e63d5a9598e.diff

LOG: [libc++] Move pointer safety related utilities out of <memory>

Differential Revision: https://reviews.llvm.org/D100318

Added: 
    libcxx/include/__memory/pointer_safety.h

Modified: 
    libcxx/include/CMakeLists.txt
    libcxx/include/memory

Removed: 
    


################################################################################
diff  --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 8b8b2141c03c9..f31540119de94 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -18,6 +18,7 @@ set(files
   __memory/auto_ptr.h
   __memory/base.h
   __memory/compressed_pair.h
+  __memory/pointer_safety.h
   __memory/pointer_traits.h
   __memory/raw_storage_iterator.h
   __memory/shared_ptr.h

diff  --git a/libcxx/include/__memory/pointer_safety.h b/libcxx/include/__memory/pointer_safety.h
new file mode 100644
index 0000000000000..5937e7c59edc0
--- /dev/null
+++ b/libcxx/include/__memory/pointer_safety.h
@@ -0,0 +1,86 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___MEMORY_POINTER_SAFETY_H
+#define _LIBCPP___MEMORY_POINTER_SAFETY_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+//enum class
+#if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE)
+# ifndef _LIBCPP_CXX03_LANG
+enum class pointer_safety : unsigned char {
+  relaxed,
+  preferred,
+  strict
+};
+# endif
+#else
+struct _LIBCPP_TYPE_VIS pointer_safety
+{
+    enum __lx
+    {
+        relaxed,
+        preferred,
+        strict
+    };
+
+    __lx __v_;
+
+    _LIBCPP_INLINE_VISIBILITY
+    pointer_safety() : __v_() {}
+
+    _LIBCPP_INLINE_VISIBILITY
+    pointer_safety(__lx __v) : __v_(__v) {}
+    _LIBCPP_INLINE_VISIBILITY
+    operator int() const {return __v_;}
+};
+#endif
+
+#if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \
+    defined(_LIBCPP_BUILDING_LIBRARY)
+_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
+#else
+// This function is only offered in C++03 under ABI v1.
+# if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG)
+inline _LIBCPP_INLINE_VISIBILITY
+pointer_safety get_pointer_safety() _NOEXCEPT {
+  return pointer_safety::relaxed;
+}
+# endif
+#endif
+
+
+_LIBCPP_FUNC_VIS void declare_reachable(void* __p);
+_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
+_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
+_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp*
+undeclare_reachable(_Tp* __p)
+{
+    return static_cast<_Tp*>(__undeclare_reachable(__p));
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif  // _LIBCPP___MEMORY_POINTER_SAFETY_H

diff  --git a/libcxx/include/memory b/libcxx/include/memory
index f2af0339f9451..ad977334a78fa 100644
--- a/libcxx/include/memory
+++ b/libcxx/include/memory
@@ -683,6 +683,7 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
 #include <__memory/auto_ptr.h>
 #include <__memory/base.h>
 #include <__memory/compressed_pair.h>
+#include <__memory/pointer_safety.h>
 #include <__memory/pointer_traits.h>
 #include <__memory/raw_storage_iterator.h>
 #include <__memory/shared_ptr.h>
@@ -828,64 +829,6 @@ public:
         {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
 };
 
-//enum class
-#if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE)
-# ifndef _LIBCPP_CXX03_LANG
-enum class pointer_safety : unsigned char {
-  relaxed,
-  preferred,
-  strict
-};
-# endif
-#else
-struct _LIBCPP_TYPE_VIS pointer_safety
-{
-    enum __lx
-    {
-        relaxed,
-        preferred,
-        strict
-    };
-
-    __lx __v_;
-
-    _LIBCPP_INLINE_VISIBILITY
-    pointer_safety() : __v_() {}
-
-    _LIBCPP_INLINE_VISIBILITY
-    pointer_safety(__lx __v) : __v_(__v) {}
-    _LIBCPP_INLINE_VISIBILITY
-    operator int() const {return __v_;}
-};
-#endif
-
-#if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \
-    defined(_LIBCPP_BUILDING_LIBRARY)
-_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
-#else
-// This function is only offered in C++03 under ABI v1.
-# if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG)
-inline _LIBCPP_INLINE_VISIBILITY
-pointer_safety get_pointer_safety() _NOEXCEPT {
-  return pointer_safety::relaxed;
-}
-# endif
-#endif
-
-
-_LIBCPP_FUNC_VIS void declare_reachable(void* __p);
-_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
-_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
-_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
-
-template <class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
-_Tp*
-undeclare_reachable(_Tp* __p)
-{
-    return static_cast<_Tp*>(__undeclare_reachable(__p));
-}
-
 _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
 
 // --- Helper for container swap --


        


More information about the libcxx-commits mailing list