clean up usage of printf attribute (encapsulate it in a macro)

This commit is contained in:
Arvid Norberg 2015-05-10 05:11:51 +00:00
parent b60934288b
commit 1357fd5265
15 changed files with 26 additions and 82 deletions

View File

@ -69,11 +69,7 @@ extern char const* libtorrent_assert_log;
#include <sstream>
#endif
TORRENT_EXPORT void assert_print(char const* fmt, ...)
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 1, 2)))
#endif
;
TORRENT_EXPORT void assert_print(char const* fmt, ...) TORRENT_FORMAT(1,2);
#if TORRENT_USE_ASSERTS || defined TORRENT_ASIO_DEBUGGING
TORRENT_NO_RETURN

View File

@ -1124,16 +1124,8 @@ namespace libtorrent
boost::uint16_t m_tick_residual;
#ifndef TORRENT_DISABLE_LOGGING
virtual void session_log(char const* fmt, ...) const
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 2, 3)))
#endif
;
virtual void session_vlog(char const* fmt, va_list& va) const
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 2, 0)))
#endif
;
virtual void session_log(char const* fmt, ...) const TORRENT_FORMAT(2,3);
virtual void session_vlog(char const* fmt, va_list& va) const TORRENT_FORMAT(2,0);
// this list of tracker loggers serves as tracker_callbacks when
// shutting down. This list is just here to keep them alive during
@ -1216,11 +1208,7 @@ namespace libtorrent
void tracker_request_error(tracker_request const& r
, int response_code, error_code const& ec, const std::string& str
, int retry_interval);
void debug_log(const char* fmt, ...) const
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 2, 3)))
#endif
;
void debug_log(const char* fmt, ...) const TORRENT_FORMAT(2,3);
session_interface& m_ses;
private:
// explicitly disallow assignment, to silence msvc warning

View File

@ -111,16 +111,8 @@ namespace libtorrent { namespace aux
struct session_logger
{
#ifndef TORRENT_DISABLE_LOGGING
virtual void session_log(char const* fmt, ...) const
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 2, 3)))
#endif
= 0;
virtual void session_vlog(char const* fmt, va_list& va) const
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 2, 0)))
#endif
= 0;
virtual void session_log(char const* fmt, ...) const TORRENT_FORMAT(2,3) = 0;
virtual void session_vlog(char const* fmt, va_list& va) const = 0;
#endif
#if TORRENT_USE_ASSERTS

View File

@ -431,6 +431,12 @@ int snprintf(char* buf, int len, char const* fmt, ...)
#define TORRENT_ICONV_ARG (char**)
#endif
#if defined __GNUC__ || defined __clang__
#define TORRENT_FORMAT(fmt, ellipsis) __attribute__((format(printf, fmt, ellipsis)))
#else
#define TORRENT_FORMAT(fmt, ellipsis)
#endif
#ifndef TORRENT_USE_INTERLOCKED_ATOMIC
#define TORRENT_USE_INTERLOCKED_ATOMIC 0
#endif

View File

@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef DHT_OBSERVER_HPP
#define DHT_OBSERVER_HPP
#include "libtorrent/config.hpp"
#include "libtorrent/address.hpp"
#include "libtorrent/kademlia/msg.hpp"
@ -49,12 +50,7 @@ namespace libtorrent { namespace dht
traversal
};
// TODO: 3 instead of these format attributes, make a macro for it
virtual void log(dht_module_t m, char const* fmt, ...)
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 3, 4)))
#endif
= 0;
virtual void log(dht_module_t m, char const* fmt, ...) TORRENT_FORMAT(3,4) = 0;
protected:
~dht_logger() {}

View File

@ -95,11 +95,7 @@ private:
#endif
#ifndef TORRENT_DISABLE_LOGGING
log_callback_t m_log_cb;
void debug_log(char const* fmt, ...) const
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 2, 3)))
#endif
;
void debug_log(char const* fmt, ...) const TORRENT_FORMAT(2,3);
#endif
// used to resend udp packets in case

View File

