diff --git a/ChangeLog b/ChangeLog index 3e9b278a2..fdffcbb5b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -28,6 +28,7 @@ 1.1.1 release + * fix piece picker bug that could result in division by zero * fix value of current_tracker when all tracker failed * deprecate lt_trackers extension * remove load_asnum_db and load_country_db from python bindings diff --git a/Jamfile b/Jamfile index 046256adb..9fdf3b396 100644 --- a/Jamfile +++ b/Jamfile @@ -555,8 +555,8 @@ lib libiconv : : iconv shared /usr/local/lib ; # openssl on linux/bsd/macos etc. lib gcrypt : : gcrypt shared /opt/local/lib /usr/local/lib : : /opt/local/include /usr/local/include ; lib z : : shared z /usr/lib ; -lib crypto : : crypto shared z /opt/local/lib /usr/local/lib : : /opt/local/include /usr/local/include ; -lib ssl : : ssl shared crypto /opt/local/lib /usr/local/lib : : /opt/local/include /usr/local/include ; +lib crypto : : crypto shared z /opt/local/lib : : /opt/local/include ; +lib ssl : : ssl shared crypto /opt/local/lib : : /opt/local/include ; lib dl : : shared dl ; # time functions used on linux require librt diff --git a/bindings/python/setup.py b/bindings/python/setup.py index deec0492e..e7dc06c9c 100644 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from distutils.core import setup, Extension -from distutils.sysconfig import get_config_var +from distutils.sysconfig import get_config_vars import os import platform import sys @@ -98,8 +98,10 @@ if '--bjam' in sys.argv: else: # Remove the '-Wstrict-prototypes' compiler option, which isn't valid for C++. - os.environ['OPT'] = ' '.join( - flag for flag in get_config_var('OPT').split() if flag != '-Wstrict-prototypes') + cfg_vars = get_config_vars() + for key, value in cfg_vars.items(): + if isinstance(value, str): + cfg_vars[key] = value.replace('-Wstrict-prototypes', '') source_list = os.listdir(os.path.join(os.path.dirname(__file__), "src")) source_list = [os.path.abspath(os.path.join(os.path.dirname(__file__), "src", s)) for s in source_list if s.endswith(".cpp")] diff --git a/bindings/python/src/entry.cpp b/bindings/python/src/entry.cpp index bced76d65..5019920f1 100644 --- a/bindings/python/src/entry.cpp +++ b/bindings/python/src/entry.cpp @@ -45,6 +45,15 @@ struct entry_to_python return convert(e.list()); case entry::dictionary_t: return convert(e.dict()); + case entry::preformatted_t: + { + std::vector const& pre = e.preformatted(); + list l; + for (std::vector::const_iterator i = pre.begin() + , end(pre.end()); i != end; ++i) + l.append(*i); + return tuple(l); + } default: return object(); } @@ -136,6 +145,19 @@ struct entry_from_python { return entry(extract(e)()); } + else if (extract(e).check()) + { + tuple t = extract(e); + + std::size_t const length = extract(t.attr("__len__")()); + std::vector preformatted(length); + for (std::size_t i = 0; i < length; ++i) + { + preformatted[i] = extract(t[i]); + } + + return entry(preformatted); + } return entry(); } diff --git a/bindings/python/test.py b/bindings/python/test.py index f3427327f..87a080018 100644 --- a/bindings/python/test.py +++ b/bindings/python/test.py @@ -8,6 +8,20 @@ import os import shutil import binascii + +class test_create_torrent(unittest.TestCase): + + def test_from_torrent_info(self): + ti = lt.torrent_info('unordered.torrent') + ct = lt.create_torrent(ti) + entry = ct.generate() + content = lt.bencode(entry).strip() + with open('unordered.torrent', 'r') as f: + file_content = f.read().strip() + print file_content + print content + self.assertEqual(content, file_content) + class test_torrent_handle(unittest.TestCase): def test_torrent_handle(self): @@ -191,5 +205,6 @@ if __name__ == '__main__': print(lt.__version__) shutil.copy(os.path.join('..', '..', 'test', 'test_torrents', 'url_seed_multi.torrent'), '.') shutil.copy(os.path.join('..', '..', 'test', 'test_torrents', 'base.torrent'), '.') + shutil.copy(os.path.join('..', '..', 'test', 'test_torrents', 'unordered.torrent'), '.') unittest.main() diff --git a/m4/ax_boost_base.m4 b/m4/ax_boost_base.m4 index ac9ee75ec..d35d466de 100644 --- a/m4/ax_boost_base.m4 +++ b/m4/ax_boost_base.m4 @@ -33,7 +33,7 @@ # and this notice are preserved. This file is offered as-is, without any # warranty. -#serial 22 +#serial 26 AC_DEFUN([AX_BOOST_BASE], [ @@ -92,8 +92,11 @@ if test "x$want_boost" = "xyes"; then libsubdirs="lib" ax_arch=`uname -m` case $ax_arch in - x86_64|ppc64|s390x|sparc64|aarch64) - libsubdirs="lib64 lib lib64" + x86_64) + libsubdirs="lib64 libx32 lib lib64" + ;; + ppc64|s390x|sparc64|aarch64|ppc64le) + libsubdirs="lib64 lib lib64 ppc64le" ;; esac @@ -103,6 +106,12 @@ if test "x$want_boost" = "xyes"; then AC_REQUIRE([AC_CANONICAL_HOST]) libsubdirs="lib/${host_cpu}-${host_os} $libsubdirs" + case ${host_cpu} in + i?86) + libsubdirs="lib/i386-${host_os} $libsubdirs" + ;; + esac + dnl first we check the system location for boost libraries dnl this location ist chosen if boost libraries are installed with the --layout=system option dnl or if you install boost with RPM @@ -164,6 +173,10 @@ if test "x$want_boost" = "xyes"; then dnl if we found no boost with system layout we search for boost libraries dnl built and installed without the --layout=system option or for a staged(not installed) version if test "x$succeeded" != "xyes"; then + CPPFLAGS="$CPPFLAGS_SAVED" + LDFLAGS="$LDFLAGS_SAVED" + BOOST_CPPFLAGS= + BOOST_LDFLAGS= _version=0 if test "$ac_boost_path" != ""; then if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then @@ -176,6 +189,12 @@ if test "x$want_boost" = "xyes"; then VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE" done + dnl if nothing found search for layout used in Windows distributions + if test -z "$BOOST_CPPFLAGS"; then + if test -d "$ac_boost_path/boost" && test -r "$ac_boost_path/boost"; then + BOOST_CPPFLAGS="-I$ac_boost_path" + fi + fi fi else if test "$cross_compiling" != yes; then diff --git a/m4/ax_boost_python.m4 b/m4/ax_boost_python.m4 index 385af3ef5..5d21fd31e 100644 --- a/m4/ax_boost_python.m4 +++ b/m4/ax_boost_python.m4 @@ -101,12 +101,11 @@ if test "$ac_cv_boost_python" = "yes"; then fi]) BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` for ax_lib in $ax_python_lib $ax_boost_python_lib `ls $BOOSTLIBDIR/libboost_python*.so* $BOOSTLIBDIR/libboost_python*.dylib* $BOOSTLIBDIR/libboost_python*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_python.*\)\.so.*$;\1;' -e 's;^lib\(boost_python.*\)\.dylib.*$;\1;' -e 's;^lib\(boost_python.*\)\.a.*$;\1;' ` boost_python boost_python3; do - AS_VAR_PUSHDEF([ax_Lib], [ax_cv_lib_$ax_lib''_BOOST_PYTHON_MODULE])dnl + AS_VAR_PUSHDEF([ax_Lib], [ax_cv_lib_$ax_lib''_main])dnl AC_CACHE_CHECK([whether $ax_lib is the correct library], [ax_Lib], [LIBS="-l$ax_lib $ax_boost_python_save_LIBS $PYTHON_LIBS" AC_LINK_IFELSE([AC_LANG_PROGRAM([[ -#include -BOOST_PYTHON_MODULE(test) { throw "Boost::Python test."; }]], [])], + ]], [])], [AS_VAR_SET([ax_Lib], [yes])], [AS_VAR_SET([ax_Lib], [no])])]) AS_VAR_IF([ax_Lib], [yes], [BOOST_PYTHON_LIB=$ax_lib break], []) diff --git a/m4/ax_python_devel.m4 b/m4/ax_python_devel.m4 index f18ed8a01..11f1f51ac 100644 --- a/m4/ax_python_devel.m4 +++ b/m4/ax_python_devel.m4 @@ -136,7 +136,7 @@ variable to configure. See ``configure --help'' for reference. # Check if you have distutils, else fail # AC_MSG_CHECKING([for the distutils Python package]) - ac_distutils_result=`$PYTHON -c "import distutils" 2>&1` + ac_distutils_result=`$PYTHON -c "import distutils" 2>&1 | grep -v '^\[[0-9]\{1,\} refs\]'` if test -z "$ac_distutils_result"; then AC_MSG_RESULT([yes]) else diff --git a/src/disk_buffer_pool.cpp b/src/disk_buffer_pool.cpp index 032c66301..4a2674b01 100644 --- a/src/disk_buffer_pool.cpp +++ b/src/disk_buffer_pool.cpp @@ -118,8 +118,8 @@ namespace libtorrent m_cache_pool = nullptr; // attempt to make MacOS not flush this to disk, making close() // block for a long time - int ignore = ftruncate(m_cache_fd, 0); - TORRENT_UNUSED(ignore); + int const best_effort = ftruncate(m_cache_fd, 0); + TORRENT_UNUSED(best_effort); close(m_cache_fd); m_cache_fd = -1; } @@ -462,8 +462,8 @@ namespace libtorrent m_cache_pool = nullptr; // attempt to make MacOS not flush this to disk, making close() // block for a long time - int ignore = ftruncate(m_cache_fd, 0); - TORRENT_UNUSED(ignore); + int const best_effort = ftruncate(m_cache_fd, 0); + TORRENT_UNUSED(best_effort); close(m_cache_fd); m_cache_fd = -1; std::vector().swap(m_free_list); @@ -503,8 +503,8 @@ namespace libtorrent m_cache_pool = nullptr; // attempt to make MacOS not flush this to disk, making close() // block for a long time - int ignore = ftruncate(m_cache_fd, 0); - TORRENT_UNUSED(ignore); + int const best_effort2 = ftruncate(m_cache_fd, 0); + TORRENT_UNUSED(best_effort2); close(m_cache_fd); m_cache_fd = -1; return; diff --git a/src/part_file.cpp b/src/part_file.cpp index 930738052..973da165f 100644 --- a/src/part_file.cpp +++ b/src/part_file.cpp @@ -330,14 +330,14 @@ namespace libtorrent // don't hold the lock during disk I/O l.unlock(); - file::iovec_t const v = { buf.get(), size_t(block_to_copy) }; - int ret = m_file.readv(slot_offset + piece_offset, &v, 1, ec); - TORRENT_ASSERT(ec || ret == block_to_copy); - if (ec || ret != block_to_copy) return; + file::iovec_t v = { buf.get(), size_t(block_to_copy) }; + v.iov_len = m_file.readv(slot_offset + piece_offset, &v, 1, ec); + TORRENT_ASSERT(!ec); + if (ec || v.iov_len == 0) return; - ret = f.writev(file_offset, &v, 1, ec); - TORRENT_ASSERT(ec || ret == block_to_copy); - if (ec || ret != block_to_copy) return; + boost::int64_t ret = f.writev(file_offset, &v, 1, ec); + TORRENT_ASSERT(ec || ret == v.iov_len); + if (ec || ret != v.iov_len) return; // we're done with the disk I/O, grab the lock again to update // the slot map diff --git a/test/Makefile.am b/test/Makefile.am index 380f1acad..ebb256614 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -93,6 +93,7 @@ EXTRA_DIST = Jamfile \ test_torrents/string.torrent \ test_torrents/symlink1.torrent \ test_torrents/unaligned_pieces.torrent \ + test_torrents/unordered.torrent \ test_torrents/url_list.torrent \ test_torrents/url_list2.torrent \ test_torrents/url_list3.torrent \ diff --git a/test/test_torrent_info.cpp b/test/test_torrent_info.cpp index 6d1f2d973..d33481ae7 100644 --- a/test/test_torrent_info.cpp +++ b/test/test_torrent_info.cpp @@ -127,6 +127,7 @@ static test_torrent_t test_torrents[] = { "invalid_name2.torrent" }, { "invalid_name3.torrent" }, { "symlink1.torrent" }, + { "unordered.torrent" }, }; struct test_failing_torrent_t diff --git a/test/test_torrents/unordered.torrent b/test/test_torrents/unordered.torrent new file mode 100644 index 000000000..0d59f70dd --- /dev/null +++ b/test/test_torrents/unordered.torrent @@ -0,0 +1 @@ +d10:created by10:libtorrent13:creation datei1359599503e4:infod4:name4:temp6:lengthi425e12:piece lengthi16384e6:pieces20:‚ž¼Œ&¾ÇJW›}ÜA4u,·¼‘‡ee