1 |
From fceba968292c52b67e331384206652350d5331ea Mon Sep 17 00:00:00 2001 |
2 |
From: Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de> |
3 |
Date: Sat, 5 Apr 2008 11:41:34 +0200 |
4 |
Subject: [PATCH 3/6] Use proper datatypes for 'long long' |
5 |
|
6 |
xmlrpc-c uses 'long long' at some places (e.g. in printf |
7 |
statements with PRId64) under the assumption that it has a |
8 |
width of exactly 64 bits. |
9 |
|
10 |
On 64 bit machines 'long long' has a width of 128 bit and |
11 |
will cause overhead both in memory and cpu usage there. As |
12 |
'long long' is used only to handle <i8> datatypes, the patch |
13 |
uses a plain 64 integer type there. |
14 |
|
15 |
It is arguable whether 'int_least64_t' (and 'int_least32_t') |
16 |
would be a better choice for 'int64_t' (and 'int32_t'), but |
17 |
for now, the patch uses datatypes with exact widths. |
18 |
--- |
19 |
include/xmlrpc-c/base.h | 10 ++++++---- |
20 |
src/cpp/param_list.cpp | 8 ++++---- |
21 |
src/cpp/value.cpp | 2 +- |
22 |
3 files changed, 11 insertions(+), 9 deletions(-) |
23 |
|
24 |
diff --git a/include/xmlrpc-c/base.h b/include/xmlrpc-c/base.h |
25 |
index a768b70..0069fc2 100644 |
26 |
--- a/include/xmlrpc-c/base.h |
27 |
+++ b/include/xmlrpc-c/base.h |
28 |
@@ -5,7 +5,9 @@ |
29 |
|
30 |
#include <stddef.h> |
31 |
#include <stdarg.h> |
32 |
+#include <stdint.h> |
33 |
#include <time.h> |
34 |
+#include <stdint.h> |
35 |
#include <xmlrpc-c/util.h> |
36 |
#include <xmlrpc-c/config.h> |
37 |
/* Defines XMLRPC_HAVE_WCHAR, XMLRPC_INT64, XMLRPC_HAVE_TIMEVAL */ |
38 |
@@ -40,9 +42,9 @@ extern unsigned int const xmlrpc_version_point; |
39 |
|
40 |
typedef signed int xmlrpc_int; |
41 |
/* An integer of the type defined by XML-RPC <int>; i.e. 32 bit */ |
42 |
-typedef XMLRPC_INT32 xmlrpc_int32; |
43 |
+typedef int32_t xmlrpc_int32; |
44 |
/* An integer of the type defined by XML-RPC <i4>; i.e. 32 bit */ |
45 |
-typedef XMLRPC_INT64 xmlrpc_int64; |
46 |
+typedef int64_t xmlrpc_int64; |
47 |
/* An integer of the type defined by "XML-RPC" <i8>; i.e. 64 bit */ |
48 |
typedef int xmlrpc_bool; |
49 |
/* A boolean (of the type defined by XML-RPC <boolean>, but there's |
50 |
@@ -130,7 +132,7 @@ extern xmlrpc_type xmlrpc_value_type (xmlrpc_value* const value); |
51 |
|
52 |
xmlrpc_value * |
53 |
xmlrpc_int_new(xmlrpc_env * const envP, |
54 |
- int const intValue); |
55 |
+ xmlrpc_int32 const intValue); |
56 |
|
57 |
xmlrpc_value * |
58 |
xmlrpc_i8_new(xmlrpc_env * const envP, |
59 |
@@ -139,7 +141,7 @@ xmlrpc_i8_new(xmlrpc_env * const envP, |
60 |
void |
61 |
xmlrpc_read_int(xmlrpc_env * const envP, |
62 |
const xmlrpc_value * const valueP, |
63 |
- int * const intValueP); |
64 |
+ xmlrpc_int32 * const intValueP); |
65 |
|
66 |
xmlrpc_value * |
67 |
xmlrpc_bool_new(xmlrpc_env * const envP, |
68 |
diff --git a/src/cpp/param_list.cpp b/src/cpp/param_list.cpp |
69 |
index 67c636b..60f7df9 100644 |
70 |
--- a/src/cpp/param_list.cpp |
71 |
+++ b/src/cpp/param_list.cpp |
72 |
@@ -265,10 +265,10 @@ paramList::getNil(unsigned int const paramNumber) const { |
73 |
|
74 |
|
75 |
|
76 |
-long long |
77 |
+xmlrpc_int64 |
78 |
paramList::getI8(unsigned int const paramNumber, |
79 |
- long long const minimum, |
80 |
- long long const maximum) const { |
81 |
+ xmlrpc_int64 const minimum, |
82 |
+ xmlrpc_int64 const maximum) const { |
83 |
|
84 |
if (paramNumber >= this->paramVector.size()) |
85 |
throw(fault("Not enough parameters", fault::CODE_TYPE)); |
86 |
@@ -277,7 +277,7 @@ paramList::getI8(unsigned int const paramNumber, |
87 |
throw(fault("Parameter that is supposed to be 64-bit integer is not", |
88 |
fault::CODE_TYPE)); |
89 |
|
90 |
- long long const longlongvalue(static_cast<long long>( |
91 |
+ xmlrpc_int64 const longlongvalue(static_cast<xmlrpc_int64>( |
92 |
value_i8(this->paramVector[paramNumber]))); |
93 |
|
94 |
if (longlongvalue < minimum) |
95 |
diff --git a/src/cpp/value.cpp b/src/cpp/value.cpp |
96 |
index e952a5f..fa2e5ce 100644 |
97 |
--- a/src/cpp/value.cpp |
98 |
+++ b/src/cpp/value.cpp |
99 |
@@ -265,7 +265,7 @@ value_int::value_int(xmlrpc_c::value const baseValue) { |
100 |
|
101 |
value_int::operator int() const { |
102 |
|
103 |
- int retval; |
104 |
+ xmlrpc_int32 retval; |
105 |
env_wrap env; |
106 |
|
107 |
xmlrpc_read_int(&env.env_c, this->cValueP, &retval); |
108 |
-- |
109 |
1.6.5.2 |
110 |
|