Date: Thursday, October 19, 2006 @ 17:54:17
Author: gilles
Path: /cvsroot/carob/carob
Modified: Makefile (1.45 -> 1.46) include/BigDecimal.hpp (1.26 -> 1.27)
src/BigDecimal.cpp (1.29 -> 1.30)
test/30-ResultSet/TestBigDecimal.cpp (1.11 -> 1.12)
test/40-Parameter-PreparedStatement/TestParameterStatement.cpp
(1.14 -> 1.15) test/GNUmakefile (1.22 -> 1.23)
Fixes for 64bits compatibility:
.removed int and long instances and replaced with int32_t and int64_t. Warning:
BigDecimal int32_t ctor and cast operator can be bugger under x64. To be checked
.Added -fPIC compilation flags
Partly fixes CAROB-88 (still needs bug hunting/fixing)
----------------------------------------------------------------+
Makefile | 2
include/BigDecimal.hpp | 19 --
src/BigDecimal.cpp | 55 -------
test/30-ResultSet/TestBigDecimal.cpp | 72
+++++-----
test/40-Parameter-PreparedStatement/TestParameterStatement.cpp | 20 +-
test/GNUmakefile | 4
6 files changed, 57 insertions(+), 115 deletions(-)
Index: carob/Makefile
diff -u carob/Makefile:1.45 carob/Makefile:1.46
--- carob/Makefile:1.45 Wed Aug 30 12:17:59 2006
+++ carob/Makefile Thu Oct 19 17:54:17 2006
@@ -58,7 +58,7 @@
# _GLIBCXX_GTHREAD_USE_WEAK
# optional CXXFLAGS
-CXXFLAGS = -g3 -Wall -O0
+CXXFLAGS = -g3 -Wall -O0 -fPIC
# mandatory CXXFLAGS
override CXXFLAGS += -I${INCDIR}
Index: carob/include/BigDecimal.hpp
diff -u carob/include/BigDecimal.hpp:1.26 carob/include/BigDecimal.hpp:1.27
--- carob/include/BigDecimal.hpp:1.26 Thu Jul 27 17:10:42 2006
+++ carob/include/BigDecimal.hpp Thu Oct 19 17:54:17 2006
@@ -87,11 +87,7 @@
/**
* Constructs a BigDecimal which value is taken from the given argument
*/
- BigDecimal(const int);
- /**
- * Constructs a BigDecimal which value is taken from the given argument
- */
- BigDecimal(const long);
+ BigDecimal(const int32_t);
/**
* Constructs a BigDecimal which value is taken from the given argument
*/
@@ -154,19 +150,12 @@
*/
std::wstring toString(const std::locale& loc) const;
/**
- * Conversion to int.
- * Any fractional part of this BigDecimal will be discarded, and if the
- * resulting "BigInteger" is too big to fit in an int, throws an exception
- * @throw ConversionException if the value is to big to be converted
- */
- operator int() const throw (ConversionException);
- /**
- * Conversion to long.
+ * Conversion to int32.
* Any fractional part of this BigDecimal will be discarded, and if the
- * resulting "BigInteger" is too big to fit in a long, throws an exception
+ * resulting "BigInteger" is too big to fit in an int32, throws an exception
* @throw ConversionException if the value is to big to be converted
*/
- operator long() const throw (ConversionException);
+ operator int32_t() const throw (ConversionException);
/**
* Conversion to int64_t
* Any fractional part of this BigDecimal will be discarded, and if the
Index: carob/src/BigDecimal.cpp
diff -u carob/src/BigDecimal.cpp:1.29 carob/src/BigDecimal.cpp:1.30
--- carob/src/BigDecimal.cpp:1.29 Thu Jul 27 17:10:42 2006
+++ carob/src/BigDecimal.cpp Thu Oct 19 17:54:17 2006
@@ -111,7 +111,8 @@
signum = 1;
}
-BigDecimal::BigDecimal(const int arg)
+// FIXME: this operator is possibly bugged for 64bits machines
+BigDecimal::BigDecimal(const int32_t arg)
{
mpz_init(unscaled_value);
initToZero();
@@ -126,21 +127,6 @@
mpz_neg(unscaled_value, unscaled_value);
}
-BigDecimal::BigDecimal(const long arg)
-{
- mpz_init(unscaled_value);
- initToZero();
- if (arg > 0L)
- signum = 1;
- else if (arg < 0L)
- signum = -1;
- else
- return;
- mpz_set_si(unscaled_value, arg);
- if (signum<0) //take the abs()
- mpz_neg(unscaled_value, unscaled_value);
-}
-
BigDecimal::BigDecimal(const int64_t arg)
{
mpz_init(unscaled_value);
@@ -396,7 +382,8 @@
return sRet;
}
-BigDecimal::operator int() const throw (ConversionException)
+// FIXME: this operator is possibly bugged for 64bits machines
+BigDecimal::operator int32_t() const throw (ConversionException)
{
if (signum == 0)
return 0;
@@ -441,40 +428,6 @@
return res;
}
-BigDecimal::operator long() const throw (ConversionException)
-{
- if (signum == 0)
- return 0;
- mpz_t scaled_int; mpz_init(scaled_int);
- toBigInteger(scaled_int);
- if (mpz_size(scaled_int) == 0) // ie. if scaled_int == 0
- {
- mpz_clear(scaled_int);
- return 0;
- }
- // Check we can convert to int
- if (signum>0)
- {
- if (!mpz_fits_slong_p(scaled_int))
- throw (ConversionException(L"BigDecimal " + static_cast<wstring>(*this)
- + L" is to big to be converted into a long", CONV_NUM_RANGE));
- }
- else
- {
- // We have to negate the value for the test
- mpz_t tmp; mpz_init(tmp);
- mpz_neg(tmp, scaled_int);
- if (!mpz_fits_slong_p(tmp))
- throw (ConversionException(L"BigDecimal " + static_cast<wstring>(*this)
- + L" is to big to be converted into a long", CONV_NUM_RANGE));
- mpz_clear(tmp);
- }
- long ret = mpz_get_si(scaled_int);
- if (signum < 0)
- ret = -ret;
- mpz_clear(scaled_int);
- return ret;
-}
//TODO: optimize this horribly slow stuff
BigDecimal::operator int64_t() const throw (ConversionException)
Index: carob/test/30-ResultSet/TestBigDecimal.cpp
diff -u carob/test/30-ResultSet/TestBigDecimal.cpp:1.11
carob/test/30-ResultSet/TestBigDecimal.cpp:1.12
--- carob/test/30-ResultSet/TestBigDecimal.cpp:1.11 Thu Jul 27 17:10:42 2006
+++ carob/test/30-ResultSet/TestBigDecimal.cpp Thu Oct 19 17:54:17 2006
@@ -60,13 +60,13 @@
statementPtr->executeUpdate(
L"UPDATE product SET cost = 12.34 WHERE id=" + toWString(id++));
statementPtr->executeUpdate(
- L"UPDATE product SET cost = " + toWString(numeric_limits<int>::min()) +
L" WHERE id=" + toWString(id++));
+ L"UPDATE product SET cost = " +
toWString(numeric_limits<int32_t>::min()) + L" WHERE id=" + toWString(id++));
statementPtr->executeUpdate(
- L"UPDATE product SET cost = " + toWString(numeric_limits<int>::max()) +
L" WHERE id=" + toWString(id++));
+ L"UPDATE product SET cost = " +
toWString(numeric_limits<int32_t>::max()) + L" WHERE id=" + toWString(id++));
statementPtr->executeUpdate(
- L"UPDATE product SET cost = " + toWString(numeric_limits<long
long>::min()) + L" WHERE id=" + toWString(id++));
+ L"UPDATE product SET cost = " +
toWString(static_cast<int64_t>(numeric_limits<long long>::min())) + L" WHERE
id=" + toWString(id++));
statementPtr->executeUpdate(
- L"UPDATE product SET cost = " + toWString(numeric_limits<long
long>::max()) + L" WHERE id= " + toWString(id++));
+ L"UPDATE product SET cost = " +
toWString(static_cast<int64_t>(numeric_limits<long long>::max())) + L" WHERE
id= " + toWString(id++));
// statementPtr->executeUpdate(
// L"UPDATE product SET cost = " +
toWString(numeric_limits<float>::min()) + L" WHERE id=" + toWString(id++));
statementPtr->executeUpdate(
@@ -158,17 +158,17 @@
logInfo(fctName, toUserString(12.34) + L" - getAsString=" +
drsPtr->getAsString(3, loc));
CPPUNIT_ASSERT(drsPtr->getAsString(3, loc) == toUserString(12.34));
drsPtr->next();
- logInfo(fctName, toUserString(numeric_limits<int>::min()) + L" -
getAsString=" + drsPtr->getAsString(3, loc));
- CPPUNIT_ASSERT(drsPtr->getAsString(3, loc) ==
toUserString(numeric_limits<int>::min()));
+ logInfo(fctName, toUserString(numeric_limits<int32_t>::min()) + L" -
getAsString=" + drsPtr->getAsString(3, loc));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3, loc) ==
toUserString(numeric_limits<int32_t>::min()));
drsPtr->next();
- logInfo(fctName, toUserString(numeric_limits<int>::max()) + L" -
getAsString=" + drsPtr->getAsString(3, loc));
- CPPUNIT_ASSERT(drsPtr->getAsString(3, loc) ==
toUserString(numeric_limits<int>::max()));
+ logInfo(fctName, toUserString(numeric_limits<int32_t>::max()) + L" -
getAsString=" + drsPtr->getAsString(3, loc));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3, loc) ==
toUserString(numeric_limits<int32_t>::max()));
drsPtr->next();
- logInfo(fctName, toUserString(numeric_limits<long long>::min()) + L" -
getAsString=" + drsPtr->getAsString(3, loc));
- CPPUNIT_ASSERT(drsPtr->getAsString(3, loc) ==
toUserString(numeric_limits<long long>::min()));
+ logInfo(fctName, toUserString(static_cast<int64_t>(numeric_limits<long
long>::min())) + L" - getAsString=" + drsPtr->getAsString(3, loc));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3, loc) ==
toUserString(static_cast<int64_t>(numeric_limits<long long>::min())));
drsPtr->next();
- logInfo(fctName, toUserString(numeric_limits<long long>::max()) + L" -
getAsString=" + drsPtr->getAsString(3, loc));
- CPPUNIT_ASSERT(drsPtr->getAsString(3, loc) ==
toUserString(numeric_limits<long long>::max()));
+ logInfo(fctName, toUserString(static_cast<int64_t>(numeric_limits<long
long>::max())) + L" - getAsString=" + drsPtr->getAsString(3, loc));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3, loc) ==
toUserString(static_cast<int64_t>(numeric_limits<long long>::max())));
drsPtr->next();
// logInfo(fctName, toUserString(numeric_limits<float>::min()) + L" -
getAsString=" + drsPtr->getAsString(3, loc));
// CPPUNIT_ASSERT(drsPtr->getAsString(3, loc) ==
toUserString(numeric_limits<float>::min()));
@@ -183,11 +183,11 @@
// CPPUNIT_ASSERT(drsPtr->getAsString(3, loc) ==
toUserString(numeric_limits<double>::max()));
drsPtr->next();
- logInfo(fctName, toUserString(-123456789012LL) + thousandsSep +
toUserString(345678901) + thousandsSep + toUserString(234567890) + decimalSep +
L"123456789012345678901234567890 - getAsString=" + drsPtr->getAsString(3, loc));
- CPPUNIT_ASSERT(drsPtr->getAsString(3, loc) == toUserString(-123456789012LL)
+ thousandsSep + toUserString(345678901) + thousandsSep +
toUserString(234567890) + decimalSep + L"123456789012345678901234567890");
+ logInfo(fctName, toUserString(static_cast<int64_t>(-123456789012LL)) +
thousandsSep + toUserString(345678901) + thousandsSep + toUserString(234567890)
+ decimalSep + L"123456789012345678901234567890 - getAsString=" +
drsPtr->getAsString(3, loc));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3, loc) ==
toUserString(static_cast<int64_t>(-123456789012LL)) + thousandsSep +
toUserString(345678901) + thousandsSep + toUserString(234567890) + decimalSep +
L"123456789012345678901234567890");
drsPtr->next();
- logInfo(fctName, toUserString(123456789012LL) + thousandsSep +
toUserString(345678901) + thousandsSep + toUserString(234567890) + decimalSep +
L"123456789012345678901234567890 - getAsString=" + drsPtr->getAsString(3, loc));
- CPPUNIT_ASSERT(drsPtr->getAsString(3, loc) == toUserString(123456789012LL) +
thousandsSep + toUserString(345678901) + thousandsSep + toUserString(234567890)
+ decimalSep + L"123456789012345678901234567890");
+ logInfo(fctName, toUserString(static_cast<int64_t>(123456789012LL)) +
thousandsSep + toUserString(345678901) + thousandsSep + toUserString(234567890)
+ decimalSep + L"123456789012345678901234567890 - getAsString=" +
drsPtr->getAsString(3, loc));
+ CPPUNIT_ASSERT(drsPtr->getAsString(3, loc) ==
toUserString(static_cast<int64_t>(123456789012LL)) + thousandsSep +
toUserString(345678901) + thousandsSep + toUserString(234567890) + decimalSep +
L"123456789012345678901234567890");
}
//TODO: improve log msgs
@@ -220,12 +220,12 @@
logInfo(fctName, L"12.34 - getAsInt=" + toWString(drsPtr->getAsInt(3)));
CPPUNIT_ASSERT(drsPtr->getAsInt(3) == 12);
drsPtr->next();
- logInfo(fctName, toWString(numeric_limits<int>::min()) + L" - getAsInt=" +
drsPtr->getAsString(3));//toWString(drsPtr->getAsInt(3)));
+ logInfo(fctName, toWString(numeric_limits<int32_t>::min()) + L" - getAsInt="
+ drsPtr->getAsString(3));//toWString(drsPtr->getAsInt(3)));
toWString(drsPtr->getAsInt(3));
- CPPUNIT_ASSERT(drsPtr->getAsInt(3) == numeric_limits<int>::min());
+ CPPUNIT_ASSERT(drsPtr->getAsInt(3) == numeric_limits<int32_t>::min());
drsPtr->next();
- logInfo(fctName, toWString(numeric_limits<int>::max()) + L" - getAsInt=" +
toWString(drsPtr->getAsInt(3)));
- CPPUNIT_ASSERT(drsPtr->getAsInt(3) == numeric_limits<int>::max());
+ logInfo(fctName, toWString(numeric_limits<int32_t>::max()) + L" - getAsInt="
+ toWString(drsPtr->getAsInt(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsInt(3) == numeric_limits<int32_t>::max());
drsPtr->next();
try
{
@@ -269,17 +269,17 @@
logInfo(fctName, L"12.34 - getAsInt64=" + drsPtr->getAsString(3));
CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == 12);
drsPtr->next();
- logInfo(fctName, toWString(numeric_limits<int>::min()) + L" - getAsInt64=" +
drsPtr->getAsString(3));
- CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == numeric_limits<int>::min());
+ logInfo(fctName, toWString(numeric_limits<int32_t>::min()) + L" -
getAsInt64=" + drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == numeric_limits<int32_t>::min());
drsPtr->next();
- logInfo(fctName, toWString(numeric_limits<int>::max()) + L" - getAsInt64=" +
drsPtr->getAsString(3));
- CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == numeric_limits<int>::max());
+ logInfo(fctName, toWString(numeric_limits<int32_t>::max()) + L" -
getAsInt64=" + drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == numeric_limits<int32_t>::max());
drsPtr->next();
- logInfo(fctName, toWString(numeric_limits<long long>::min()) + L" -
getAsInt64=" + drsPtr->getAsString(3));
- CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == numeric_limits<long long>::min());
+ logInfo(fctName, toWString(static_cast<int64_t>(numeric_limits<long
long>::min())) + L" - getAsInt64=" + drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) ==
static_cast<int64_t>(numeric_limits<long long>::min()));
drsPtr->next();
- logInfo(fctName, toWString(numeric_limits<long long>::max()) + L" -
getAsInt64=" + drsPtr->getAsString(3));
- CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == numeric_limits<long long>::max());
+ logInfo(fctName, toWString(static_cast<int64_t>(numeric_limits<long
long>::max())) + L" - getAsInt64=" + drsPtr->getAsString(3));
+ CPPUNIT_ASSERT(drsPtr->getAsInt64(3) ==
static_cast<int64_t>(numeric_limits<long long>::max()));
drsPtr->next();
logInfo(fctName, L"0<number<1 - getAsInt64="+drsPtr->getAsString(3));
CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == 0);
@@ -329,7 +329,7 @@
logInfo(fctName, L"ConversionException catched (this is ok)" +
ce.description());
}
drsPtr->next();
- logInfo(fctName, toWString(numeric_limits<long long>::min()+1) + L" -
getAsInt64=" + drsPtr->getAsString(3));
+ logInfo(fctName, toWString(static_cast<int64_t>(numeric_limits<long
long>::min()+1)) + L" - getAsInt64=" + drsPtr->getAsString(3));
CPPUNIT_ASSERT(drsPtr->getAsInt64(3) == numeric_limits<long long>::min()+1);
connectionPtr->deleteStatement(statementPtr);
@@ -368,11 +368,11 @@
CPPUNIT_ASSERT(drsPtr->getAsUInt64(3) == 12);
drsPtr->next();
drsPtr->next();
- logInfo(fctName, toWString(numeric_limits<int>::max()) + L" - getAsUInt64="
+ toWString(drsPtr->getAsUInt64(3)));
- CPPUNIT_ASSERT(drsPtr->getAsUInt64(3) ==
static_cast<uint64_t>(numeric_limits<int>::max()));
+ logInfo(fctName, toWString(numeric_limits<int32_t>::max()) + L" -
getAsUInt64=" + toWString(drsPtr->getAsUInt64(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsUInt64(3) ==
static_cast<uint64_t>(numeric_limits<int32_t>::max()));
drsPtr->next();
drsPtr->next();
- logInfo(fctName, toWString(numeric_limits<long long>::max()) + L" -
getAsUInt64=" + toWString(drsPtr->getAsUInt64(3)));
+ logInfo(fctName, toWString(static_cast<int64_t>(numeric_limits<long
long>::max())) + L" - getAsUInt64=" + toWString(drsPtr->getAsUInt64(3)));
CPPUNIT_ASSERT(drsPtr->getAsUInt64(3) ==
static_cast<uint64_t>(numeric_limits<long long>::max()));
drsPtr->next();
//min float
@@ -479,11 +479,11 @@
logInfo(fctName, L"12.34 - getAsDouble=" +
toWString(drsPtr->getAsDouble(3)));
CPPUNIT_ASSERT(drsPtr->getAsDouble(3) == 12.34);
drsPtr->next();
- logInfo(fctName, toWString(numeric_limits<int>::min()) + L" - getAsDouble="
+ toWString(drsPtr->getAsDouble(3)));
- CPPUNIT_ASSERT(drsPtr->getAsDouble(3) == numeric_limits<int>::min());
+ logInfo(fctName, toWString(numeric_limits<int32_t>::min()) + L" -
getAsDouble=" + toWString(drsPtr->getAsDouble(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsDouble(3) == numeric_limits<int32_t>::min());
drsPtr->next();
- logInfo(fctName, toWString(numeric_limits<int>::max()) + L" - getAsDouble="
+ toWString(drsPtr->getAsDouble(3)));
- CPPUNIT_ASSERT(drsPtr->getAsDouble(3) == numeric_limits<int>::max());
+ logInfo(fctName, toWString(numeric_limits<int32_t>::max()) + L" -
getAsDouble=" + toWString(drsPtr->getAsDouble(3)));
+ CPPUNIT_ASSERT(drsPtr->getAsDouble(3) == numeric_limits<int32_t>::max());
drsPtr->next();
drsPtr->next(); //skip longs
drsPtr->next();
Index: carob/test/40-Parameter-PreparedStatement/TestParameterStatement.cpp
diff -u
carob/test/40-Parameter-PreparedStatement/TestParameterStatement.cpp:1.14
carob/test/40-Parameter-PreparedStatement/TestParameterStatement.cpp:1.15
--- carob/test/40-Parameter-PreparedStatement/TestParameterStatement.cpp:1.14
Thu Jul 27 17:10:42 2006
+++ carob/test/40-Parameter-PreparedStatement/TestParameterStatement.cpp
Thu Oct 19 17:54:17 2006
@@ -289,16 +289,16 @@
testVals[nbTestVals++] = BigDecimal(L"123,456");
testVals[nbTestVals++] = BigDecimal(-123456789);
testVals[nbTestVals++] = BigDecimal(123456789);
- testVals[nbTestVals++] = BigDecimal(-123456789L);
- testVals[nbTestVals++] = BigDecimal(123456789L);
- testVals[nbTestVals++] = BigDecimal(-123456789LL);
- testVals[nbTestVals++] = BigDecimal(123456789LL);
- testVals[nbTestVals++] = BigDecimal(numeric_limits<int>::min());
- testVals[nbTestVals++] = BigDecimal(numeric_limits<int>::max());
- testVals[nbTestVals++] = BigDecimal(numeric_limits<long>::min());
- testVals[nbTestVals++] = BigDecimal(numeric_limits<long>::max());
- testVals[nbTestVals++] = BigDecimal(numeric_limits<long long>::min());
- testVals[nbTestVals++] = BigDecimal(numeric_limits<long long>::max());
+ testVals[nbTestVals++] = BigDecimal(static_cast<int64_t>(-123456789L));
+ testVals[nbTestVals++] = BigDecimal(static_cast<int64_t>(123456789L));
+ testVals[nbTestVals++] = BigDecimal(static_cast<int64_t>(-123456789LL));
+ testVals[nbTestVals++] = BigDecimal(static_cast<int64_t>(123456789LL));
+ testVals[nbTestVals++] = BigDecimal(numeric_limits<int32_t>::min());
+ testVals[nbTestVals++] = BigDecimal(numeric_limits<int32_t>::max());
+ testVals[nbTestVals++] = BigDecimal(numeric_limits<int64_t>::min());
+ testVals[nbTestVals++] = BigDecimal(numeric_limits<int64_t>::max());
+ testVals[nbTestVals++] = BigDecimal(static_cast<int64_t>(numeric_limits<long
long>::min()));
+ testVals[nbTestVals++] = BigDecimal(static_cast<int64_t>(numeric_limits<long
long>::max()));
//TODO change testVals array size when adding new values
for (int i=0; i<nbTestVals; i++)
Index: carob/test/GNUmakefile
diff -u carob/test/GNUmakefile:1.22 carob/test/GNUmakefile:1.23
--- carob/test/GNUmakefile:1.22 Wed Sep 20 17:09:13 2006
+++ carob/test/GNUmakefile Thu Oct 19 17:54:17 2006
@@ -42,8 +42,8 @@
TESTOBJS = ${TESTSRCS:%.cpp=%.o}
# for GCC
-CXXFLAGS = -g3 -Wall -I${INCDIR}
-LDFLAGS = -Wl,-rpath,${CAROB_ROOT} -L${CAROB_ROOT}
-l${LIB_CAROB} -ldl -l${LIB_CPPUNIT} -rdynamic
+CXXFLAGS = -g3 -Wall -fPIC -I${INCDIR}
+LDFLAGS = -fPIC -Wl,-rpath,${CAROB_ROOT} -L${CAROB_ROOT}
-l${LIB_CAROB} -ldl -l${LIB_CPPUNIT} -rdynamic
# For QT ui, uncomment this
#LDFLAGS += -l${LIB_CPPUNIT_QTUI}
EXE = carobTestLauncher
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits