diff --git a/Makefile.am b/Makefile.am index 56259ece..18df34ab 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,4 +16,7 @@ EXTRA_DIST= \ rak/timer.h \ rak/unordered_vector.h \ scripts/checks.m4 \ - scripts/common.m4 + scripts/common.m4 \ + scripts/attributes.m4 + +ACLOCAL_AMFLAGS = -I scripts diff --git a/autogen.sh b/autogen.sh index 24f60ca4..ac61f632 100755 --- a/autogen.sh +++ b/autogen.sh @@ -6,7 +6,7 @@ echo aclocal... exit 1 } -aclocal -I . ${ACLOCAL_FLAGS} +aclocal -I . -I ./scripts ${ACLOCAL_FLAGS} echo autoheader... (autoheader --version) < /dev/null > /dev/null 2>&1 || { diff --git a/configure.ac b/configure.ac index e31d9769..1457bedc 100644 --- a/configure.ac +++ b/configure.ac @@ -1,18 +1,15 @@ -AC_INIT(rtorrent, 0.4.4, jaris@ifi.uio.no) +AC_INIT(rtorrent, 0.4.5, jaris@ifi.uio.no) AM_INIT_AUTOMAKE AM_CONFIG_HEADER(config.h) -sinclude(scripts/checks.m4) -sinclude(scripts/common.m4) - TORRENT_CHECK_CXXFLAGS() TORRENT_ENABLE_DEBUG() TORRENT_ENABLE_EXTRA_DEBUG() TORRENT_ENABLE_WERROR() AC_PROG_CXX -AC_PROG_RANLIB +AC_PROG_LIBTOOL AC_SYS_LARGEFILE @@ -33,6 +30,11 @@ PKG_CHECK_MODULES(STUFF, sigc++-2.0 libtorrent >= 0.8.0, AC_DEFINE(HAVE_CONFIG_H, 1, true if config.h was included) +CC_ATTRIBUTE_UNUSED( + AC_DEFINE([__UNUSED], [__attribute__((unused))], [Wrapper around unused attribute]), + AC_DEFINE([__UNUSED], [], [Null-wrapper if unused attribute is unsupported]) +) + AC_OUTPUT([ Makefile doc/Makefile diff --git a/rak/string_manip.h b/rak/string_manip.h index 0bcd0601..85c1f169 100644 --- a/rak/string_manip.h +++ b/rak/string_manip.h @@ -108,8 +108,8 @@ public: return *this; } - bool operator == (const split_iterator_t& itr) const { return m_pos == m_seq->end(); } - bool operator != (const split_iterator_t& itr) const { return m_pos != m_seq->end(); } + bool operator == (__UNUSED const split_iterator_t& itr) const { return m_pos == m_seq->end(); } + bool operator != (__UNUSED const split_iterator_t& itr) const { return m_pos != m_seq->end(); } private: const Sequence* m_seq; @@ -126,7 +126,7 @@ split_iterator(const Sequence& seq, typename Sequence::value_type delim) { template inline split_iterator_t -split_iterator(const Sequence& seq) { +split_iterator(__UNUSED const Sequence& seq) { return split_iterator_t(); } diff --git a/scripts/attributes.m4 b/scripts/attributes.m4 new file mode 100644 index 00000000..a153f528 --- /dev/null +++ b/scripts/attributes.m4 @@ -0,0 +1,121 @@ +# Functions to check for attributes support in compiler + +AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [ + AC_CACHE_CHECK([if compiler supports __attribute__((constructor))], + [cc_cv_attribute_constructor], + [AC_COMPILE_IFELSE([ + void ctor() __attribute__((constructor)); + void ctor() { }; + ], + [cc_cv_attribute_constructor=yes], + [cc_cv_attribute_constructor=no]) + ]) + + if test "x$cc_cv_attribute_constructor" = "xyes"; then + AC_DEFINE([SUPPORT_ATTRIBUTE_CONSTRUCTOR], 1, [Define this if the compiler supports the constructor attribute]) + $1 + else + true + $2 + fi +]) + +AC_DEFUN([CC_ATTRIBUTE_FORMAT], [ + AC_CACHE_CHECK([if compiler supports __attribute__((format(printf, n, n)))], + [cc_cv_attribute_format], + [AC_COMPILE_IFELSE([ + void __attribute__((format(printf, 1, 2))) printflike(const char *fmt, ...) { } + ], + [cc_cv_attribute_format=yes], + [cc_cv_attribute_format=no]) + ]) + + if test "x$cc_cv_attribute_format" = "xyes"; then + AC_DEFINE([SUPPORT_ATTRIBUTE_FORMAT], 1, [Define this if the compiler supports the format attribute]) + $1 + else + true + $2 + fi +]) + +AC_DEFUN([CC_ATTRIBUTE_INTERNAL], [ + AC_CACHE_CHECK([if compiler supports __attribute__((visibility("internal")))], + [cc_cv_attribute_internal], + [AC_COMPILE_IFELSE([ + void __attribute__((visibility("internal"))) internal_function() { } + ], + [cc_cv_attribute_internal=yes], + [cc_cv_attribute_internal=no]) + ]) + + if test "x$cc_cv_attribute_internal" = "xyes"; then + AC_DEFINE([SUPPORT_ATTRIBUTE_INTERNAL], 1, [Define this if the compiler supports the internal visibility attribute]) + $1 + else + true + $2 + fi +]) + +AC_DEFUN([CC_ATTRIBUTE_NONNULL], [ + AC_CACHE_CHECK([if compiler supports __attribute__((nonnull()))], + [cc_cv_attribute_nonnull], + [AC_COMPILE_IFELSE([ + void some_function(void *foo, void *bar) __attribute__((nonnull())); + void some_function(void *foo, void *bar) { } + ], + [cc_cv_attribute_nonnull=yes], + [cc_cv_attribute_nonnull=no]) + ]) + + if test "x$cc_cv_attribute_nonnull" = "xyes"; then + AC_DEFINE([SUPPORT_ATTRIBUTE_NONNULL], 1, [Define this if the compiler supports the nonnull attribute]) + $1 + else + true + $2 + fi +]) + +AC_DEFUN([CC_ATTRIBUTE_UNUSED], [ + AC_CACHE_CHECK([if compiler supports __attribute__((unused))], + [cc_cv_attribute_unused], + [AC_COMPILE_IFELSE([ + void some_function(void *foo, __attribute__((unused)) void *bar); + ], + [cc_cv_attribute_unused=yes], + [cc_cv_attribute_unused=no]) + ]) + + if test "x$cc_cv_attribute_unused" = "xyes"; then + AC_DEFINE([SUPPORT_ATTRIBUTE_UNUSED], 1, [Define this if the compiler supports the unused attribute]) + $1 + else + true + $2 + fi +]) + +AC_DEFUN([CC_FUNC_EXPECT], [ + AC_CACHE_CHECK([if compiler has __builtin_expect function], + [cc_cv_func_expect], + [AC_COMPILE_IFELSE([ + int some_function() + { + int a = 3; + return (int)__builtin_expect(a, 3); + } + ], + [cc_cv_func_expect=yes], + [cc_cv_func_expect=no]) + ]) + + if test "x$cc_cv_func_expect" = "xyes"; then + AC_DEFINE([SUPPORT__BUILTIN_EXPECT], 1, [Define this if the compiler supports __builtin_expect() function]) + $1 + else + true + $2 + fi +]) diff --git a/src/command_scheduler.h b/src/command_scheduler.h index 954297f9..be0ceea0 100644 --- a/src/command_scheduler.h +++ b/src/command_scheduler.h @@ -39,6 +39,7 @@ #include #include +#include #include class CommandSchedulerItem; diff --git a/src/core/download.cc b/src/core/download.cc index bbb53ad9..9b47b6ab 100644 --- a/src/core/download.cc +++ b/src/core/download.cc @@ -211,7 +211,7 @@ Download::priority_to_string(uint32_t p) { } void -Download::receive_chunk_failed(uint32_t idx) { +Download::receive_chunk_failed(__UNUSED uint32_t idx) { m_chunksFailed++; } diff --git a/src/display/utils.cc b/src/display/utils.cc index db0b276c..d9b64372 100644 --- a/src/display/utils.cc +++ b/src/display/utils.cc @@ -269,7 +269,7 @@ print_status_info(char* first, char* last) { } char* -print_status_extra(char* first, char* last, Control* c) { +print_status_extra(char* first, char* last, __UNUSED Control* c) { first = print_buffer(first, last, " [U %i/%i]", torrent::currently_unchoked(), torrent::max_unchoked()); diff --git a/src/main.cc b/src/main.cc index 92e49b9e..a5f24516 100644 --- a/src/main.cc +++ b/src/main.cc @@ -78,7 +78,7 @@ void do_panic(int signum); void print_help(); int -parse_options(Control* c, utils::VariableMap* optionHandler, int argc, char** argv) { +parse_options(__UNUSED Control* c, utils::VariableMap* optionHandler, int argc, char** argv) { try { OptionParser optionParser; diff --git a/src/option_handler_rules.cc b/src/option_handler_rules.cc index e0abf598..40e7f827 100644 --- a/src/option_handler_rules.cc +++ b/src/option_handler_rules.cc @@ -71,12 +71,12 @@ apply_working_directory(const std::string& path) { } void -apply_hash_read_ahead(Control* m, int arg) { +apply_hash_read_ahead(__UNUSED Control* m, int arg) { torrent::set_hash_read_ahead(arg << 20); } void -apply_hash_interval(Control* m, int arg) { +apply_hash_interval(__UNUSED Control* m, int arg) { torrent::set_hash_interval(arg * 1000); } @@ -107,7 +107,7 @@ apply_load_start(Control* m, const std::string& arg) { } void -apply_stop_untied(Control* m, const std::string& arg) { +apply_stop_untied(Control* m, __UNUSED const std::string& arg) { core::Manager::DListItr itr = m->core()->download_list().begin(); while ((itr = std::find_if(itr, m->core()->download_list().end(), @@ -126,7 +126,7 @@ apply_stop_untied(Control* m, const std::string& arg) { } void -apply_remove_untied(Control* m, const std::string& arg) { +apply_remove_untied(Control* m, __UNUSED const std::string& arg) { core::Manager::DListItr itr = m->core()->download_list().begin(); while ((itr = std::find_if(itr, m->core()->download_list().end(), @@ -147,7 +147,7 @@ apply_remove_untied(Control* m, const std::string& arg) { } void -apply_encoding_list(Control* m, const std::string& arg) { +apply_encoding_list(__UNUSED Control* m, const std::string& arg) { torrent::encoding_list()->push_back(arg); }