@ -548,11 +548,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_LOGGING
void peer_log(peer_log_alert::direction_t direction
, char const* event, char const* fmt = "", ...) const
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 4, 5)))
#endif
;
, char const* event, char const* fmt = "", ...) const TORRENT_FORMAT(4,5);
#endif
#ifndef TORRENT_DISABLE_LOGGING

View File

@ -64,11 +64,7 @@ namespace libtorrent
virtual void get_peer_info(peer_info& p) const = 0;
#ifndef TORRENT_DISABLE_LOGGING
virtual void peer_log(peer_log_alert::direction_t direction
, char const* event, char const* fmt = "", ...) const
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 4, 5)))
#endif
= 0;
, char const* event, char const* fmt = "", ...) const TORRENT_FORMAT(4,5) = 0;
#endif
protected:
~peer_connection_interface() {}

View File

@ -1024,11 +1024,7 @@ namespace libtorrent
// LOGGING
#ifndef TORRENT_DISABLE_LOGGING
virtual void debug_log(const char* fmt, ...) const TORRENT_OVERRIDE
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 2, 3)))
#endif
;
virtual void debug_log(const char* fmt, ...) const TORRENT_OVERRIDE TORRENT_FORMAT(2,3);
void log_to_all_peers(char const* message);
time_point m_dht_start_time;

View File

@ -229,11 +229,7 @@ namespace libtorrent
, int retry_interval) = 0;
#ifndef TORRENT_DISABLE_LOGGING
virtual void debug_log(const char* fmt, ...) const
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 2, 3)))
#endif
= 0;
virtual void debug_log(const char* fmt, ...) const TORRENT_FORMAT(2,3) = 0;
#endif
};

View File

@ -221,9 +221,7 @@ char const* libtorrent_assert_log = "asserts.log";
boost::atomic<int> assert_counter(0);
#endif
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 1, 2)))
#endif
TORRENT_FORMAT(1,2)
TORRENT_EXPORT void assert_print(char const* fmt, ...)
{
#ifdef TORRENT_PRODUCTION_ASSERTS
@ -299,9 +297,7 @@ TORRENT_NO_RETURN TORRENT_EXPORT void assert_fail(char const* expr, int line
#else
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 1, 2)))
#endif
TORRENT_FORMAT(1,2)
TORRENT_EXPORT void assert_print(char const*, ...) {}
TORRENT_EXPORT void assert_fail(char const*, int, char const*
, char const*, char const*, int) {}

View File

@ -101,9 +101,7 @@ lsd::lsd(io_service& ios, peer_callback_t const& cb
}
#ifndef TORRENT_DISABLE_LOGGING
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 2, 3)))
#endif
TORRENT_FORMAT(2,3)
void lsd::debug_log(char const* fmt, ...) const
{
va_list v;

View File

@ -495,9 +495,7 @@ namespace libtorrent
}
#ifndef TORRENT_DISABLE_LOGGING
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 4, 5)))
#endif
TORRENT_FORMAT(4,5)
void peer_connection::peer_log(peer_log_alert::direction_t direction
, char const* event, char const* fmt, ...) const
{

View File

@ -4276,9 +4276,7 @@ retry:
}
#ifndef TORRENT_DISABLE_LOGGING
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 2, 3)))
#endif
TORRENT_FORMAT(2,3)
void session_impl::session_log(char const* fmt, ...) const
{
if (!m_alerts.should_post<log_alert>()) return;
@ -4289,9 +4287,7 @@ retry:
va_end(v);
}
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 2, 0)))
#endif
TORRENT_FORMAT(2, 0)
void session_impl::session_vlog(char const* fmt, va_list& v) const
{
if (!m_alerts.should_post<log_alert>()) return;

View File

@ -11659,9 +11659,7 @@ namespace libtorrent
}
#ifndef TORRENT_DISABLE_LOGGING
#if defined __GNUC__ || defined __clang__
__attribute__((format(printf, 2, 3)))
#endif
TORRENT_FORMAT(2,3)
void torrent::debug_log(char const* fmt, ...) const
{
if (!alerts().should_post<torrent_log_alert>()) return;