You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2022/01/18 14:04:17 UTC
[qpid-proton] 01/05: PROTON-2485: Use C++11 standard unique_ptr instead of our version
This is an automated email from the ASF dual-hosted git repository.
astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
commit 7473eb41c9082bc5fbc70641d8b8b3130432879e
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Wed Jan 12 11:24:31 2022 -0500
PROTON-2485: Use C++11 standard unique_ptr instead of our version
Now we only support C++11 and later we can use std::unique_ptr. As it
has the same size as our custom version and was never in the API just
used as a private member this should not change our ABI/API.
---
cpp/include/proton/connection_options.hpp | 4 +-
cpp/include/proton/container.hpp | 4 +-
cpp/include/proton/internal/pn_unique_ptr.hpp | 67 ---------------------------
cpp/include/proton/map.hpp | 4 +-
cpp/include/proton/message.hpp | 2 -
cpp/include/proton/receiver_options.hpp | 4 +-
cpp/include/proton/reconnect_options.hpp | 4 +-
cpp/include/proton/sender_options.hpp | 4 +-
cpp/include/proton/session_options.hpp | 5 +-
cpp/include/proton/source_options.hpp | 4 +-
cpp/include/proton/target_options.hpp | 4 +-
cpp/include/proton/url.hpp | 4 +-
cpp/include/proton/work_queue.hpp | 6 +--
cpp/src/contexts.hpp | 9 ++--
cpp/src/credit_test.cpp | 5 +-
cpp/src/delivery_test.cpp | 1 -
cpp/src/map.cpp | 2 +-
cpp/src/reconnect_options_impl.hpp | 1 -
18 files changed, 32 insertions(+), 102 deletions(-)
diff --git a/cpp/include/proton/connection_options.hpp b/cpp/include/proton/connection_options.hpp
index c96cbe7..d86a203 100644
--- a/cpp/include/proton/connection_options.hpp
+++ b/cpp/include/proton/connection_options.hpp
@@ -25,13 +25,13 @@
#include "./duration.hpp"
#include "./fwd.hpp"
#include "./internal/export.hpp"
-#include "./internal/pn_unique_ptr.hpp"
#include "./symbol.hpp"
#include "./types_fwd.hpp"
#include <proton/type_compat.h>
#include <map>
+#include <memory>
#include <vector>
#include <string>
@@ -218,7 +218,7 @@ class connection_options {
messaging_handler* handler() const;
class impl;
- internal::pn_unique_ptr<impl> impl_;
+ std::unique_ptr<impl> impl_;
/// @cond INTERNAL
friend class container;
diff --git a/cpp/include/proton/container.hpp b/cpp/include/proton/container.hpp
index eafcde7..f5a4dd6 100644
--- a/cpp/include/proton/container.hpp
+++ b/cpp/include/proton/container.hpp
@@ -27,8 +27,8 @@
#include "./types_fwd.hpp"
#include "./internal/export.hpp"
-#include "./internal/pn_unique_ptr.hpp"
+#include <memory>
#include <string>
/// @file
@@ -313,7 +313,7 @@ class PN_CPP_CLASS_EXTERN container {
/// A C++11 user should never call the v03 overload so it is private in this case
PN_CPP_EXTERN void schedule(duration dur, internal::v03::work fn);
class impl;
- internal::pn_unique_ptr<impl> impl_;
+ std::unique_ptr<impl> impl_;
/// @cond INTERNAL
friend class connection_options;
diff --git a/cpp/include/proton/internal/pn_unique_ptr.hpp b/cpp/include/proton/internal/pn_unique_ptr.hpp
deleted file mode 100644
index 51679d1..0000000
--- a/cpp/include/proton/internal/pn_unique_ptr.hpp
+++ /dev/null
@@ -1,67 +0,0 @@
-#ifndef PROTON_INTERNAL_UNIQUE_PTR_HPP
-#define PROTON_INTERNAL_UNIQUE_PTR_HPP
-
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-
-#include <memory>
-
-namespace proton {
-namespace internal {
-
-template <class T> class pn_unique_ptr;
-template <class T> void swap(pn_unique_ptr<T>& x, pn_unique_ptr<T>& y);
-
-/// A simple unique ownership pointer, used as a return value from
-/// functions that transfer ownership to the caller.
-///
-/// pn_unique_ptr return values should be converted immediately to
-/// std::unique_ptr if that is available or std::auto_ptr (by calling
-/// release()) for older C++. You should not use pn_unique_ptr in your
-/// own code. It is a limited pointer class designed only to work
-/// around differences between C++11 and C++03.
-template <class T> class pn_unique_ptr {
- public:
- pn_unique_ptr(T* p=0) : ptr_(p) {}
- pn_unique_ptr(pn_unique_ptr&& x) : ptr_(0) { std::swap(ptr_, x.ptr_); }
- ~pn_unique_ptr() { delete(ptr_); }
- T& operator*() const { return *ptr_; }
- T* operator->() const { return ptr_; }
- T* get() const { return ptr_; }
- void reset(T* p = 0) { pn_unique_ptr<T> tmp(p); std::swap(ptr_, tmp.ptr_); }
- T* release() { T *p = ptr_; ptr_ = 0; return p; }
- explicit operator bool() const { return get(); }
- bool operator !() const { return !get(); }
- void swap(pn_unique_ptr& x) { std::swap(ptr_, x.ptr_); }
-
- operator std::unique_ptr<T>() { T *p = ptr_; ptr_ = 0; return std::unique_ptr<T>(p); }
-
- private:
- T* ptr_;
-};
-
-template <class T> void swap(pn_unique_ptr<T>& x, pn_unique_ptr<T>& y) { x.swap(y); }
-
-} // internal
-} // proton
-
-#endif // PROTON_INTERNAL_UNIQUE_PTR_HPP
diff --git a/cpp/include/proton/map.hpp b/cpp/include/proton/map.hpp
index ff9eed0..b114d1c 100644
--- a/cpp/include/proton/map.hpp
+++ b/cpp/include/proton/map.hpp
@@ -23,9 +23,9 @@
*/
#include "./value.hpp"
-#include "./internal/pn_unique_ptr.hpp"
#include <cstddef>
+#include <memory>
/// @file
/// @copybrief proton::map
@@ -132,7 +132,7 @@ class PN_CPP_CLASS_EXTERN map {
private:
typedef map_type_impl<K,T> map_type;
- mutable internal::pn_unique_ptr<map_type> map_;
+ mutable std::unique_ptr<map_type> map_;
mutable proton::value value_;
map_type& cache() const;
diff --git a/cpp/include/proton/message.hpp b/cpp/include/proton/message.hpp
index fc87050..de23824 100644
--- a/cpp/include/proton/message.hpp
+++ b/cpp/include/proton/message.hpp
@@ -29,8 +29,6 @@
#include "./value.hpp"
#include "./map.hpp"
-#include "./internal/pn_unique_ptr.hpp"
-
#include <proton/type_compat.h>
#include <string>
diff --git a/cpp/include/proton/receiver_options.hpp b/cpp/include/proton/receiver_options.hpp
index bcf8276..e82ae73 100644
--- a/cpp/include/proton/receiver_options.hpp
+++ b/cpp/include/proton/receiver_options.hpp
@@ -24,11 +24,11 @@
#include "./fwd.hpp"
#include "./internal/export.hpp"
-#include "./internal/pn_unique_ptr.hpp"
#include "./delivery_mode.hpp"
#include "./types_fwd.hpp"
#include <map>
+#include <memory>
#include <string>
/// @file
@@ -111,7 +111,7 @@ class receiver_options {
const std::string* get_name() const; // Pointer to name if set, else 0
class impl;
- internal::pn_unique_ptr<impl> impl_;
+ std::unique_ptr<impl> impl_;
/// @cond INTERNAL
friend class receiver;
diff --git a/cpp/include/proton/reconnect_options.hpp b/cpp/include/proton/reconnect_options.hpp
index fab9fb8..76d5fcf 100644
--- a/cpp/include/proton/reconnect_options.hpp
+++ b/cpp/include/proton/reconnect_options.hpp
@@ -23,10 +23,10 @@
*/
#include "./internal/export.hpp"
-#include "./internal/pn_unique_ptr.hpp"
#include "./duration.hpp"
#include "./source.hpp"
+#include <memory>
#include <string>
#include <vector>
@@ -83,7 +83,7 @@ class reconnect_options {
private:
class impl;
- internal::pn_unique_ptr<impl> impl_;
+ std::unique_ptr<impl> impl_;
/// @cond INTERNAL
friend class connection_options;
diff --git a/cpp/include/proton/sender_options.hpp b/cpp/include/proton/sender_options.hpp
index 143db3f..a706806 100644
--- a/cpp/include/proton/sender_options.hpp
+++ b/cpp/include/proton/sender_options.hpp
@@ -24,11 +24,11 @@
#include "./fwd.hpp"
#include "./internal/export.hpp"
-#include "./internal/pn_unique_ptr.hpp"
#include "./delivery_mode.hpp"
#include "./types_fwd.hpp"
#include <map>
+#include <memory>
#include <string>
/// @file
@@ -102,7 +102,7 @@ class sender_options {
const std::string* get_name() const; // Pointer to name if set, else 0
class impl;
- internal::pn_unique_ptr<impl> impl_;
+ std::unique_ptr<impl> impl_;
/// @cond INTERNAL
friend class sender;
diff --git a/cpp/include/proton/session_options.hpp b/cpp/include/proton/session_options.hpp
index 515a798..18196df 100644
--- a/cpp/include/proton/session_options.hpp
+++ b/cpp/include/proton/session_options.hpp
@@ -24,7 +24,8 @@
#include "./fwd.hpp"
#include "./internal/export.hpp"
-#include "./internal/pn_unique_ptr.hpp"
+
+#include <memory>
/// @file
/// @copybrief proton::session_options
@@ -60,7 +61,7 @@ class session_options {
void apply(session&) const;
class impl;
- internal::pn_unique_ptr<impl> impl_;
+ std::unique_ptr<impl> impl_;
friend class session;
/// @endcond
diff --git a/cpp/include/proton/source_options.hpp b/cpp/include/proton/source_options.hpp
index 8a0f093..754090c 100644
--- a/cpp/include/proton/source_options.hpp
+++ b/cpp/include/proton/source_options.hpp
@@ -23,11 +23,11 @@
*/
#include "./internal/export.hpp"
-#include "./internal/pn_unique_ptr.hpp"
#include "./duration.hpp"
#include "./source.hpp"
#include <map>
+#include <memory>
#include <string>
#include <vector>
@@ -101,7 +101,7 @@ class source_options {
void apply(source&) const;
class impl;
- internal::pn_unique_ptr<impl> impl_;
+ std::unique_ptr<impl> impl_;
/// @cond INTERNAL
friend class source;
diff --git a/cpp/include/proton/target_options.hpp b/cpp/include/proton/target_options.hpp
index 02feba8..f5fe991 100644
--- a/cpp/include/proton/target_options.hpp
+++ b/cpp/include/proton/target_options.hpp
@@ -23,11 +23,11 @@
*/
#include "./internal/export.hpp"
-#include "./internal/pn_unique_ptr.hpp"
#include "./duration.hpp"
#include "./target.hpp"
#include <map>
+#include <memory>
#include <string>
#include <vector>
@@ -92,7 +92,7 @@ class target_options {
void apply(target&) const;
class impl;
- internal::pn_unique_ptr<impl> impl_;
+ std::unique_ptr<impl> impl_;
/// @cond INTERNAL
friend class target;
diff --git a/cpp/include/proton/url.hpp b/cpp/include/proton/url.hpp
index 2d7c127..1d2d5be 100644
--- a/cpp/include/proton/url.hpp
+++ b/cpp/include/proton/url.hpp
@@ -22,12 +22,12 @@
*
*/
-#include "./internal/pn_unique_ptr.hpp"
#include "./error.hpp"
#include <proton/type_compat.h>
#include <iosfwd>
+#include <memory>
#include <string>
/// @file
@@ -135,7 +135,7 @@ class PN_CPP_DEPRECATED("Use a third-party URL library") url {
private:
struct impl;
- internal::pn_unique_ptr<impl> impl_;
+ std::unique_ptr<impl> impl_;
/// @cond INTERNAL
diff --git a/cpp/include/proton/work_queue.hpp b/cpp/include/proton/work_queue.hpp
index bc09f88..4f4a1d0 100644
--- a/cpp/include/proton/work_queue.hpp
+++ b/cpp/include/proton/work_queue.hpp
@@ -26,11 +26,11 @@
#include "./fwd.hpp"
#include "./function.hpp"
#include "./internal/export.hpp"
-#include "./internal/pn_unique_ptr.hpp"
#include <functional>
-#include <utility>
+#include <memory>
#include <type_traits>
+#include <utility>
struct pn_connection_t;
struct pn_session_t;
@@ -375,7 +375,7 @@ class PN_CPP_CLASS_EXTERN work_queue {
PN_CPP_EXTERN static work_queue& get(pn_session_t*);
PN_CPP_EXTERN static work_queue& get(pn_link_t*);
- internal::pn_unique_ptr<impl> impl_;
+ std::unique_ptr<impl> impl_;
/// @cond INTERNAL
friend class container;
diff --git a/cpp/src/contexts.hpp b/cpp/src/contexts.hpp
index dcd8081..8d22837 100644
--- a/cpp/src/contexts.hpp
+++ b/cpp/src/contexts.hpp
@@ -26,7 +26,8 @@
#include "proton/work_queue.hpp"
#include "proton/message.hpp"
-#include "proton/internal/pn_unique_ptr.hpp"
+
+#include <memory>
struct pn_record_t;
struct pn_link_t;
@@ -95,8 +96,8 @@ class connection_context : public context {
messaging_handler* handler;
std::string reconnect_url_;
std::vector<std::string> failover_urls_;
- internal::pn_unique_ptr<connection_options> connection_options_;
- internal::pn_unique_ptr<reconnect_context> reconnect_context_;
+ std::unique_ptr<connection_options> connection_options_;
+ std::unique_ptr<reconnect_context> reconnect_context_;
listener_context* listener_context_;
work_queue work_queue_;
};
@@ -122,7 +123,7 @@ class listener_context : public context {
static listener_context& get(pn_listener_t* c);
listen_handler* listen_handler_;
- internal::pn_unique_ptr<const connection_options> connection_options_;
+ std::unique_ptr<const connection_options> connection_options_;
};
class link_context : public context {
diff --git a/cpp/src/credit_test.cpp b/cpp/src/credit_test.cpp
index a6993cb..ea8452a 100644
--- a/cpp/src/credit_test.cpp
+++ b/cpp/src/credit_test.cpp
@@ -31,12 +31,11 @@
#include "proton/transport.hpp"
#include "proton/work_queue.hpp"
-#include "proton/internal/pn_unique_ptr.hpp"
-
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstdio>
+#include <memory>
#include <sstream>
namespace {
@@ -212,7 +211,7 @@ class tester : public proton::messaging_handler, public waiter {
virtual void first_idle() = 0;
protected:
- proton::internal::pn_unique_ptr<server_connection_handler> srv_;
+ std::unique_ptr<server_connection_handler> srv_;
proton::container container_;
proton::receiver receiver_;
proton::work next_idle_;
diff --git a/cpp/src/delivery_test.cpp b/cpp/src/delivery_test.cpp
index 9765223..021c86c 100644
--- a/cpp/src/delivery_test.cpp
+++ b/cpp/src/delivery_test.cpp
@@ -36,7 +36,6 @@
#include <proton/value.hpp>
#include "proton/error_condition.hpp"
-#include "proton/internal/pn_unique_ptr.hpp"
#include "proton/receiver_options.hpp"
#include "proton/transport.hpp"
#include "proton/work_queue.hpp"
diff --git a/cpp/src/map.cpp b/cpp/src/map.cpp
index fdfb3fd..6ff62ee 100644
--- a/cpp/src/map.cpp
+++ b/cpp/src/map.cpp
@@ -117,7 +117,7 @@ void map<K,T>::value(const proton::value& x) {
if (x.empty()) {
clear();
} else {
- internal::pn_unique_ptr<map_type> tmp(new map_type);
+ std::unique_ptr<map_type> tmp(new map_type);
proton::get(x, *tmp); // Validate by decoding, may throw
map_.reset(tmp.release());
value_.clear();
diff --git a/cpp/src/reconnect_options_impl.hpp b/cpp/src/reconnect_options_impl.hpp
index 4861292..aacc14c 100644
--- a/cpp/src/reconnect_options_impl.hpp
+++ b/cpp/src/reconnect_options_impl.hpp
@@ -23,7 +23,6 @@
*/
#include "proton/duration.hpp"
-#include "proton/internal/pn_unique_ptr.hpp"
#include "proton/reconnect_options.hpp"
#include <string>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org