Skip to content

Commit

Permalink
THRIFT-3622: remove auto_ptr use in the codebase because it is deprec…
Browse files Browse the repository at this point in the history
…ated

Client: C++

This closes #1183
  • Loading branch information
jeking3 committed Feb 10, 2017
1 parent 3590f1e commit e1832c3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/cpp/src/thrift/async/TEvhttpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#include <thrift/async/TEvhttpServer.h>
#include <thrift/async/TAsyncBufferProcessor.h>
#include <thrift/transport/TBufferTransports.h>
#include <boost/scoped_ptr.hpp>
#include <evhttp.h>
#include <event2/buffer.h>
#include <event2/buffer_compat.h>

#include <iostream>

#ifndef HTTP_INTERNAL // libevent < 2
Expand Down Expand Up @@ -118,7 +118,7 @@ void TEvhttpServer::process(struct evhttp_request* req) {

void TEvhttpServer::complete(RequestContext* ctx, bool success) {
(void)success;
std::auto_ptr<RequestContext> ptr(ctx);
boost::scoped_ptr<RequestContext> ptr(ctx);

int code = success ? 200 : 400;
const char* reason = success ? "OK" : "Bad Request";
Expand Down
8 changes: 4 additions & 4 deletions lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@

#include <cassert>

#include <boost/weak_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/thread.hpp>
#include <boost/weak_ptr.hpp>

namespace apache {
namespace thrift {
Expand All @@ -48,7 +49,7 @@ class BoostThread : public Thread {
static void* threadMain(void* arg);

private:
std::auto_ptr<boost::thread> thread_;
boost::scoped_ptr<boost::thread> thread_;
STATE state_;
weak_ptr<BoostThread> self_;
bool detached_;
Expand Down Expand Up @@ -80,8 +81,7 @@ class BoostThread : public Thread {

state_ = starting;

thread_
= std::auto_ptr<boost::thread>(new boost::thread(boost::bind(threadMain, (void*)selfRef)));
thread_.reset(new boost::thread(boost::bind(threadMain, (void*)selfRef)));

if (detached_)
thread_->detach();
Expand Down
27 changes: 24 additions & 3 deletions lib/cpp/src/thrift/transport/TFileTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
#include <thrift/transport/PlatformSocket.h>
#include <thrift/concurrency/FunctionRunner.h>

#include <boost/scoped_ptr.hpp>
#include <boost/version.hpp>
#if (BOOST_VERSION >= 105700)
#include <boost/move/unique_ptr.hpp>
using boost::movelib::unique_ptr;
#else
#include <boost/interprocess/smart_ptr/unique_ptr.hpp>
using boost::interprocess::unique_ptr;
#endif

#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 <class _T>
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_) {
Expand All @@ -209,7 +230,7 @@ void TFileTransport::enqueueEvent(const uint8_t* buf, uint32_t eventLen) {
return;
}

std::auto_ptr<eventInfo> toEnqueue(new eventInfo());
unique_ptr<eventInfo, uniqueDeleter<eventInfo> > toEnqueue(new eventInfo());
toEnqueue->eventBuff_ = new uint8_t[(sizeof(uint8_t) * eventLen) + 4];

// first 4 bytes is the event length
Expand Down
7 changes: 4 additions & 3 deletions lib/cpp/test/DebugProtoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
#include <cmath>
#include "gen-cpp/DebugProtoTest_types.h"
#include <thrift/protocol/TDebugProtocol.h>
#include <boost/scoped_ptr.hpp>

#define BOOST_TEST_MODULE DebugProtoTest
#include <boost/test/unit_test.hpp>

using namespace thrift::test::debug;

static std::auto_ptr<OneOfEach> ooe;
static boost::scoped_ptr<OneOfEach> ooe;

void testCaseSetup_1() {
ooe.reset(new OneOfEach);
Expand Down Expand Up @@ -80,7 +81,7 @@ BOOST_AUTO_TEST_CASE(test_debug_proto_1) {
"Expected:\n" << expected_result << "\nGotten:\n" << result);
}

static std::auto_ptr<Nesting> n;
static boost::scoped_ptr<Nesting> n;

void testCaseSetup_2() {
testCaseSetup_1();
Expand Down Expand Up @@ -148,7 +149,7 @@ BOOST_AUTO_TEST_CASE(test_debug_proto_2) {
"Expected:\n" << expected_result << "\nGotten:\n" << result);
}

static std::auto_ptr<HolyMoley> hm;
static boost::scoped_ptr<HolyMoley> hm;

void testCaseSetup_3() {
testCaseSetup_2();
Expand Down
7 changes: 4 additions & 3 deletions lib/cpp/test/JSONProtoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <sstream>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/protocol/TJSONProtocol.h>
#include <boost/scoped_ptr.hpp>
#include "gen-cpp/DebugProtoTest_types.h"

#define BOOST_TEST_MODULE JSONProtoTest
Expand All @@ -32,7 +33,7 @@ using namespace thrift::test::debug;
using apache::thrift::transport::TMemoryBuffer;
using apache::thrift::protocol::TJSONProtocol;

static std::auto_ptr<OneOfEach> ooe;
static boost::scoped_ptr<OneOfEach> ooe;

void testCaseSetup_1() {
ooe.reset(new OneOfEach);
Expand Down Expand Up @@ -65,7 +66,7 @@ BOOST_AUTO_TEST_CASE(test_json_proto_1) {
"Expected:\n" << expected_result << "\nGotten:\n" << result);
}

static std::auto_ptr<Nesting> n;
static boost::scoped_ptr<Nesting> n;

void testCaseSetup_2() {
testCaseSetup_1();
Expand Down Expand Up @@ -105,7 +106,7 @@ BOOST_AUTO_TEST_CASE(test_json_proto_2) {
"Expected:\n" << expected_result << "\nGotten:\n" << result);
}

static std::auto_ptr<HolyMoley> hm;
static boost::scoped_ptr<HolyMoley> hm;

void testCaseSetup_3() {
testCaseSetup_2();
Expand Down

0 comments on commit e1832c3

Please sign in to comment.