forked from premiere/premiere-libtorrent
make the assert macro also be able to print a value
This commit is contained in:
parent
a1567458ca
commit
c341f15f71
|
@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#if (!defined TORRENT_DEBUG && !TORRENT_PRODUCTION_ASSERTS) || TORRENT_NO_ASSERTS
|
#if (!defined TORRENT_DEBUG && !TORRENT_PRODUCTION_ASSERTS) || TORRENT_NO_ASSERTS
|
||||||
#define TORRENT_ASSERT(a) do {} while(false)
|
#define TORRENT_ASSERT(a) do {} while(false)
|
||||||
|
#define TORRENT_ASSERT_VAL(a, b) do {} while(false)
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#if TORRENT_PRODUCTION_ASSERTS
|
#if TORRENT_PRODUCTION_ASSERTS
|
||||||
|
@ -50,12 +51,14 @@ std::string demangle(char const* name);
|
||||||
|
|
||||||
#if (defined __linux__ || defined __MACH__) && defined __GNUC__
|
#if (defined __linux__ || defined __MACH__) && defined __GNUC__
|
||||||
|
|
||||||
TORRENT_EXPORT void assert_fail(const char* expr, int line, char const* file, char const* function);
|
TORRENT_EXPORT void assert_fail(const char* expr, int line, char const* file, char const* function, char const* val);
|
||||||
#define TORRENT_ASSERT(x) do { if (x) {} else assert_fail(#x, __LINE__, __FILE__, __PRETTY_FUNCTION__); } while (false)
|
#define TORRENT_ASSERT(x) do { if (x) {} else assert_fail(#x, __LINE__, __FILE__, __PRETTY_FUNCTION__, 0); } while (false)
|
||||||
|
#define TORRENT_ASSERT_VAL(x, y) do { if (x) {} else { std::stringstream __s__; __s__ << #y ": " << y; assert_fail(#x, __LINE__, __FILE__, __PRETTY_FUNCTION__, __s__.str().c_str()); } } while (false)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#define TORRENT_ASSERT(x) assert(x)
|
#define TORRENT_ASSERT(x) assert(x)
|
||||||
|
#define TORRENT_ASSERT_VAL(x, y) assert(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -121,7 +121,7 @@ void print_backtrace(FILE* out, char const* label) {}
|
||||||
char const* libtorrent_assert_log = "asserts.log";
|
char const* libtorrent_assert_log = "asserts.log";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void assert_fail(char const* expr, int line, char const* file, char const* function)
|
void assert_fail(char const* expr, int line, char const* file, char const* function, char const* value)
|
||||||
{
|
{
|
||||||
|
|
||||||
#if TORRENT_PRODUCTION_ASSERTS
|
#if TORRENT_PRODUCTION_ASSERTS
|
||||||
|
@ -139,7 +139,10 @@ void assert_fail(char const* expr, int line, char const* file, char const* funct
|
||||||
"file: '%s'\n"
|
"file: '%s'\n"
|
||||||
"line: %d\n"
|
"line: %d\n"
|
||||||
"function: %s\n"
|
"function: %s\n"
|
||||||
"expression: %s\n", LIBTORRENT_REVISION, file, line, function, expr);
|
"expression: %s\n"
|
||||||
|
"%s%s"
|
||||||
|
, LIBTORRENT_REVISION, file, line, function, expr
|
||||||
|
, value ? value : "", value ? "\n" : "");
|
||||||
|
|
||||||
print_backtrace(out, "stack:");
|
print_backtrace(out, "stack:");
|
||||||
|
|
||||||
|
|
|
@ -432,7 +432,7 @@ namespace aux {
|
||||||
char const* key = m[i].name;
|
char const* key = m[i].name;
|
||||||
void const* src = ((char*)s) + m[i].offset;
|
void const* src = ((char*)s) + m[i].offset;
|
||||||
entry& val = e[key];
|
entry& val = e[key];
|
||||||
TORRENT_ASSERT(val.type() == entry::undefined_t);
|
TORRENT_ASSERT_VAL(val.type() == entry::undefined_t, val.type());
|
||||||
switch (m[i].type)
|
switch (m[i].type)
|
||||||
{
|
{
|
||||||
case std_string:
|
case std_string:
|
||||||
|
@ -537,10 +537,10 @@ namespace aux {
|
||||||
m_next_lsd_torrent = m_torrents.begin();
|
m_next_lsd_torrent = m_torrents.begin();
|
||||||
m_next_connect_torrent = m_torrents.begin();
|
m_next_connect_torrent = m_torrents.begin();
|
||||||
|
|
||||||
TORRENT_ASSERT(listen_interface);
|
TORRENT_ASSERT_VAL(listen_interface, listen_interface);
|
||||||
error_code ec;
|
error_code ec;
|
||||||
m_listen_interface = tcp::endpoint(address::from_string(listen_interface, ec), listen_port_range.first);
|
m_listen_interface = tcp::endpoint(address::from_string(listen_interface, ec), listen_port_range.first);
|
||||||
TORRENT_ASSERT(!ec);
|
TORRENT_ASSERT_VAL(!ec, ec);
|
||||||
|
|
||||||
m_tcp_mapping[0] = -1;
|
m_tcp_mapping[0] = -1;
|
||||||
m_tcp_mapping[1] = -1;
|
m_tcp_mapping[1] = -1;
|
||||||
|
@ -740,7 +740,7 @@ namespace aux {
|
||||||
|
|
||||||
m_key = rand() + (rand() << 15) + (rand() << 30);
|
m_key = rand() + (rand() << 15) + (rand() << 30);
|
||||||
std::string print = cl_fprint.to_string();
|
std::string print = cl_fprint.to_string();
|
||||||
TORRENT_ASSERT(print.length() <= 20);
|
TORRENT_ASSERT_VAL(print.length() <= 20, print.length());
|
||||||
|
|
||||||
// the client's fingerprint
|
// the client's fingerprint
|
||||||
std::copy(
|
std::copy(
|
||||||
|
@ -1004,7 +1004,7 @@ namespace aux {
|
||||||
void session_impl::add_extension(
|
void session_impl::add_extension(
|
||||||
boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> ext)
|
boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> ext)
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(ext);
|
TORRENT_ASSERT_VAL(ext, ext);
|
||||||
|
|
||||||
typedef boost::shared_ptr<torrent_plugin>(*function_t)(torrent*, void*);
|
typedef boost::shared_ptr<torrent_plugin>(*function_t)(torrent*, void*);
|
||||||
function_t const* f = ext.target<function_t>();
|
function_t const* f = ext.target<function_t>();
|
||||||
|
@ -1126,7 +1126,7 @@ namespace aux {
|
||||||
int conn = m_connections.size();
|
int conn = m_connections.size();
|
||||||
#endif
|
#endif
|
||||||
(*m_connections.begin())->disconnect(errors::stopping_torrent);
|
(*m_connections.begin())->disconnect(errors::stopping_torrent);
|
||||||
TORRENT_ASSERT(conn == int(m_connections.size()) + 1);
|
TORRENT_ASSERT_VAL(conn == int(m_connections.size()) + 1, conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
||||||
|
@ -1191,10 +1191,10 @@ namespace aux {
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
TORRENT_ASSERT(s.file_pool_size > 0);
|
TORRENT_ASSERT_VAL(s.file_pool_size > 0, s.file_pool_size);
|
||||||
|
|
||||||
// less than 5 seconds unchoke interval is insane
|
// less than 5 seconds unchoke interval is insane
|
||||||
TORRENT_ASSERT(s.unchoke_interval >= 5);
|
TORRENT_ASSERT_VAL(s.unchoke_interval >= 5, s.unchoke_interval);
|
||||||
|
|
||||||
// if disk io thread settings were changed
|
// if disk io thread settings were changed
|
||||||
// post a notification to that thread
|
// post a notification to that thread
|
||||||
|
@ -1396,7 +1396,7 @@ namespace aux {
|
||||||
(*m_logger) << msg << "\n";
|
(*m_logger) << msg << "\n";
|
||||||
#endif
|
#endif
|
||||||
ec = error_code();
|
ec = error_code();
|
||||||
TORRENT_ASSERT(!ec);
|
TORRENT_ASSERT_VAL(!ec, ec);
|
||||||
--retries;
|
--retries;
|
||||||
ep.port(ep.port() + 1);
|
ep.port(ep.port() + 1);
|
||||||
s.sock->bind(ep, ec);
|
s.sock->bind(ep, ec);
|
||||||
|
@ -1591,7 +1591,7 @@ namespace aux {
|
||||||
m_socks_listen_socket = boost::shared_ptr<socket_type>(new socket_type(m_io_service));
|
m_socks_listen_socket = boost::shared_ptr<socket_type>(new socket_type(m_io_service));
|
||||||
bool ret = instantiate_connection(m_io_service, m_proxy
|
bool ret = instantiate_connection(m_io_service, m_proxy
|
||||||
, *m_socks_listen_socket);
|
, *m_socks_listen_socket);
|
||||||
TORRENT_ASSERT(ret);
|
TORRENT_ASSERT_VAL(ret, ret);
|
||||||
|
|
||||||
socks5_stream& s = *m_socks_listen_socket->get<socks5_stream>();
|
socks5_stream& s = *m_socks_listen_socket->get<socks5_stream>();
|
||||||
s.set_command(2); // 2 means BIND (as opposed to CONNECT)
|
s.set_command(2); // 2 means BIND (as opposed to CONNECT)
|
||||||
|
@ -1616,7 +1616,7 @@ namespace aux {
|
||||||
m_i2p_listen_socket = boost::shared_ptr<socket_type>(new socket_type(m_io_service));
|
m_i2p_listen_socket = boost::shared_ptr<socket_type>(new socket_type(m_io_service));
|
||||||
bool ret = instantiate_connection(m_io_service, m_i2p_conn.proxy()
|
bool ret = instantiate_connection(m_io_service, m_i2p_conn.proxy()
|
||||||
, *m_i2p_listen_socket);
|
, *m_i2p_listen_socket);
|
||||||
TORRENT_ASSERT(ret);
|
TORRENT_ASSERT_VAL(ret, ret);
|
||||||
|
|
||||||
i2p_stream& s = *m_i2p_listen_socket->get<i2p_stream>();
|
i2p_stream& s = *m_i2p_listen_socket->get<i2p_stream>();
|
||||||
s.set_command(i2p_stream::cmd_accept);
|
s.set_command(i2p_stream::cmd_accept);
|
||||||
|
|
Loading…
Reference in New Issue