fix bug in dict_to_torrent_params in python binding

This commit is contained in:
Arvid Norberg 2011-11-08 05:53:13 +00:00
parent 2330520c51
commit e71ead49ed
2 changed files with 23 additions and 13 deletions

View File

@ -12,7 +12,8 @@ using namespace boost::python;
using namespace libtorrent; using namespace libtorrent;
extern void dict_to_add_torrent_params(dict params extern void dict_to_add_torrent_params(dict params
, add_torrent_params& p, std::vector<char>& rd); , add_torrent_params& p, std::vector<char>& rd
, std::list<std::string>& storage);
namespace { namespace {
@ -21,7 +22,8 @@ namespace {
add_torrent_params p; add_torrent_params p;
std::vector<char> resume_buf; std::vector<char> resume_buf;
dict_to_add_torrent_params(params, p, resume_buf); std::list<std::string> string_storage;
dict_to_add_torrent_params(params, p, resume_buf, string_storage);
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
return add_magnet_uri(s, uri, p); return add_magnet_uri(s, uri, p);

View File

@ -2,6 +2,8 @@
// subject to the Boost Software License, Version 1.0. (See accompanying // subject to the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <list>
#include <string>
#include <boost/python.hpp> #include <boost/python.hpp>
#include <libtorrent/session.hpp> #include <libtorrent/session.hpp>
#include <libtorrent/settings.hpp> // for bencode_map_entry #include <libtorrent/settings.hpp> // for bencode_map_entry
@ -145,7 +147,8 @@ namespace
#endif #endif
} }
void dict_to_add_torrent_params(dict params, add_torrent_params& p, std::vector<char>& rd) void dict_to_add_torrent_params(dict params, add_torrent_params& p
, std::vector<char>& rd, std::list<std::string>& string_storage)
{ {
// torrent_info objects are always held by an intrusive_ptr in the python binding // torrent_info objects are always held by an intrusive_ptr in the python binding
if (params.has_key("ti")) if (params.has_key("ti"))
@ -154,16 +157,15 @@ namespace
std::string url; std::string url;
if (params.has_key("tracker_url")) if (params.has_key("tracker_url"))
{ {
url = extract<std::string>(params["tracker_url"]); string_storage.push_back(extract<std::string>(params["tracker_url"]));
p.tracker_url = url.c_str(); p.tracker_url = string_storage.back().c_str();
} }
if (params.has_key("info_hash")) if (params.has_key("info_hash"))
p.info_hash = extract<sha1_hash>(params["info_hash"]); p.info_hash = extract<sha1_hash>(params["info_hash"]);
std::string name;
if (params.has_key("name")) if (params.has_key("name"))
{ {
name = extract<std::string>(params["name"]); string_storage.push_back(extract<std::string>(params["name"]));
p.name = name.c_str(); p.name = string_storage.back().c_str();
} }
p.save_path = extract<std::string>(params["save_path"]); p.save_path = extract<std::string>(params["save_path"]);
@ -217,7 +219,8 @@ namespace
{ {
add_torrent_params p; add_torrent_params p;
std::vector<char> resume_buf; std::vector<char> resume_buf;
dict_to_add_torrent_params(params, p, resume_buf); std::list<std::string> string_buf;
dict_to_add_torrent_params(params, p, resume_buf, string_buf);
allow_threading_guard guard; allow_threading_guard guard;
@ -229,7 +232,9 @@ namespace
#endif #endif
} }
void dict_to_feed_settings(dict params, feed_settings& feed, std::vector<char>& resume_buf) void dict_to_feed_settings(dict params, feed_settings& feed
, std::vector<char>& resume_buf
, std::list<std::string>& string_storage)
{ {
if (params.has_key("auto_download")) if (params.has_key("auto_download"))
feed.auto_download = extract<bool>(params["auto_download"]); feed.auto_download = extract<bool>(params["auto_download"]);
@ -238,7 +243,8 @@ namespace
if (params.has_key("url")) if (params.has_key("url"))
feed.url = extract<std::string>(params["url"]); feed.url = extract<std::string>(params["url"]);
if (params.has_key("add_args")) if (params.has_key("add_args"))
dict_to_add_torrent_params(dict(params["add_args"]), feed.add_args, resume_buf); dict_to_add_torrent_params(dict(params["add_args"]), feed.add_args
, resume_buf, string_storage);
} }
feed_handle add_feed(session& s, dict params) feed_handle add_feed(session& s, dict params)
@ -249,7 +255,8 @@ namespace
// this static here is a bit of a hack. It will // this static here is a bit of a hack. It will
// probably work for the most part // probably work for the most part
static std::vector<char> resume_buf; static std::vector<char> resume_buf;
dict_to_feed_settings(params, feed, resume_buf); std::list<std::string> string_storage;
dict_to_feed_settings(params, feed, resume_buf, string_storage);
return s.add_feed(feed); return s.add_feed(feed);
} }
@ -295,7 +302,8 @@ namespace
feed_settings feed; feed_settings feed;
static std::vector<char> resume_buf; static std::vector<char> resume_buf;
dict_to_feed_settings(sett, feed, resume_buf); std::list<std::string> string_storage;
dict_to_feed_settings(sett, feed, resume_buf, string_storage);
h.set_settings(feed); h.set_settings(feed);
} }