From: Amos Jeffries Date: Sat, 23 May 2015 20:17:16 +0000 (-0700) Subject: C++11: migrate auto_ptr to unique_ptr X-Git-Tag: merge-candidate-3-v1~102 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=829030b5ce5af975ebd66b0fbb8ba26dadab6d99;p=thirdparty%2Fsquid.git C++11: migrate auto_ptr to unique_ptr Improving the backward compatibility workaround for older compilers. This is required for GCC 5.x which does not include any auto_ptr support or compatibility at all. --- diff --git a/acinclude/ax_cxx_0x_types.m4 b/acinclude/ax_cxx_0x_types.m4 index 5898a7f400..6707805a03 100644 --- a/acinclude/ax_cxx_0x_types.m4 +++ b/acinclude/ax_cxx_0x_types.m4 @@ -42,6 +42,9 @@ AC_DEFUN([AX_CXX_TYPE_UNIQUE_PTR],[ AC_MSG_RESULT(yes)], [ HAVE_UNIQUE_PTR=no AC_MSG_RESULT(no)]) + if test "x$HAVE_UNIQUE_PTR" = xno; then + AC_DEFINE(unique_ptr, auto_ptr, [Leave undefined if std::unique_ptr is supported]) + fi if test "x$HAVE_UNIQUE_PTR" = xyes; then AC_DEFINE(HAVE_UNIQUE_PTR, 1, [Define to 1 if std::unique_ptr is supported]) fi diff --git a/src/CollapsedForwarding.cc b/src/CollapsedForwarding.cc index c86e0306f4..f95bbef913 100644 --- a/src/CollapsedForwarding.cc +++ b/src/CollapsedForwarding.cc @@ -27,7 +27,7 @@ static const char *const ShmLabel = "cf"; // TODO: make configurable or compute from squid.conf settings if possible static const int QueueCapacity = 1024; -std::auto_ptr CollapsedForwarding::queue; +std::unique_ptr CollapsedForwarding::queue; /// IPC queue message class CollapsedForwardingMsg diff --git a/src/CollapsedForwarding.h b/src/CollapsedForwarding.h index 89e18e46cb..b964b504b5 100644 --- a/src/CollapsedForwarding.h +++ b/src/CollapsedForwarding.h @@ -40,7 +40,7 @@ public: private: typedef Ipc::MultiQueue Queue; - static std::auto_ptr queue; ///< IPC queue + static std::unique_ptr queue; ///< IPC queue }; #endif /* SQUID_COLLAPSED_FORWARDING_H */ diff --git a/src/DiskIO/IpcIo/IpcIoFile.cc b/src/DiskIO/IpcIo/IpcIoFile.cc index 16418c707d..4b650ecd75 100644 --- a/src/DiskIO/IpcIo/IpcIoFile.cc +++ b/src/DiskIO/IpcIo/IpcIoFile.cc @@ -45,7 +45,7 @@ static const int QueueCapacity = 1024; const double IpcIoFile::Timeout = 7; // seconds; XXX: ALL,9 may require more IpcIoFile::IpcIoFileList IpcIoFile::WaitingForOpen; IpcIoFile::IpcIoFilesMap IpcIoFile::IpcIoFiles; -std::auto_ptr IpcIoFile::queue; +std::unique_ptr IpcIoFile::queue; bool IpcIoFile::DiskerHandleMoreRequestsScheduled = false; diff --git a/src/DiskIO/IpcIo/IpcIoFile.h b/src/DiskIO/IpcIo/IpcIoFile.h index 4bf21ca0ed..fbf2511827 100644 --- a/src/DiskIO/IpcIo/IpcIoFile.h +++ b/src/DiskIO/IpcIo/IpcIoFile.h @@ -140,7 +140,7 @@ private: static IpcIoFilesMap IpcIoFiles; typedef Ipc::FewToFewBiQueue Queue; - static std::auto_ptr queue; ///< IPC queue + static std::unique_ptr queue; ///< IPC queue /// whether we are waiting for an event to handle still queued I/O requests static bool DiskerHandleMoreRequestsScheduled; diff --git a/src/base/AsyncJobs.dox b/src/base/AsyncJobs.dox index 6e5f16f5ce..854b83a7c9 100644 --- a/src/base/AsyncJobs.dox +++ b/src/base/AsyncJobs.dox @@ -37,7 +37,7 @@ If you want to do something before starting the job, do it in the constructor or some custom method that the job creator will call _before_ calling AsyncJob::Start(): - std::auto_ptr job(new MyJob(...)); // sync/blocking + std::unique_ptr job(new MyJob(...)); // sync/blocking job->prepare(...); // sync/blocking job->prepareSomethingElse(...); // sync/blocking AsyncStart(job.release()); // non-blocking diff --git a/src/base/TidyPointer.h b/src/base/TidyPointer.h index 4be17f4155..19334dbeac 100644 --- a/src/base/TidyPointer.h +++ b/src/base/TidyPointer.h @@ -11,7 +11,7 @@ /** * A pointer that deletes the object it points to when the pointer's owner or - * context is gone. Similar to std::auto_ptr but without confusing assignment + * context is gone. Similar to std::unique_ptr but without confusing assignment * and with a customizable cleanup method. Prevents memory leaks in * the presence of exceptions and processing short cuts. */ diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 008ce87b72..3b35fbd779 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -804,7 +804,7 @@ clientReplyContext::blockedHit() const return false; // internal content "hits" cannot be blocked if (const HttpReply *rep = http->storeEntry()->getReply()) { - std::auto_ptr chl(clientAclChecklistCreate(Config.accessList.sendHit, http)); + std::unique_ptr chl(clientAclChecklistCreate(Config.accessList.sendHit, http)); chl->reply = const_cast(rep); // ACLChecklist API bug HTTPMSGLOCK(chl->reply); return chl->fastCheck() != ACCESS_ALLOWED; // when in doubt, block diff --git a/src/mgr/Inquirer.cc b/src/mgr/Inquirer.cc index 1c53d1a39b..9880f36436 100644 --- a/src/mgr/Inquirer.cc +++ b/src/mgr/Inquirer.cc @@ -72,28 +72,16 @@ Mgr::Inquirer::start() Must(Comm::IsConnOpen(conn)); Must(aggrAction != NULL); -#if HAVE_UNIQUE_PTR std::unique_ptr replyBuf; -#else - std::auto_ptr replyBuf; -#endif if (strands.empty()) { LOCAL_ARRAY(char, url, MAX_URL); snprintf(url, MAX_URL, "%s", aggrAction->command().params.httpUri.termedBuf()); HttpRequest *req = HttpRequest::CreateFromUrl(url); ErrorState err(ERR_INVALID_URL, Http::scNotFound, req); -#if HAVE_UNIQUE_PTR std::unique_ptr reply(err.BuildHttpReply()); -#else - std::auto_ptr reply(err.BuildHttpReply()); -#endif replyBuf.reset(reply->pack()); } else { -#if HAVE_UNIQUE_PTR std::unique_ptr reply(new HttpReply); -#else - std::auto_ptr reply(new HttpReply); -#endif reply->setHeaders(Http::scOkay, NULL, "text/plain", -1, squid_curtime, squid_curtime); reply->header.putStr(HDR_CONNECTION, "close"); // until we chunk response replyBuf.reset(reply->pack());