From 95a3d335642f902b04e224d53fdcd2ca44b72714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20M=C3=BChleisen?= Date: Mon, 3 Jun 2024 09:44:50 +0200 Subject: [PATCH] remove old files --- .../duckdb/common/enable_shared_from_this.ipp | 42 --- .../src/include/duckdb/common/shared_ptr.ipp | 268 ------------------ .../src/include/duckdb/common/weak_ptr.ipp | 117 -------- 3 files changed, 427 deletions(-) delete mode 100644 src/duckdb/src/include/duckdb/common/enable_shared_from_this.ipp delete mode 100644 src/duckdb/src/include/duckdb/common/shared_ptr.ipp delete mode 100644 src/duckdb/src/include/duckdb/common/weak_ptr.ipp diff --git a/src/duckdb/src/include/duckdb/common/enable_shared_from_this.ipp b/src/duckdb/src/include/duckdb/common/enable_shared_from_this.ipp deleted file mode 100644 index 85cdd220..00000000 --- a/src/duckdb/src/include/duckdb/common/enable_shared_from_this.ipp +++ /dev/null @@ -1,42 +0,0 @@ -namespace duckdb { - -template -class enable_shared_from_this { // NOLINT: invalid case style -public: - template - friend class shared_ptr; - -private: - mutable weak_ptr __weak_this_; // NOLINT: __weak_this_ is reserved - -protected: - constexpr enable_shared_from_this() noexcept { - } - enable_shared_from_this(enable_shared_from_this const &) noexcept { // NOLINT: not marked as explicit - } - enable_shared_from_this &operator=(enable_shared_from_this const &) noexcept { - return *this; - } - ~enable_shared_from_this() { - } - -public: - shared_ptr shared_from_this() { // NOLINT: invalid case style - return shared_ptr(__weak_this_); - } - shared_ptr shared_from_this() const { // NOLINT: invalid case style - return shared_ptr(__weak_this_); - } - -#if _LIBCPP_STD_VER >= 17 - weak_ptr weak_from_this() noexcept { // NOLINT: invalid case style - return __weak_this_; - } - - weak_ptr weak_from_this() const noexcept { // NOLINT: invalid case style - return __weak_this_; - } -#endif // _LIBCPP_STD_VER >= 17 -}; - -} // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/common/shared_ptr.ipp b/src/duckdb/src/include/duckdb/common/shared_ptr.ipp deleted file mode 100644 index d046dc14..00000000 --- a/src/duckdb/src/include/duckdb/common/shared_ptr.ipp +++ /dev/null @@ -1,268 +0,0 @@ -namespace duckdb { - -template -class weak_ptr; - -template -class enable_shared_from_this; - -template -class shared_ptr { // NOLINT: invalid case style -public: - using original = std::shared_ptr; - using element_type = typename original::element_type; - using weak_type = weak_ptr; - -private: - static inline void AssertNotNull(const bool null) { -#if defined(DUCKDB_DEBUG_NO_SAFETY) || defined(DUCKDB_CLANG_TIDY) - return; -#else - if (DUCKDB_UNLIKELY(null)) { - throw duckdb::InternalException("Attempted to dereference shared_ptr that is NULL!"); - } -#endif - } - -private: - template - friend class weak_ptr; - - template - friend class shared_ptr; - - template - friend shared_ptr shared_ptr_cast(shared_ptr src); // NOLINT: invalid case style - -private: - original internal; - -public: - // Constructors - shared_ptr() : internal() { - } - shared_ptr(std::nullptr_t) : internal(nullptr) { // NOLINT: not marked as explicit - } - - // From raw pointer of type U convertible to T - template ::value, int>::type = 0> - explicit shared_ptr(U *ptr) : internal(ptr) { - __enable_weak_this(internal.get(), internal.get()); - } - // From raw pointer of type T with custom DELETER - template - shared_ptr(T *ptr, DELETER deleter) : internal(ptr, deleter) { - __enable_weak_this(internal.get(), internal.get()); - } - // Aliasing constructor: shares ownership information with ref but contains ptr instead - // When the created shared_ptr goes out of scope, it will call the DELETER of ref, will not delete ptr - template - shared_ptr(const shared_ptr &ref, T *ptr) noexcept : internal(ref.internal, ptr) { - } -#if _LIBCPP_STD_VER >= 20 - template - shared_ptr(shared_ptr &&ref, T *ptr) noexcept : internal(std::move(ref.internal), ptr) { - } -#endif - - // Copy constructor, share ownership with ref - template ::value, int>::type = 0> - shared_ptr(const shared_ptr &ref) noexcept : internal(ref.internal) { // NOLINT: not marked as explicit - } - shared_ptr(const shared_ptr &other) : internal(other.internal) { // NOLINT: not marked as explicit - } - // Move constructor, share ownership with ref - template ::value, int>::type = 0> -#ifdef DUCKDB_CLANG_TIDY - [[clang::reinitializes]] -#endif - shared_ptr(shared_ptr &&ref) noexcept // NOLINT: not marked as explicit - : internal(std::move(ref.internal)) { - } -#ifdef DUCKDB_CLANG_TIDY - [[clang::reinitializes]] -#endif - shared_ptr(shared_ptr &&other) // NOLINT: not marked as explicit - : internal(std::move(other.internal)) { - } - - // Construct from std::shared_ptr - explicit shared_ptr(std::shared_ptr other) : internal(other) { - // FIXME: should we __enable_weak_this here? - // *our* enable_shared_from_this hasn't initialized yet, so I think so? - __enable_weak_this(internal.get(), internal.get()); - } - - // Construct from weak_ptr - template - explicit shared_ptr(weak_ptr other) : internal(other.internal) { - } - - // Construct from unique_ptr, takes over ownership of the unique_ptr - template ::value && - std::is_convertible::pointer, T *>::value, - int>::type = 0> -#ifdef DUCKDB_CLANG_TIDY - [[clang::reinitializes]] -#endif - shared_ptr(unique_ptr &&other) // NOLINT: not marked as explicit - : internal(std::move(other)) { - __enable_weak_this(internal.get(), internal.get()); - } - - // Destructor - ~shared_ptr() = default; - - // Assign from shared_ptr copy - shared_ptr &operator=(const shared_ptr &other) noexcept { - if (this == &other) { - return *this; - } - // Create a new shared_ptr using the copy constructor, then swap out the ownership to *this - shared_ptr(other).swap(*this); - return *this; - } - template ::value, int>::type = 0> - shared_ptr &operator=(const shared_ptr &other) { - shared_ptr(other).swap(*this); - return *this; - } - - // Assign from moved shared_ptr - shared_ptr &operator=(shared_ptr &&other) noexcept { - // Create a new shared_ptr using the move constructor, then swap out the ownership to *this - shared_ptr(std::move(other)).swap(*this); - return *this; - } - template ::value, int>::type = 0> - shared_ptr &operator=(shared_ptr &&other) { - shared_ptr(std::move(other)).swap(*this); - return *this; - } - - // Assign from moved unique_ptr - template ::value && - std::is_convertible::pointer, T *>::value, - int>::type = 0> - shared_ptr &operator=(unique_ptr &&ref) { - shared_ptr(std::move(ref)).swap(*this); - return *this; - } - -#ifdef DUCKDB_CLANG_TIDY - [[clang::reinitializes]] -#endif - void - reset() { // NOLINT: invalid case style - internal.reset(); - } - template -#ifdef DUCKDB_CLANG_TIDY - [[clang::reinitializes]] -#endif - void - reset(U *ptr) { // NOLINT: invalid case style - internal.reset(ptr); - } - template -#ifdef DUCKDB_CLANG_TIDY - [[clang::reinitializes]] -#endif - void - reset(U *ptr, DELETER deleter) { // NOLINT: invalid case style - internal.reset(ptr, deleter); - } - - void swap(shared_ptr &r) noexcept { // NOLINT: invalid case style - internal.swap(r.internal); - } - - T *get() const { // NOLINT: invalid case style - return internal.get(); - } - - long use_count() const { // NOLINT: invalid case style - return internal.use_count(); - } - - explicit operator bool() const noexcept { - return internal.operator bool(); - } - - typename std::add_lvalue_reference::type operator*() const { - if (MemorySafety::ENABLED) { - const auto ptr = internal.get(); - AssertNotNull(!ptr); - return *ptr; - } else { - return *internal; - } - } - - T *operator->() const { - if (MemorySafety::ENABLED) { - const auto ptr = internal.get(); - AssertNotNull(!ptr); - return ptr; - } else { - return internal.operator->(); - } - } - - // Relational operators - template - bool operator==(const shared_ptr &other) const noexcept { - return internal == other.internal; - } - template - bool operator!=(const shared_ptr &other) const noexcept { - return internal != other.internal; - } - - bool operator==(std::nullptr_t) const noexcept { - return internal == nullptr; - } - bool operator!=(std::nullptr_t) const noexcept { - return internal != nullptr; - } - - template - bool operator<(const shared_ptr &other) const noexcept { - return internal < other.internal; - } - template - bool operator<=(const shared_ptr &other) const noexcept { - return internal <= other.internal; - } - template - bool operator>(const shared_ptr &other) const noexcept { - return internal > other.internal; - } - template - bool operator>=(const shared_ptr &other) const noexcept { - return internal >= other.internal; - } - -private: - // This overload is used when the class inherits from 'enable_shared_from_this' - template *>::value, - int>::type = 0> - void __enable_weak_this(const enable_shared_from_this *object, // NOLINT: invalid case style - V *ptr) noexcept { - typedef typename std::remove_cv::type non_const_u_t; - if (object && object->__weak_this_.expired()) { - // __weak_this__ is the mutable variable returned by 'shared_from_this' - // it is initialized here - auto non_const = const_cast(static_cast(ptr)); // NOLINT: const cast - object->__weak_this_ = shared_ptr(*this, non_const); - } - } - - void __enable_weak_this(...) noexcept { // NOLINT: invalid case style - } -}; - -} // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/common/weak_ptr.ipp b/src/duckdb/src/include/duckdb/common/weak_ptr.ipp deleted file mode 100644 index 076fde95..00000000 --- a/src/duckdb/src/include/duckdb/common/weak_ptr.ipp +++ /dev/null @@ -1,117 +0,0 @@ -namespace duckdb { - -template -class weak_ptr { // NOLINT: invalid case style -public: - using original = std::weak_ptr; - using element_type = typename original::element_type; - -private: - template - friend class shared_ptr; - -private: - original internal; - -public: - // Constructors - weak_ptr() : internal() { - } - - // NOLINTBEGIN - template ::value, int>::type = 0> - weak_ptr(shared_ptr const &ptr) noexcept : internal(ptr.internal) { - } - weak_ptr(weak_ptr const &other) noexcept : internal(other.internal) { - } - template ::value, int>::type = 0> - weak_ptr(weak_ptr const &ptr) noexcept : internal(ptr.internal) { - } -#ifdef DUCKDB_CLANG_TIDY - [[clang::reinitializes]] -#endif - weak_ptr(weak_ptr &&ptr) noexcept - : internal(std::move(ptr.internal)) { - } - template ::value, int>::type = 0> -#ifdef DUCKDB_CLANG_TIDY - [[clang::reinitializes]] -#endif - weak_ptr(weak_ptr &&ptr) noexcept - : internal(std::move(ptr.internal)) { - } - // NOLINTEND - // Destructor - ~weak_ptr() = default; - - // Assignment operators - weak_ptr &operator=(const weak_ptr &other) { - if (this == &other) { - return *this; - } - internal = other.internal; - return *this; - } - - template ::value, int>::type = 0> - weak_ptr &operator=(const shared_ptr &ptr) { - internal = ptr.internal; - return *this; - } - - // Modifiers -#ifdef DUCKDB_CLANG_TIDY - // This is necessary to tell clang-tidy that it reinitializes the variable after a move - [[clang::reinitializes]] -#endif - void - reset() { // NOLINT: invalid case style - internal.reset(); - } - - // Observers - long use_count() const { // NOLINT: invalid case style - return internal.use_count(); - } - - bool expired() const { // NOLINT: invalid case style - return internal.expired(); - } - - shared_ptr lock() const { // NOLINT: invalid case style - return shared_ptr(internal.lock()); - } - - // Relational operators - template - bool operator==(const weak_ptr &other) const noexcept { - return internal == other.internal; - } - - template - bool operator!=(const weak_ptr &other) const noexcept { - return internal != other.internal; - } - - template - bool operator<(const weak_ptr &other) const noexcept { - return internal < other.internal; - } - - template - bool operator<=(const weak_ptr &other) const noexcept { - return internal <= other.internal; - } - - template - bool operator>(const weak_ptr &other) const noexcept { - return internal > other.internal; - } - - template - bool operator>=(const weak_ptr &other) const noexcept { - return internal >= other.internal; - } -}; - -} // namespace duckdb