From 0b7ebfae977f40d4cd2fb740002381730d7a7c25 Mon Sep 17 00:00:00 2001 From: "James E. King, III" Date: Thu, 9 Feb 2017 09:36:01 -0500 Subject: [PATCH] THRIFT-3622: remove auto_ptr use in the codebase because it is deprecated --- lib/cpp/src/thrift/async/TEvhttpServer.cpp | 4 +-- .../thrift/concurrency/BoostThreadFactory.cpp | 8 +++--- .../src/thrift/transport/TFileTransport.cpp | 27 ++++++++++++++++--- lib/cpp/test/DebugProtoTest.cpp | 7 ++--- lib/cpp/test/JSONProtoTest.cpp | 7 ++--- 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/lib/cpp/src/thrift/async/TEvhttpServer.cpp b/lib/cpp/src/thrift/async/TEvhttpServer.cpp index 57d0d612039..4fa41f8f0b9 100644 --- a/lib/cpp/src/thrift/async/TEvhttpServer.cpp +++ b/lib/cpp/src/thrift/async/TEvhttpServer.cpp @@ -20,10 +20,10 @@ #include #include #include +#include #include #include #include - #include #ifndef HTTP_INTERNAL // libevent < 2 @@ -118,7 +118,7 @@ void TEvhttpServer::process(struct evhttp_request* req) { void TEvhttpServer::complete(RequestContext* ctx, bool success) { (void)success; - std::auto_ptr ptr(ctx); + boost::scoped_ptr ptr(ctx); int code = success ? 200 : 400; const char* reason = success ? "OK" : "Bad Request"; diff --git a/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp b/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp index a72d38b9c25..6adcb682ed8 100644 --- a/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp +++ b/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp @@ -26,8 +26,9 @@ #include -#include +#include #include +#include namespace apache { namespace thrift { @@ -48,7 +49,7 @@ class BoostThread : public Thread { static void* threadMain(void* arg); private: - std::auto_ptr thread_; + boost::scoped_ptr thread_; STATE state_; weak_ptr self_; bool detached_; @@ -80,8 +81,7 @@ class BoostThread : public Thread { state_ = starting; - thread_ - = std::auto_ptr(new boost::thread(boost::bind(threadMain, (void*)selfRef))); + thread_.reset(new boost::thread(boost::bind(threadMain, (void*)selfRef))); if (detached_) thread_->detach(); diff --git a/lib/cpp/src/thrift/transport/TFileTransport.cpp b/lib/cpp/src/thrift/transport/TFileTransport.cpp index 85e88b9da95..e49f81c66b8 100644 --- a/lib/cpp/src/thrift/transport/TFileTransport.cpp +++ b/lib/cpp/src/thrift/transport/TFileTransport.cpp @@ -24,6 +24,16 @@ #include #include +#include +#include +#if (BOOST_VERSION >= 105700) +#include +using boost::movelib::unique_ptr; +#else +#include +using boost::interprocess::unique_ptr; +#endif + #ifdef HAVE_SYS_TIME_H #include #else @@ -52,9 +62,12 @@ namespace apache { namespace thrift { namespace transport { -using boost::scoped_ptr; using boost::shared_ptr; -using namespace std; +using std::cerr; +using std::cout; +using std::endl; +using std::min; +using std::string; using namespace apache::thrift::protocol; using namespace apache::thrift::concurrency; @@ -192,6 +205,14 @@ void TFileTransport::write(const uint8_t* buf, uint32_t len) { enqueueEvent(buf, len); } +// this is needed until boost 1.57 as the older unique_ptr implementation +// has no default deleter in interprocess +template +struct uniqueDeleter +{ + void operator()(_T *ptr) const { delete ptr; } +}; + void TFileTransport::enqueueEvent(const uint8_t* buf, uint32_t eventLen) { // can't enqueue more events if file is going to close if (closing_) { @@ -209,7 +230,7 @@ void TFileTransport::enqueueEvent(const uint8_t* buf, uint32_t eventLen) { return; } - std::auto_ptr toEnqueue(new eventInfo()); + unique_ptr > toEnqueue(new eventInfo()); toEnqueue->eventBuff_ = new uint8_t[(sizeof(uint8_t) * eventLen) + 4]; // first 4 bytes is the event length diff --git a/lib/cpp/test/DebugProtoTest.cpp b/lib/cpp/test/DebugProtoTest.cpp index 607744b3853..c070af22596 100644 --- a/lib/cpp/test/DebugProtoTest.cpp +++ b/lib/cpp/test/DebugProtoTest.cpp @@ -21,13 +21,14 @@ #include #include "gen-cpp/DebugProtoTest_types.h" #include +#include #define BOOST_TEST_MODULE DebugProtoTest #include using namespace thrift::test::debug; -static std::auto_ptr ooe; +static boost::scoped_ptr ooe; void testCaseSetup_1() { ooe.reset(new OneOfEach); @@ -80,7 +81,7 @@ BOOST_AUTO_TEST_CASE(test_debug_proto_1) { "Expected:\n" << expected_result << "\nGotten:\n" << result); } -static std::auto_ptr n; +static boost::scoped_ptr n; void testCaseSetup_2() { testCaseSetup_1(); @@ -148,7 +149,7 @@ BOOST_AUTO_TEST_CASE(test_debug_proto_2) { "Expected:\n" << expected_result << "\nGotten:\n" << result); } -static std::auto_ptr hm; +static boost::scoped_ptr hm; void testCaseSetup_3() { testCaseSetup_2(); diff --git a/lib/cpp/test/JSONProtoTest.cpp b/lib/cpp/test/JSONProtoTest.cpp index 2da3044a073..2ac7adc6f6d 100644 --- a/lib/cpp/test/JSONProtoTest.cpp +++ b/lib/cpp/test/JSONProtoTest.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "gen-cpp/DebugProtoTest_types.h" #define BOOST_TEST_MODULE JSONProtoTest @@ -32,7 +33,7 @@ using namespace thrift::test::debug; using apache::thrift::transport::TMemoryBuffer; using apache::thrift::protocol::TJSONProtocol; -static std::auto_ptr ooe; +static boost::scoped_ptr ooe; void testCaseSetup_1() { ooe.reset(new OneOfEach); @@ -65,7 +66,7 @@ BOOST_AUTO_TEST_CASE(test_json_proto_1) { "Expected:\n" << expected_result << "\nGotten:\n" << result); } -static std::auto_ptr n; +static boost::scoped_ptr n; void testCaseSetup_2() { testCaseSetup_1(); @@ -105,7 +106,7 @@ BOOST_AUTO_TEST_CASE(test_json_proto_2) { "Expected:\n" << expected_result << "\nGotten:\n" << result); } -static std::auto_ptr hm; +static boost::scoped_ptr hm; void testCaseSetup_3() { testCaseSetup_2();