Skip to content

Commit

Permalink
tinyxml2: Resolve LTO issues
Browse files Browse the repository at this point in the history
We can't have two classes with the same name in the rpc namespace. It causes ODR and lto-type-mismatches when compiling rTorrent with LTO.

This pull request addresses the problem by renaming the `xmlrpc_error` error class to `xmlrpc_error_c` in the xmlrpc_c file.
  • Loading branch information
stickz committed Dec 24, 2024
1 parent cd9948a commit 51d2d5e
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/rpc/xmlrpc_c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@

namespace rpc {

class xmlrpc_error : public torrent::base_error {
class xmlrpc_error_c : public torrent::base_error {
public:
xmlrpc_error(xmlrpc_env* env) : m_type(env->fault_code), m_msg(env->fault_string) {}
xmlrpc_error(int type, const char* msg) : m_type(type), m_msg(msg) {}
virtual ~xmlrpc_error() throw() {}
xmlrpc_error_c(xmlrpc_env* env) : m_type(env->fault_code), m_msg(env->fault_string) {}
xmlrpc_error_c(int type, const char* msg) : m_type(type), m_msg(msg) {}
virtual ~xmlrpc_error_c() throw() {}

virtual int type() const throw() { return m_type; }
virtual const char* what() const throw() { return m_msg; }
Expand All @@ -78,7 +78,7 @@ xmlrpc_list_entry_to_object(xmlrpc_env* env, xmlrpc_value* src, int index) {
xmlrpc_array_read_item(env, src, index, &tmp);

if (env->fault_occurred)
throw xmlrpc_error(env);
throw xmlrpc_error_c(env);

torrent::Object obj = xmlrpc_to_object(env, tmp);
xmlrpc_DECREF(tmp);
Expand All @@ -92,7 +92,7 @@ xmlrpc_list_entry_to_value(xmlrpc_env* env, xmlrpc_value* src, int index) {
xmlrpc_array_read_item(env, src, index, &tmp);

if (env->fault_occurred)
throw xmlrpc_error(env);
throw xmlrpc_error_c(env);

switch (xmlrpc_value_type(tmp)) {
case XMLRPC_TYPE_INT:
Expand All @@ -115,22 +115,22 @@ xmlrpc_list_entry_to_value(xmlrpc_env* env, xmlrpc_value* src, int index) {
xmlrpc_read_string(env, tmp, &str);

if (env->fault_occurred)
throw xmlrpc_error(env);
throw xmlrpc_error_c(env);

const char* end = str;
int64_t v3 = ::strtoll(str, (char**)&end, 0);

::free((void*)str);

if (*str == '\0' || *end != '\0')
throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Invalid index.");
throw xmlrpc_error_c(XMLRPC_TYPE_ERROR, "Invalid index.");

return v3;
}

default:
xmlrpc_DECREF(tmp);
throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Invalid type found.");
throw xmlrpc_error_c(XMLRPC_TYPE_ERROR, "Invalid type found.");
}
}

Expand All @@ -153,7 +153,7 @@ xmlrpc_to_index_type(int index, int callType, core::Download* download) {
}

if (result == NULL)
throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Invalid index.");
throw xmlrpc_error_c(XMLRPC_TYPE_ERROR, "Invalid index.");

return rpc::make_target(callType, result);
}
Expand Down Expand Up @@ -194,7 +194,7 @@ xmlrpc_to_object(xmlrpc_env* env, xmlrpc_value* value, int callType, rpc::target
xmlrpc_read_string(env, value, &valueString);

if (env->fault_occurred)
throw xmlrpc_error(env);
throw xmlrpc_error_c(env);

torrent::Object result = torrent::Object(std::string(valueString));

Expand All @@ -211,7 +211,7 @@ xmlrpc_to_object(xmlrpc_env* env, xmlrpc_value* value, int callType, rpc::target
xmlrpc_read_base64(env, value, &valueSize, (const unsigned char**)&valueString);

if (env->fault_occurred)
throw xmlrpc_error(env);
throw xmlrpc_error_c(env);

torrent::Object result = torrent::Object(std::string(valueString, valueSize));

Expand All @@ -226,24 +226,24 @@ xmlrpc_to_object(xmlrpc_env* env, xmlrpc_value* value, int callType, rpc::target
unsigned int last = xmlrpc_array_size(env, value);

if (env->fault_occurred)
throw xmlrpc_error(env);
throw xmlrpc_error_c(env);

if (callType != XmlRpc::call_generic && last != 0) {
if (last < 1)
throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Too few arguments.");
throw xmlrpc_error_c(XMLRPC_TYPE_ERROR, "Too few arguments.");

xmlrpc_value* tmp;
xmlrpc_array_read_item(env, value, current++, &tmp);

if (env->fault_occurred)
throw xmlrpc_error(env);
throw xmlrpc_error_c(env);

if (target != nullptr)
*target = xmlrpc_to_target(env, tmp, callType);
xmlrpc_DECREF(tmp);

if (env->fault_occurred)
throw xmlrpc_error(env);
throw xmlrpc_error_c(env);

if (target->first == XmlRpc::call_download &&
(callType == XmlRpc::call_file || callType == XmlRpc::call_tracker)) {
Expand All @@ -252,7 +252,7 @@ xmlrpc_to_object(xmlrpc_env* env, xmlrpc_value* value, int callType, rpc::target
// parameter as the index to support old-style calls.

if (current == last)
throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Too few arguments, missing index.");
throw xmlrpc_error_c(XMLRPC_TYPE_ERROR, "Too few arguments, missing index.");

*target = xmlrpc_to_index_type(xmlrpc_list_entry_to_value(env, value, current++), callType, (core::Download*)target->second);
}
Expand Down Expand Up @@ -280,7 +280,7 @@ xmlrpc_to_object(xmlrpc_env* env, xmlrpc_value* value, int callType, rpc::target
// case XMLRPC_TYPE_NIL:
// case XMLRPC_TYPE_DEAD:
default:
throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Unsupported type found.");
throw xmlrpc_error_c(XMLRPC_TYPE_ERROR, "Unsupported type found.");
}
}

Expand Down Expand Up @@ -409,7 +409,7 @@ xmlrpc_call_command(xmlrpc_env* env, xmlrpc_value* args, void* voidServerInfo) {

return object_to_xmlrpc(env, rpc::commands.call_command(itr, object, target));

} catch (xmlrpc_error& e) {
} catch (xmlrpc_error_c& e) {
xmlrpc_env_set_fault(env, e.type(), e.what());
return NULL;

Expand Down

0 comments on commit 51d2d5e

Please sign in to comment.