From: Amos Jeffries Date: Wed, 27 May 2015 23:28:09 +0000 (-0700) Subject: Portability: migrate auto_ptr to C++11 unique_ptr X-Git-Tag: SQUID_3_5_5~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cbe0f590512d2d3bc153e9779be8a08c95178474;p=thirdparty%2Fsquid.git Portability: migrate auto_ptr to C++11 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. This does apply for 3.5 where C++11 support is still optional, since it is the portability definition to allow patch back-ports. --- diff --git a/acinclude/ax_cxx_0x_types.m4 b/acinclude/ax_cxx_0x_types.m4 index 2657b3f79e..d08cb35958 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 e57fc0172d..2b4a34fd99 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 718a1367da..fe1ba89893 100644 --- a/src/DiskIO/IpcIo/IpcIoFile.h +++ b/src/DiskIO/IpcIo/IpcIoFile.h @@ -139,7 +139,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 5263bf2429..126815819f 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -786,7 +786,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());