------------------------------------------------------------ revno: 11605 revision-id: squid3@treenet.co.nz-20110802073153-1e1cxedjawe96sd4 parent: kinkie@squid-cache.org-20110802051545-0zz7ff4jupg8cavr committer: Amos Jeffries branch nick: trunk timestamp: Tue 2011-08-02 19:31:53 +1200 message: Support C++0x features where possible This tests for and enables -std=c++0x compiler support on build. Due to auto_ptr deprecation pieces of the code and a hack to work around incompatible cppunit code, are converted to use unique_ptr. When C++0x is available it also tests and uses the nullptr definition for extra type safety. ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20110802073153-1e1cxedjawe96sd4 # target_branch: http://www.squid-cache.org/bzr/squid3/trunk/ # testament_sha1: c3db27d84ab0b0623fa3e94b3f46633b8cba3d3f # timestamp: 2011-08-02 07:52:33 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # base_revision_id: kinkie@squid-cache.org-20110802051545-\ # 0zz7ff4jupg8cavr # # Begin patch === added file 'acinclude/ax_cxx_0x_types.m4' --- acinclude/ax_cxx_0x_types.m4 1970-01-01 00:00:00 +0000 +++ acinclude/ax_cxx_0x_types.m4 2011-08-02 07:31:53 +0000 @@ -0,0 +1,41 @@ +## Shamelessly copied from the DUNE sources under GPL version 2 +## +AC_DEFUN([AX_CXX_TYPE_NULLPTR],[ + AC_REQUIRE([AC_PROG_CXX]) + AC_LANG_PUSH([C++]) + AC_MSG_CHECKING([whether nullptr is supported]) + AC_TRY_COMPILE([],[char* ch = nullptr;], [ + HAVE_NULLPTR=yes + AC_MSG_RESULT(yes)], [ + HAVE_NULLPTR=no + AC_MSG_RESULT(no)]) + if test "x$HAVE_NULLPTR" = xyes; then + AC_DEFINE(HAVE_NULLPTR, 1, [Define to 1 if nullptr is supported]) + fi + AC_MSG_CHECKING([whether nullptr_t is supported]) + AC_TRY_COMPILE([#include ],[typedef nullptr_t peng;], [ + HAVE_NULLPTR_T=yes + AC_MSG_RESULT(yes)], [ + HAVE_NULLPTR_T=no + AC_MSG_RESULT(no)]) + if test "x$HAVE_NULLPTR_T" = xyes; then + AC_DEFINE(HAVE_NULLPTR_T, 1, [Define to 1 if nullptr_t is supported]) + fi + AC_LANG_POP +]) + +## Hand crafted for Squid under GPL version 2 +AC_DEFUN([AX_CXX_TYPE_UNIQUE_PTR],[ + AC_REQUIRE([AC_PROG_CXX]) + AC_LANG_PUSH([C++]) + AC_MSG_CHECKING([whether std::unique_ptr is supported]) + AC_TRY_COMPILE([#include ],[std::unique_ptr c;], [ + HAVE_UNIQUE_PTR=yes + AC_MSG_RESULT(yes)], [ + HAVE_UNIQUE_PTR=no + AC_MSG_RESULT(no)]) + if test "x$HAVE_UNIQUE_PTR" = xyes; then + AC_DEFINE(HAVE_UNIQUE_PTR, 1, [Define to 1 if std::unique_ptr is supported]) + fi + AC_LANG_POP +]) === added file 'acinclude/ax_cxx_compile_stdcxx_0x.m4' --- acinclude/ax_cxx_compile_stdcxx_0x.m4 1970-01-01 00:00:00 +0000 +++ acinclude/ax_cxx_compile_stdcxx_0x.m4 2011-08-02 07:31:53 +0000 @@ -0,0 +1,107 @@ +# ============================================================================ +# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_0x.html +# ============================================================================ +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX_0X +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the C++0x +# standard. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 7 + +AU_ALIAS([AC_CXX_COMPILE_STDCXX_0X], [AX_CXX_COMPILE_STDCXX_0X]) +AC_DEFUN([AX_CXX_COMPILE_STDCXX_0X], [ + AC_CACHE_CHECK(if g++ supports C++0x features without additional flags, + ax_cv_cxx_compile_cxx0x_native, + [AC_LANG_SAVE + AC_LANG_CPLUSPLUS + AC_TRY_COMPILE([ + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check check_type; + check_type c; + check_type&& cr = static_cast(c);],, + ax_cv_cxx_compile_cxx0x_native=yes, ax_cv_cxx_compile_cxx0x_native=no) + AC_LANG_RESTORE + ]) + + AC_CACHE_CHECK(if g++ supports C++0x features with -std=c++0x, + ax_cv_cxx_compile_cxx0x_cxx, + [AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -std=c++0x" + AC_TRY_COMPILE([ + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check check_type; + check_type c; + check_type&& cr = static_cast(c);],, + ax_cv_cxx_compile_cxx0x_cxx=yes, ax_cv_cxx_compile_cxx0x_cxx=no) + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE + ]) + + AC_CACHE_CHECK(if g++ supports C++0x features with -std=gnu++0x, + ax_cv_cxx_compile_cxx0x_gxx, + [AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -std=gnu++0x" + AC_TRY_COMPILE([ + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check check_type; + check_type c; + check_type&& cr = static_cast(c);],, + ax_cv_cxx_compile_cxx0x_gxx=yes, ax_cv_cxx_compile_cxx0x_gxx=no) + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE + ]) + + if test "$ax_cv_cxx_compile_cxx0x_native" = yes || + test "$ax_cv_cxx_compile_cxx0x_cxx" = yes || + test "$ax_cv_cxx_compile_cxx0x_gxx" = yes; then + AC_DEFINE(HAVE_STDCXX_0X,,[Define if g++ supports C++0x features. ]) + fi +]) === modified file 'compat/GnuRegex.c' --- compat/GnuRegex.c 2011-07-22 15:33:47 +0000 +++ compat/GnuRegex.c 2011-08-02 07:31:53 +0000 @@ -158,10 +158,6 @@ #define ISUPPER(c) (isascii ((unsigned char)c) && isupper ((unsigned char)c)) #define ISXDIGIT(c) (isascii ((unsigned char)c) && isxdigit ((unsigned char)c)) -#ifndef NULL -#define NULL 0 -#endif - /* We remove any previous definition of `SIGN_EXTEND_CHAR', * since ours (we hope) works properly with all combinations of * machines, compilers, `char' and `unsigned char' argument types. === modified file 'compat/Makefile.am' --- compat/Makefile.am 2011-04-06 13:58:14 +0000 +++ compat/Makefile.am 2011-08-02 07:31:53 +0000 @@ -17,6 +17,7 @@ compat.h \ compat_shared.h \ cpu.h \ + cppunit.h \ debug.cc \ debug.h \ drand48.h \ === modified file 'compat/compat.h' --- compat/compat.h 2011-04-06 13:58:14 +0000 +++ compat/compat.h 2011-08-02 07:31:53 +0000 @@ -113,4 +113,7 @@ /* some functions are unsafe to be used in Squid. */ #include "compat/unsafe.h" +/* cppunit is not quite C++0x compatible yet */ +#include "compat/cppunit.h" + #endif /* _SQUID_COMPAT_H */ === added file 'compat/cppunit.h' --- compat/cppunit.h 1970-01-01 00:00:00 +0000 +++ compat/cppunit.h 2011-08-02 07:31:53 +0000 @@ -0,0 +1,33 @@ +#ifndef SQUID_COMPAT_CPPUNIT_H +#define SQUID_COMPAT_CPPUNIT_H + +// CPPUNIT test suite uses auto_ptr which is deprecated in C++0x + +#if defined(__cplusplus) && HAVE_UNIQUE_PTR +#include + +#undef CPPUNIT_TEST_SUITE_END + +// Clone from cppunit 1.12.1 +#define CPPUNIT_TEST_SUITE_END() \ + } \ + \ + static CPPUNIT_NS::TestSuite *suite() \ + { \ + const CPPUNIT_NS::TestNamer &namer = getTestNamer__(); \ + std::unique_ptr suite( \ + new CPPUNIT_NS::TestSuite( namer.getFixtureName() )); \ + CPPUNIT_NS::ConcretTestFixtureFactory factory; \ + CPPUNIT_NS::TestSuiteBuilderContextBase context( *suite.get(), \ + namer, \ + factory ); \ + TestFixtureType::addTestsToSuite( context ); \ + return suite.release(); \ + } \ + private: /* dummy typedef so that the macro can still end with ';'*/ \ + typedef int CppUnitDummyTypedefForSemiColonEnding__ + + +#endif /* HAVE_UNIQUE_PTR */ + +#endif /* SQUID_COMPAT_CPPUNIT_H */ === modified file 'compat/types.h' --- compat/types.h 2011-07-23 08:37:52 +0000 +++ compat/types.h 2011-08-02 07:31:53 +0000 @@ -138,4 +138,12 @@ typedef long mtyp_t; #endif +#ifndef NULL +#if defined(__cplusplus) && HAVE_NULLPTR +#define NULL nullptr +#else +#define NULL 0 +#endif +#endif + #endif /* SQUID_TYPES_H */ === modified file 'configure.ac' --- configure.ac 2011-07-26 05:53:32 +0000 +++ configure.ac 2011-08-02 07:31:53 +0000 @@ -21,8 +21,11 @@ m4_include([acinclude/pam.m4]) m4_include([acinclude/pkg.m4]) m4_include([acinclude/lib-checks.m4]) +m4_include([acinclude/ax_cxx_compile_stdcxx_0x.m4]) +m4_include([acinclude/ax_cxx_0x_types.m4]) PRESET_CFLAGS="$CFLAGS" +PRESET_CXXFLAGS="$CXXFLAGS" PRESET_LDFLAGS="$LDFLAGS" dnl Set default LDFLAGS @@ -54,6 +57,12 @@ AC_USE_SYSTEM_EXTENSIONS fi +# Check for C++0x compiler support +AX_CXX_COMPILE_STDCXX_0X +if test "x$ax_cv_cxx_compile_cxx0x_cxx" = "xyes"; then + CXXFLAGS="$CXXFLAGS -std=c++0x" +fi + # test for programs AC_PROG_RANLIB AC_PROG_CPP @@ -2431,6 +2440,10 @@ AC_CHECK_SIZEOF(off_t) AC_CHECK_SIZEOF(size_t) +dnl Some C++0x types we try to use +AX_CXX_TYPE_NULLPTR +AX_CXX_TYPE_UNIQUE_PTR + dnl On Solaris 9 x86, gcc may includes a "fixed" set of old system include files dnl that is incompatible with the updated Solaris header files. dnl For this reason, we must check if pad128_t and upad128_t are defined. === modified file 'include/snmp_impl.h' --- include/snmp_impl.h 2009-01-21 03:47:47 +0000 +++ include/snmp_impl.h 2011-08-02 07:31:53 +0000 @@ -47,20 +47,6 @@ #define SID_MAX_LEN 64 -#if 0 /* defines performed globally by config.h */ - -#ifndef NULL -#define NULL 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif -#endif /* dead code. */ - #define READ 1 #define WRITE 0 === modified file 'src/StoreEntryStream.h' --- src/StoreEntryStream.h 2009-05-03 13:02:50 +0000 +++ src/StoreEntryStream.h 2011-08-02 07:31:53 +0000 @@ -70,7 +70,10 @@ return traits_type::eof(); if (aChar != traits_type::eof()) { - char chars[1] = {aChar}; + // NP: cast because GCC promotes int_type to 32-bit type + // std::basic_streambuf::int_type {aka int} + // despite the definition with 8-bit type value. + char chars[1] = {char(aChar)}; if (aChar != traits_type::eof()) theEntry->append(chars, 1); === modified file 'src/mgr/Inquirer.cc' --- src/mgr/Inquirer.cc 2011-07-15 12:52:41 +0000 +++ src/mgr/Inquirer.cc 2011-08-02 07:31:53 +0000 @@ -70,17 +70,29 @@ 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 = errorCon(ERR_INVALID_URL, HTTP_NOT_FOUND, req); +#if HAVE_UNIQUE_PTR + std::unique_ptr reply(err->BuildHttpReply()); +#else std::auto_ptr reply(err->BuildHttpReply()); +#endif replyBuf.reset(reply->pack()); errorStateFree(err); } else { +#if HAVE_UNIQUE_PTR + std::unique_ptr reply(new HttpReply); +#else std::auto_ptr reply(new HttpReply); +#endif reply->setHeaders(HTTP_OK, NULL, "text/plain", -1, squid_curtime, squid_curtime); reply->header.putStr(HDR_CONNECTION, "close"); // until we chunk response replyBuf.reset(reply->pack());