diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-08-21 23:20:49 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-08-21 23:20:49 +0200 |
commit | 424ff096f72df81fa193db922153ccf28a763bf5 (patch) | |
tree | 39911d397c65cd58127ce1ae42b415eeb5e880fa /vespalib | |
parent | 9a64ce6b1b973bed38d304b2be8330e27b849dee (diff) |
Drop the dangerous LinkedPtr.
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | vespalib/src/testlist.txt | 1 | ||||
-rw-r--r-- | vespalib/src/tests/linkedptr/.gitignore | 4 | ||||
-rw-r--r-- | vespalib/src/tests/linkedptr/CMakeLists.txt | 8 | ||||
-rw-r--r-- | vespalib/src/tests/linkedptr/DESC | 1 | ||||
-rw-r--r-- | vespalib/src/tests/linkedptr/FILES | 1 | ||||
-rw-r--r-- | vespalib/src/tests/linkedptr/linkedptr_test.cpp | 231 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/linkedptr.h | 181 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/overview.h | 4 |
9 files changed, 0 insertions, 432 deletions
diff --git a/vespalib/CMakeLists.txt b/vespalib/CMakeLists.txt index cab5ce0ff4a..112f67f3a70 100644 --- a/vespalib/CMakeLists.txt +++ b/vespalib/CMakeLists.txt @@ -43,7 +43,6 @@ vespa_define_module( src/tests/io/fileutil src/tests/io/mapped_file_input src/tests/left_right_heap - src/tests/linkedptr src/tests/make_fixture_macros src/tests/memory src/tests/net/async_resolver diff --git a/vespalib/src/testlist.txt b/vespalib/src/testlist.txt index 68a1136e025..d21a06654c8 100644 --- a/vespalib/src/testlist.txt +++ b/vespalib/src/testlist.txt @@ -35,7 +35,6 @@ tests/hashmap tests/host_name tests/io/fileutil tests/left_right_heap -tests/linkedptr tests/make_fixture_macros tests/memory tests/net/socket diff --git a/vespalib/src/tests/linkedptr/.gitignore b/vespalib/src/tests/linkedptr/.gitignore deleted file mode 100644 index ca9a6b595b2..00000000000 --- a/vespalib/src/tests/linkedptr/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.depend -Makefile -linkedptr_test -vespalib_linkedptr_test_app diff --git a/vespalib/src/tests/linkedptr/CMakeLists.txt b/vespalib/src/tests/linkedptr/CMakeLists.txt deleted file mode 100644 index be3354f1af4..00000000000 --- a/vespalib/src/tests/linkedptr/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(vespalib_linkedptr_test_app TEST - SOURCES - linkedptr_test.cpp - DEPENDS - vespalib -) -vespa_add_test(NAME vespalib_linkedptr_test_app COMMAND vespalib_linkedptr_test_app) diff --git a/vespalib/src/tests/linkedptr/DESC b/vespalib/src/tests/linkedptr/DESC deleted file mode 100644 index fed98e9b552..00000000000 --- a/vespalib/src/tests/linkedptr/DESC +++ /dev/null @@ -1 +0,0 @@ -Unit test for the LinkedPtr class. diff --git a/vespalib/src/tests/linkedptr/FILES b/vespalib/src/tests/linkedptr/FILES deleted file mode 100644 index 0a10d16f5bc..00000000000 --- a/vespalib/src/tests/linkedptr/FILES +++ /dev/null @@ -1 +0,0 @@ -linkedptr.cpp diff --git a/vespalib/src/tests/linkedptr/linkedptr_test.cpp b/vespalib/src/tests/linkedptr/linkedptr_test.cpp deleted file mode 100644 index 173507c7e18..00000000000 --- a/vespalib/src/tests/linkedptr/linkedptr_test.cpp +++ /dev/null @@ -1,231 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include <vespa/vespalib/util/linkedptr.h> -#include <vespa/vespalib/testkit/testapp.h> - -using vespalib::LinkedPtr; - - -class Test : public vespalib::TestApp -{ -public: - void testEmpty(); - void testSimple(); - void testCopy(); - void testReset(); - void testAccess(); - void testRelease(); - void testEqual(); - int Main() override; -}; - - -struct Data -{ - int ctorCnt; - int dtorCnt; - Data() : ctorCnt(0), dtorCnt(0) {} -}; - - -class DataRef -{ -private: - Data &_d; - DataRef(const DataRef &); - DataRef &operator=(const DataRef &); -public: - DataRef(Data &d) : _d(d) { ++d.ctorCnt; } - ~DataRef() { ++_d.dtorCnt; } - int getCtorCnt() const { return _d.ctorCnt; } - int getDtorCnt() const { return _d.dtorCnt; } -}; -typedef LinkedPtr<DataRef> PT; - -PT copyPT(const PT &pt) { return pt; } - -void -Test::testEmpty() -{ - PT pt1; - PT pt2(NULL); - EXPECT_TRUE(pt1.get() == NULL); - EXPECT_TRUE(pt2.get() == NULL); -} - -void -Test::testRelease() -{ - { - PT p(NULL); - EXPECT_TRUE(p.release() == NULL); - } - { - Data data; - PT p(new DataRef(data)); - std::unique_ptr<DataRef> ap(p.release()); - EXPECT_TRUE(ap.get() != NULL); - EXPECT_TRUE(p.release() == NULL); - } - { - Data data; - PT p(new DataRef(data)); - PT p2(p); - EXPECT_TRUE(p.release() == NULL); - EXPECT_TRUE(p2.release() == NULL); - EXPECT_TRUE(p.get() != NULL); - EXPECT_TRUE(p2.get() != NULL); - } -} - - -void -Test::testSimple() -{ - Data data; - { - PT pt1(new DataRef(data)); - EXPECT_EQUAL(data.ctorCnt, 1); - EXPECT_EQUAL(data.dtorCnt, 0); - } - EXPECT_EQUAL(data.ctorCnt, 1); - EXPECT_EQUAL(data.dtorCnt, 1); -} - - -void -Test::testCopy() -{ - Data data; - { - PT pt3; - { - PT pt1(new DataRef(data)); - PT pt2(pt1); - EXPECT_TRUE(pt1.get() == pt2.get()); - EXPECT_TRUE(pt3.get() == NULL); - pt3 = pt1; - EXPECT_TRUE(pt3.get() == pt1.get()); - { - PT pt4; - PT pt5 = pt1; - EXPECT_TRUE(pt4.get() == NULL); - EXPECT_TRUE(pt5.get() == pt1.get()); - pt4 = pt5; - EXPECT_TRUE(pt4.get() == pt1.get()); - { - PT pt6 = copyPT(pt3); - PT pt7; - EXPECT_TRUE(pt6.get() == pt1.get()); - EXPECT_TRUE(pt7.get() == NULL); - pt7 = copyPT(pt5); - EXPECT_TRUE(pt7.get() == pt1.get()); - { - PT pt8 = pt1; - EXPECT_TRUE(pt8.get() == pt1.get()); - pt8 = pt8; - EXPECT_TRUE(pt8.get() == pt1.get()); - EXPECT_EQUAL(data.ctorCnt, 1); - EXPECT_EQUAL(data.dtorCnt, 0); - } - EXPECT_EQUAL(data.ctorCnt, 1); - EXPECT_EQUAL(data.dtorCnt, 0); - } - EXPECT_EQUAL(data.ctorCnt, 1); - EXPECT_EQUAL(data.dtorCnt, 0); - } - EXPECT_EQUAL(data.ctorCnt, 1); - EXPECT_EQUAL(data.dtorCnt, 0); - } - EXPECT_EQUAL(data.ctorCnt, 1); - EXPECT_EQUAL(data.dtorCnt, 0); - } - EXPECT_EQUAL(data.ctorCnt, 1); - EXPECT_EQUAL(data.dtorCnt, 1); -} - - -void -Test::testReset() -{ - Data data; - { - PT pt1(new DataRef(data)); - EXPECT_EQUAL(data.ctorCnt, 1); - EXPECT_EQUAL(data.dtorCnt, 0); - pt1.reset(new DataRef(data)); - EXPECT_EQUAL(data.ctorCnt, 2); - EXPECT_EQUAL(data.dtorCnt, 1); - pt1.reset(); - EXPECT_EQUAL(data.ctorCnt, 2); - EXPECT_EQUAL(data.dtorCnt, 2); - pt1.reset(new DataRef(data)); - EXPECT_EQUAL(data.ctorCnt, 3); - EXPECT_EQUAL(data.dtorCnt, 2); - { - PT pt2(pt1); - pt1.reset(new DataRef(data)); - EXPECT_EQUAL(data.ctorCnt, 4); - EXPECT_EQUAL(data.dtorCnt, 2); - } - EXPECT_EQUAL(data.ctorCnt, 4); - EXPECT_EQUAL(data.dtorCnt, 3); - } - EXPECT_EQUAL(data.ctorCnt, 4); - EXPECT_EQUAL(data.dtorCnt, 4); -} - - -void -Test::testAccess() -{ - Data data; - { - PT pt1(new DataRef(data)); - EXPECT_EQUAL(pt1->getCtorCnt(), 1); - EXPECT_EQUAL((*pt1).getDtorCnt(), 0); - } -} - -class A { - int _v; -public: - A(int v) : _v(v) {} - bool operator == (const A & rhs) const { return _v == rhs._v; } -}; -typedef LinkedPtr<A> ALP; - -void -Test::testEqual() -{ - ALP a(new A(1)); - ALP a2(new A(1)); - ALP b(new A(2)); - ALP c; - EXPECT_TRUE(a == a); - EXPECT_TRUE(a2 == a2); - EXPECT_TRUE(a == a2); - EXPECT_TRUE(a2 == a); - EXPECT_TRUE(b == b); - EXPECT_TRUE(c == c); - EXPECT_FALSE(a == b); - EXPECT_FALSE(b == c); - EXPECT_FALSE(a == c); - EXPECT_FALSE(c == a); -} - -int -Test::Main() -{ - TEST_INIT("linkedptr_test"); - testEmpty(); - testSimple(); - testCopy(); - testEqual(); - testReset(); - testAccess(); - testRelease(); - TEST_DONE(); -} - -TEST_APPHOOK(Test) diff --git a/vespalib/src/vespa/vespalib/util/linkedptr.h b/vespalib/src/vespa/vespalib/util/linkedptr.h deleted file mode 100644 index 517208b9ef9..00000000000 --- a/vespalib/src/vespa/vespalib/util/linkedptr.h +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -// Copyright (C) 2004 Overture Services Norway AS - -#pragma once - -#include <algorithm> -#include <memory> -#include <cassert> - -namespace vespalib { - -/** - * @brief A LinkedPtr is a smart pointer implementing reference - * linking. - * - * Multiple instances share the ownership of an object by being linked - * together. This has the advantage of not needing external - * book-keeping. However, note that LinkedPtr may only be used to - * share objects within a thread, as there is no internal - * synchronization. - * - * If you need to share an object between threads, take a look at - * std::shared_ptr. - **/ -template <typename T> -class LinkedPtr -{ -private: - - mutable const LinkedPtr *_prev; - mutable const LinkedPtr *_next; - T *_obj; - - /** - * Unlink this pointer - **/ - void unlink() { - if (_prev == this) { - delete _obj; - } else { - _prev->_next = _next; - _next->_prev = _prev; - } - } - - /** - * Link this pointer - **/ - void link(const LinkedPtr &rhs) { - if (rhs._obj != 0) { - _obj = rhs._obj; - _prev = &rhs; - _next = rhs._next; - rhs._next = this; - _next->_prev = this; - } else { - _obj = 0; - _next = this; - _prev = this; - } - } - -public: - /** - * @brief Create a LinkedPtr owning the given object - * - * @param obj the object, may be 0 - **/ - explicit LinkedPtr(T *obj = 0) - : _prev(this), _next(this), _obj(obj) {} - - /** - * @brief Copy constructor - * - * Copying a LinkedPtr will result in a new LinkedPtr sharing the - * ownership of the object held by the original LinkedPtr. - * - * @param rhs copy this - **/ - LinkedPtr(const LinkedPtr &rhs) - : _prev(this), _next(this), _obj(0) - { - link(rhs); - } - - /** - * @brief Delete the pointed to object if we are the last - * LinkedPtr sharing ownership of it - **/ - ~LinkedPtr() { - unlink(); - } - - /** - * @brief Assignment operator - * - * @return reference to this - * @param rhs copy this - **/ - LinkedPtr &operator= (const LinkedPtr &rhs) { - if (_obj == rhs._obj) { - return *this; - } - unlink(); - link(rhs); - return *this; - } - - /** - * @brief Check if this LinkedPtr points to anything - * - * @return true if we point to something - **/ - bool isSet() const { return (_obj != 0); } - - /** - * @brief Obtain the object being pointed to - * - * @return the object (by pointer) - **/ - T *get() const { return _obj; } - - bool operator == (const LinkedPtr & rhs) const { return (_obj == rhs._obj) || - ( (_obj != NULL) && - (rhs._obj != NULL) && - (*_obj == *rhs._obj)); } - - /** - * @brief Access the object being pointed to - * - * This is the preferred way to access the object being pointed to - * as it makes the LinkedPtr look like a naked pointer. - * - * @return the object (by pointer) - **/ - T *operator->() const { return get(); } - - /** - * @brief Obtain the object being pointed to - * - * @return the object (by reference) - **/ - T &operator*() const { return *get(); } - - /** - * @brief Change this pointer - * - * This method makes this LinkedPtr drop its current pointer and - * point to something new. If we are the last owner of the old - * object, it is deleted. The new object will be owned by this - * LinkedPtr (just like when using the constructor). - * - * @param obj the object, may be 0 - **/ - void reset(T *obj = 0) { - unlink(); - _obj = obj; - _next = this; - _prev = this; - } - - /** - * @brief release the object pointed to - * - * This is an operation that can only be done when this is the only item - * in the list. - * - * @return the pointer to the owned object or NULL if it is not the only - * owner. - **/ - T * release() { - T * obj(NULL); - if ((_next == _prev) && (_prev == this)) { - obj = _obj; - _obj = NULL; - } - return obj; - } -}; - -} // namespace vespalib diff --git a/vespalib/src/vespa/vespalib/util/overview.h b/vespalib/src/vespa/vespalib/util/overview.h index 7fc48e2f19e..7849887a14c 100644 --- a/vespalib/src/vespa/vespalib/util/overview.h +++ b/vespalib/src/vespa/vespalib/util/overview.h @@ -37,10 +37,6 @@ * * <BR> vespalib::ReferenceCounter * - * Simple smart pointers (deprecated) - * - * <BR> \ref vespalib::LinkedPtr<T> - * * Advanced pointer utilities * * \ref vespalib::PtrHolder<T> |