200 lines
6.8 KiB
Diff
200 lines
6.8 KiB
Diff
From 1823bda8047c3d7113e86f7550cbf3df8d105e67 Mon Sep 17 00:00:00 2001
|
|
From: Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
|
|
Date: Sat, 5 Apr 2008 11:41:34 +0200
|
|
Subject: [PATCH] Use proper datatypes for 'long long'
|
|
|
|
xmlrpc-c uses 'long long' at some places (e.g. in printf
|
|
statements with PRId64) under the assumption that it has a
|
|
width of exactly 64 bits.
|
|
|
|
On 64 bit machines 'long long' has a width of 128 bit and
|
|
will cause overhead both in memory and cpu usage there. As
|
|
'long long' is used only to handle <i8> datatypes, the patch
|
|
uses a plain 64 integer type there.
|
|
|
|
It is arguable whether 'int_least64_t' (and 'int_least32_t')
|
|
would be a better choice for 'int64_t' (and 'int32_t'), but
|
|
for now, the patch uses datatypes with exact widths.
|
|
---
|
|
include/xmlrpc-c/base.h | 5 +++--
|
|
include/xmlrpc-c/base.hpp | 10 +++++-----
|
|
src/cpp/param_list.cpp | 8 ++++----
|
|
src/cpp/test/test.cpp | 12 ++++++------
|
|
src/cpp/test/testclient.cpp | 2 +-
|
|
src/cpp/value.cpp | 8 ++++----
|
|
6 files changed, 23 insertions(+), 22 deletions(-)
|
|
|
|
diff --git a/include/xmlrpc-c/base.h b/include/xmlrpc-c/base.h
|
|
index 712691c..9ce0cd2 100644
|
|
--- a/include/xmlrpc-c/base.h
|
|
+++ b/include/xmlrpc-c/base.h
|
|
@@ -6,6 +6,7 @@
|
|
#include <stddef.h>
|
|
#include <stdarg.h>
|
|
#include <time.h>
|
|
+#include <stdint.h>
|
|
#include <xmlrpc-c/util.h>
|
|
#include <xmlrpc-c/config.h>
|
|
/* Defines XMLRPC_HAVE_WCHAR, XMLRPC_LONG_LONG */
|
|
@@ -36,9 +37,9 @@ extern unsigned int const xmlrpc_version_point;
|
|
|
|
typedef signed int xmlrpc_int;
|
|
/* An integer of the type defined by XML-RPC <int>; i.e. 32 bit */
|
|
-typedef signed int xmlrpc_int32;
|
|
+typedef int32_t xmlrpc_int32;
|
|
/* An integer of the type defined by XML-RPC <i4>; i.e. 32 bit */
|
|
-typedef XMLRPC_LONG_LONG xmlrpc_int64;
|
|
+typedef int64_t xmlrpc_int64;
|
|
/* An integer of the type defined by "XML-RPC" <i8>; i.e. 64 bit */
|
|
typedef int xmlrpc_bool;
|
|
/* A boolean (of the type defined by XML-RPC <boolean>, but there's
|
|
diff --git a/include/xmlrpc-c/base.hpp b/include/xmlrpc-c/base.hpp
|
|
index 5634b34..ab6fe3e 100644
|
|
--- a/include/xmlrpc-c/base.hpp
|
|
+++ b/include/xmlrpc-c/base.hpp
|
|
@@ -200,11 +200,11 @@ public:
|
|
|
|
class value_i8 : public value {
|
|
public:
|
|
- value_i8(long long const cvalue);
|
|
+ value_i8(xmlrpc_int64 const cvalue);
|
|
|
|
value_i8(xmlrpc_c::value const baseValue);
|
|
|
|
- operator long long() const;
|
|
+ operator xmlrpc_int64() const;
|
|
};
|
|
|
|
|
|
@@ -330,10 +330,10 @@ public:
|
|
void
|
|
getNil(unsigned int const paramNumber) const;
|
|
|
|
- long long
|
|
+ xmlrpc_int64
|
|
getI8(unsigned int const paramNumber,
|
|
- long long const minimum = XMLRPC_INT64_MIN,
|
|
- long long const maximum = XMLRPC_INT64_MAX) const;
|
|
+ xmlrpc_int64 const minimum = XMLRPC_INT64_MIN,
|
|
+ xmlrpc_int64 const maximum = XMLRPC_INT64_MAX) const;
|
|
|
|
void
|
|
verifyEnd(unsigned int const paramNumber) const;
|
|
diff --git a/src/cpp/param_list.cpp b/src/cpp/param_list.cpp
|
|
index 67c636b..60f7df9 100644
|
|
--- a/src/cpp/param_list.cpp
|
|
+++ b/src/cpp/param_list.cpp
|
|
@@ -265,10 +265,10 @@ paramList::getNil(unsigned int const paramNumber) const {
|
|
|
|
|
|
|
|
-long long
|
|
+xmlrpc_int64
|
|
paramList::getI8(unsigned int const paramNumber,
|
|
- long long const minimum,
|
|
- long long const maximum) const {
|
|
+ xmlrpc_int64 const minimum,
|
|
+ xmlrpc_int64 const maximum) const {
|
|
|
|
if (paramNumber >= this->paramVector.size())
|
|
throw(fault("Not enough parameters", fault::CODE_TYPE));
|
|
@@ -277,7 +277,7 @@ paramList::getI8(unsigned int const paramNumber,
|
|
throw(fault("Parameter that is supposed to be 64-bit integer is not",
|
|
fault::CODE_TYPE));
|
|
|
|
- long long const longlongvalue(static_cast<long long>(
|
|
+ xmlrpc_int64 const longlongvalue(static_cast<xmlrpc_int64>(
|
|
value_i8(this->paramVector[paramNumber])));
|
|
|
|
if (longlongvalue < minimum)
|
|
diff --git a/src/cpp/test/test.cpp b/src/cpp/test/test.cpp
|
|
index b3c2caf..c92653f 100644
|
|
--- a/src/cpp/test/test.cpp
|
|
+++ b/src/cpp/test/test.cpp
|
|
@@ -418,15 +418,15 @@ public:
|
|
}
|
|
virtual void runtests(unsigned int const) {
|
|
value_i8 int1(7);
|
|
- TEST(static_cast<long long>(int1) == 7);
|
|
+ TEST(static_cast<xmlrpc_int64>(int1) == 7);
|
|
value_i8 int2(-7);
|
|
- TEST(static_cast<long long>(int2) == -7);
|
|
+ TEST(static_cast<xmlrpc_int64>(int2) == -7);
|
|
value_i8 int5(1ull << 40);
|
|
- TEST(static_cast<long long>(int5) == (1ull << 40));
|
|
+ TEST(static_cast<xmlrpc_int64>(int5) == (1ull << 40));
|
|
value val1(int1);
|
|
TEST(val1.type() == value::TYPE_I8);
|
|
value_i8 int3(val1);
|
|
- TEST(static_cast<long long>(int3) == 7);
|
|
+ TEST(static_cast<xmlrpc_int64>(int3) == 7);
|
|
try {
|
|
value_i8 int4(value_double(3.7));
|
|
TEST_FAILED("invalid cast double-i8 suceeded");
|
|
@@ -554,7 +554,7 @@ public:
|
|
structData.insert(member);
|
|
paramList1.add(value_struct(structData));
|
|
paramList1.add(value_nil());
|
|
- paramList1.add(value_i8((long long)UINT_MAX + 1));
|
|
+ paramList1.add(value_i8((xmlrpc_int64)UINT_MAX + 1));
|
|
|
|
TEST(paramList1.size() == 11);
|
|
|
|
@@ -578,7 +578,7 @@ public:
|
|
TEST(paramList1.getArray(7, 1, 3).size() == 3);
|
|
paramList1.getStruct(8)["the_integer"];
|
|
paramList1.getNil(9);
|
|
- TEST(paramList1.getI8(10) == (long long)UINT_MAX + 1);
|
|
+ TEST(paramList1.getI8(10) == (xmlrpc_int64)UINT_MAX + 1);
|
|
paramList1.verifyEnd(11);
|
|
|
|
paramList paramList2(5);
|
|
diff --git a/src/cpp/test/testclient.cpp b/src/cpp/test/testclient.cpp
|
|
index cb7f86a..e3c23a8 100644
|
|
--- a/src/cpp/test/testclient.cpp
|
|
+++ b/src/cpp/test/testclient.cpp
|
|
@@ -783,7 +783,7 @@ public:
|
|
TEST(rpcApacheP->isFinished());
|
|
TEST(rpcApacheP->isSuccessful());
|
|
value_i8 const result(rpcApacheP->getResult());
|
|
- TEST(static_cast<long long>(result) == 7ll);
|
|
+ TEST(static_cast<xmlrpc_int64>(result) == 7ll);
|
|
}
|
|
}
|
|
};
|
|
diff --git a/src/cpp/value.cpp b/src/cpp/value.cpp
|
|
index 588b91f..6dcba93 100644
|
|
--- a/src/cpp/value.cpp
|
|
+++ b/src/cpp/value.cpp
|
|
@@ -831,13 +831,13 @@ value_nil::value_nil(xmlrpc_c::value const baseValue) {
|
|
|
|
|
|
|
|
-value_i8::value_i8(long long const cppvalue) {
|
|
+value_i8::value_i8(xmlrpc_int64 const cppvalue) {
|
|
|
|
class cWrapper {
|
|
public:
|
|
xmlrpc_value * valueP;
|
|
|
|
- cWrapper(long long const cppvalue) {
|
|
+ cWrapper(xmlrpc_int64 const cppvalue) {
|
|
env_wrap env;
|
|
|
|
this->valueP = xmlrpc_i8_new(&env.env_c, cppvalue);
|
|
@@ -866,9 +866,9 @@ value_i8::value_i8(xmlrpc_c::value const baseValue) {
|
|
|
|
|
|
|
|
-value_i8::operator long long() const {
|
|
+value_i8::operator xmlrpc_int64() const {
|
|
|
|
- long long retval;
|
|
+ xmlrpc_int64 retval;
|
|
env_wrap env;
|
|
|
|
xmlrpc_read_i8(&env.env_c, this->cValueP, &retval);
|
|
--
|
|
1.5.4.1
|
|
|