merged RC_1_1 into master

This commit is contained in:
arvidn 2018-11-04 16:17:30 +01:00
commit a0fa0b14bb
9 changed files with 102 additions and 41 deletions

View File

@ -12,8 +12,8 @@ BOOST_ROOT = [ modules.peek : BOOST_ROOT ] ;
# this is used to make bjam use the same version of python which is executing setup.py
LIBTORRENT_PYTHON_INTERPRETER = [ modules.peek : LIBTORRENT_PYTHON_INTERPRETER ] ;
feature visibility : default hidden : composite propagated ;
feature.compose <visibility>hidden : <cflags>-fvisibility=hidden <cxxflags>-fvisibility-inlines-hidden ;
feature lt-visibility : default hidden : composite propagated ;
feature.compose <lt-visibility>hidden : <cflags>-fvisibility=hidden <cxxflags>-fvisibility-inlines-hidden ;
feature libtorrent-link : shared static : composite propagated ;
feature libtorrent-python-pic : off on : composite propagated link-incompatible ;
@ -101,7 +101,7 @@ rule libtorrent_linking ( properties * )
|| <toolset>clang in $(properties)
|| <toolset>clang-darwin in $(properties)
{
result += <visibility>hidden ;
result += <lt-visibility>hidden ;
if ( <toolset>gcc in $(properties) )
{

View File

@ -124,13 +124,58 @@ namespace {
};
}
struct category_holder
{
category_holder(boost::system::error_category const& cat) : m_cat(&cat) {}
char const* name() const { return m_cat->name(); }
std::string message(int const v) const { return m_cat->message(v); }
friend bool operator==(category_holder const lhs, category_holder const rhs)
{ return *lhs.m_cat == *rhs.m_cat; }
friend bool operator!=(category_holder const lhs, category_holder const rhs)
{ return *lhs.m_cat != *rhs.m_cat; }
friend bool operator<(category_holder const lhs, category_holder const rhs)
{ return *lhs.m_cat < *rhs.m_cat; }
boost::system::error_category const& ref() const { return *m_cat; }
operator boost::system::error_category const&() const { return *m_cat; }
private:
boost::system::error_category const* m_cat;
};
void error_code_assign(boost::system::error_code& self, int const v, category_holder const cat)
{
self.assign(v, cat.ref());
}
category_holder error_code_category(boost::system::error_code const& self)
{
return category_holder(self.category());
}
#define WRAP_CAT(name) \
category_holder wrap_ ##name## _category() { return category_holder(name## _category()); }
WRAP_CAT(libtorrent)
WRAP_CAT(upnp)
WRAP_CAT(http)
WRAP_CAT(socks)
WRAP_CAT(bdecode)
#if TORRENT_USE_I2P
WRAP_CAT(i2p)
#endif
WRAP_CAT(generic)
WRAP_CAT(system)
#undef WRAP_CAT
void bind_error_code()
{
using boost::noncopyable;
class_<boost::system::error_category, noncopyable>("error_category", no_init)
.def("name", &error_category::name)
.def("message", &error_category::message)
class_<category_holder>("error_category", no_init)
.def("name", &category_holder::name)
.def("message", &category_holder::message)
.def(self == self)
.def(self < self)
.def(self != self)
@ -138,39 +183,37 @@ void bind_error_code()
class_<error_code>("error_code")
.def(init<>())
.def("message", &error_code::message)
.def(init<int, category_holder>())
.def("message", static_cast<std::string (error_code::*)() const>(&error_code::message))
.def("value", &error_code::value)
.def("clear", &error_code::clear)
.def("category", &error_code::category
, return_value_policy<reference_existing_object>())
.def("assign", &error_code::assign)
.def("category", &error_code_category)
.def("assign", &error_code_assign)
.def_pickle(ec_pickle_suite())
;
using return_existing = return_value_policy<reference_existing_object>;
def("libtorrent_category", &libtorrent_category, return_existing());
def("upnp_category", &upnp_category, return_existing());
def("http_category", &http_category, return_existing());
def("socks_category", &socks_category, return_existing());
def("bdecode_category", &bdecode_category, return_existing());
def("libtorrent_category", &wrap_libtorrent_category);
def("upnp_category", &wrap_upnp_category);
def("http_category", &wrap_http_category);
def("socks_category", &wrap_socks_category);
def("bdecode_category", &wrap_bdecode_category);
#if TORRENT_USE_I2P
def("i2p_category", &i2p_category, return_existing());
def("i2p_category", &wrap_i2p_category);
#endif
#if TORRENT_ABI_VERSION == 1
def("get_libtorrent_category", &libtorrent_category, return_existing());
def("get_upnp_category", &upnp_category, return_existing());
def("get_http_category", &http_category, return_existing());
def("get_socks_category", &socks_category, return_existing());
def("get_bdecode_category", &bdecode_category, return_existing());
def("get_libtorrent_category", &wrap_libtorrent_category);
def("get_upnp_category", &wrap_upnp_category);
def("get_http_category", &wrap_http_category);
def("get_socks_category", &wrap_socks_category);
def("get_bdecode_category", &wrap_bdecode_category);
#if TORRENT_USE_I2P
def("get_i2p_category", &i2p_category, return_existing());
def("get_i2p_category", &wrap_i2p_category);
#endif
#endif // TORRENT_ABI_VERSION
def("generic_category", &boost::system::generic_category, return_existing());
def("generic_category", &wrap_generic_category);
def("system_category", &boost::system::system_category, return_existing());
def("system_category", &wrap_system_category);
}

View File

@ -695,6 +695,23 @@ class test_operation_t(unittest.TestCase):
self.assertEqual(lt.operation_name(lt.operation_t.hostname_lookup), "hostname_lookup")
class test_error_code(unittest.TestCase):
def test_error_code(self):
a = lt.error_code()
a = lt.error_code(10, lt.libtorrent_category())
self.assertEqual(a.category().name(), 'libtorrent')
self.assertEqual(lt.libtorrent_category().name(), 'libtorrent')
self.assertEqual(lt.upnp_category().name(), 'upnp')
self.assertEqual(lt.http_category().name(), 'http')
self.assertEqual(lt.socks_category().name(), 'socks')
self.assertEqual(lt.bdecode_category().name(), 'bdecode')
self.assertEqual(lt.generic_category().name(), 'generic')
self.assertEqual(lt.system_category().name(), 'system')
if __name__ == '__main__':
print(lt.__version__)
shutil.copy(os.path.join('..', '..', 'test', 'test_torrents',

View File

@ -167,7 +167,7 @@ namespace {
const char* bdecode_error_category::name() const BOOST_SYSTEM_NOEXCEPT
{
return "bdecode error";
return "bdecode";
}
std::string bdecode_error_category::message(int ev) const

View File

@ -283,7 +283,7 @@ namespace libtorrent {
struct TORRENT_EXPORT http_error_category : boost::system::error_category
{
const char* name() const BOOST_SYSTEM_NOEXCEPT override
{ return "http error"; }
{ return "http"; }
std::string message(int ev) const override
{
std::string ret;

View File

@ -889,15 +889,16 @@ namespace libtorrent {
else
{
ret |= piece_picker::rarest_first;
}
if (m_snubbed)
{
// snubbed peers should request
// the common pieces first, just to make
// it more likely for all snubbed peers to
// request blocks from the same piece
ret |= piece_picker::reverse;
if (m_snubbed)
{
// snubbed peers should request
// the common pieces first, just to make
// it more likely for all snubbed peers to
// request blocks from the same piece
ret |= piece_picker::reverse;
}
}
if (m_settings.get_bool(settings_pack::prioritize_partial_pieces))

View File

@ -46,7 +46,7 @@ namespace libtorrent {
struct socks_error_category : boost::system::error_category
{
const char* name() const BOOST_SYSTEM_NOEXCEPT override
{ return "socks error"; }
{ return "socks"; }
std::string message(int ev) const override
{
static char const* messages[] =

View File

@ -1195,7 +1195,7 @@ struct upnp_error_category : boost::system::error_category
{
const char* name() const BOOST_SYSTEM_NOEXCEPT override
{
return "UPnP error";
return "upnp";
}
std::string message(int ev) const override

View File

@ -429,7 +429,7 @@ TORRENT_TEST(bdecode_error)
{
error_code ec(bdecode_errors::overflow);
TEST_EQUAL(ec.message(), "integer overflow");
TEST_EQUAL(ec.category().name(), std::string("bdecode error"));
TEST_EQUAL(ec.category().name(), std::string("bdecode"));
ec.assign(5434, bdecode_category());
TEST_EQUAL(ec.message(), "Unknown error");
}