mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-14 14:12:31 +00:00
* Renamed 'check_hash' and added a redirect.
* Added proper torrent::Object stack type in rpc::Command. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1160 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+15
-9
@@ -131,9 +131,15 @@ public:
|
||||
static const unsigned int max_arguments = 10;
|
||||
|
||||
struct stack_type {
|
||||
torrent::Object* begin() { return reinterpret_cast<torrent::Object*>(buffer); }
|
||||
torrent::Object* end() { return reinterpret_cast<torrent::Object*>(buffer) + max_arguments; }
|
||||
torrent::Object* begin() { return reinterpret_cast<torrent::Object*>(buffer); }
|
||||
torrent::Object* end() { return reinterpret_cast<torrent::Object*>(buffer) + max_arguments; }
|
||||
|
||||
const torrent::Object* begin() const { return reinterpret_cast<const torrent::Object*>(buffer); }
|
||||
const torrent::Object* end() const { return reinterpret_cast<const torrent::Object*>(buffer) + max_arguments; }
|
||||
|
||||
torrent::Object& operator [] (unsigned int idx) { return *(begin() + idx); }
|
||||
const torrent::Object& operator [] (unsigned int idx) const { return *(begin() + idx); }
|
||||
|
||||
static stack_type* from_data(char* data) { return reinterpret_cast<stack_type*>(data); }
|
||||
|
||||
char buffer[sizeof(torrent::Object) * max_arguments];
|
||||
@@ -142,16 +148,16 @@ public:
|
||||
Command() {}
|
||||
virtual ~Command() {}
|
||||
|
||||
static torrent::Object* argument(unsigned int index) { return m_arguments.begin() + index; }
|
||||
static torrent::Object& argument_ref(unsigned int index) { return *(m_arguments.begin() + index); }
|
||||
static torrent::Object* argument(unsigned int index) { return current_stack.begin() + index; }
|
||||
static torrent::Object& argument_ref(unsigned int index) { return *(current_stack.begin() + index); }
|
||||
|
||||
static stack_type m_arguments;
|
||||
static stack_type current_stack;
|
||||
|
||||
static torrent::Object* stack_begin() { return m_arguments.begin(); }
|
||||
static torrent::Object* stack_end() { return m_arguments.end(); }
|
||||
static torrent::Object* stack_begin() { return current_stack.begin(); }
|
||||
static torrent::Object* stack_end() { return current_stack.end(); }
|
||||
|
||||
static torrent::Object* push_stack(const torrent::Object::list_type& args, torrent::Object* tmp_stack);
|
||||
static void pop_stack(torrent::Object* first_stack, torrent::Object* last_stack);
|
||||
static torrent::Object* push_stack(const torrent::Object::list_type& args, stack_type* stack);
|
||||
static void pop_stack(stack_type* stack, torrent::Object* last_stack);
|
||||
|
||||
protected:
|
||||
Command(const Command&);
|
||||
|
||||
+10
-7
@@ -77,23 +77,26 @@ get_target_cast<torrent::File*>(target_type target, int type) {
|
||||
}
|
||||
|
||||
inline torrent::Object*
|
||||
Command::push_stack(const torrent::Object::list_type& args, torrent::Object* tmp_stack) {
|
||||
Command::push_stack(const torrent::Object::list_type& args, stack_type* stack) {
|
||||
unsigned int idx = 0;
|
||||
|
||||
for (torrent::Object::list_const_iterator itr = args.begin(), last = args.end();
|
||||
itr != last && idx < Command::max_arguments; itr++, idx++) {
|
||||
new (tmp_stack + idx) torrent::Object(*itr);
|
||||
tmp_stack[idx].swap(*Command::argument(idx));
|
||||
new (&(*stack)[idx]) torrent::Object(*itr);
|
||||
(*stack)[idx].swap(*Command::argument(idx));
|
||||
}
|
||||
|
||||
return tmp_stack + idx;
|
||||
return stack->begin() + idx;
|
||||
}
|
||||
|
||||
inline void
|
||||
Command::pop_stack(torrent::Object* first_stack, torrent::Object* last_stack) {
|
||||
while (last_stack-- != first_stack) {
|
||||
last_stack->swap(*Command::argument(std::distance(first_stack, last_stack)));
|
||||
Command::pop_stack(stack_type* stack, torrent::Object* last_stack) {
|
||||
while (last_stack-- != stack->begin()) {
|
||||
last_stack->swap(*Command::argument(std::distance(stack->begin(), last_stack)));
|
||||
last_stack->~Object();
|
||||
|
||||
// To ensure we catch errors:
|
||||
std::memset(last_stack, 0xAA, sizeof(torrent::Object));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
|
||||
namespace rpc {
|
||||
|
||||
Command::stack_type Command::m_arguments;
|
||||
Command::stack_type Command::current_stack;
|
||||
|
||||
CommandMap::~CommandMap() {
|
||||
std::vector<const char*> keys;
|
||||
|
||||
Reference in New Issue
Block a user