From d7351c0c708f2dc30df6b1e5dc89f4a5d427b240 Mon Sep 17 00:00:00 2001 From: Oliver Giles Date: Thu, 4 Jan 2018 08:40:10 +0200 Subject: [PATCH] fix compile error on 32-bit Linux On 32-bit Linux, time_t is a long. Laminar extensively uses time_t but provided only int and int64 db access, making the use of long ambiguous. Since there is no explicit use of int64, and because on 32-bit Linux long and int are recognized as different types despite being the same width, replacing the int64 handlers with long handlers fixes the compile error --- src/database.cpp | 12 ++++++------ src/database.h | 8 ++++---- src/laminar.cpp | 5 +---- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/database.cpp b/src/database.cpp index f5632a9..528d14c 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -52,11 +52,11 @@ void Database::Statement::bindValue(int i, uint e) { sqlite3_bind_int(stmt, i, static_cast(e)); } -void Database::Statement::bindValue(int i, int64_t e) { +void Database::Statement::bindValue(int i, long e) { sqlite3_bind_int64(stmt, i, e); } -void Database::Statement::bindValue(int i, uint64_t e) { +void Database::Statement::bindValue(int i, ulong e) { sqlite3_bind_int64(stmt, i, static_cast(e)); } @@ -88,12 +88,12 @@ template<> uint Database::Statement::fetchColumn(int col) { return static_cast(sqlite3_column_int(stmt, col)); } -template<> int64_t Database::Statement::fetchColumn(int col) { - return sqlite3_column_int64(stmt, col); +template<> long Database::Statement::fetchColumn(int col) { + return static_cast(sqlite3_column_int64(stmt, col)); } -template<> uint64_t Database::Statement::fetchColumn(int col) { - return static_cast(sqlite3_column_int64(stmt, col)); +template<> ulong Database::Statement::fetchColumn(int col) { + return static_cast(sqlite3_column_int64(stmt, col)); } bool Database::Statement::row() { diff --git a/src/database.h b/src/database.h index 26df3c8..c7dbc80 100644 --- a/src/database.h +++ b/src/database.h @@ -120,8 +120,8 @@ private: // Bind value specializations void bindValue(int i, int e); void bindValue(int i, uint e); - void bindValue(int i, int64_t e); - void bindValue(int i, uint64_t e); + void bindValue(int i, long e); + void bindValue(int i, unsigned long e); void bindValue(int i, const char* e); void bindValue(int i, const std::string& e); @@ -149,7 +149,7 @@ template<> std::string Database::Statement::fetchColumn(int col); template<> const char* Database::Statement::fetchColumn(int col); template<> int Database::Statement::fetchColumn(int col); template<> uint Database::Statement::fetchColumn(int col); -template<> int64_t Database::Statement::fetchColumn(int col); -template<> uint64_t Database::Statement::fetchColumn(int col); +template<> long Database::Statement::fetchColumn(int col); +template<> ulong Database::Statement::fetchColumn(int col); #endif // LAMINAR_DATABASE_H_ diff --git a/src/laminar.cpp b/src/laminar.cpp index 4ba989f..06e4069 100644 --- a/src/laminar.cpp +++ b/src/laminar.cpp @@ -41,7 +41,7 @@ class Json : public rapidjson::Writer { public: Json() : rapidjson::Writer(buf) { StartObject(); } template - Json& set(const char* key, T value); + Json& set(const char* key, T value) { String(key); Int64(value); return *this; } Json& startObject(const char* key) { String(key); StartObject(); return *this; } Json& startArray(const char* key) { String(key); StartArray(); return *this; } const char* str() { EndObject(); return buf.GetString(); } @@ -50,9 +50,6 @@ private: }; template<> Json& Json::set(const char* key, const char* value) { String(key); String(value); return *this; } template<> Json& Json::set(const char* key, std::string value) { String(key); String(value.c_str()); return *this; } -template<> Json& Json::set(const char* key, int value) { String(key); Int(value); return *this; } -template<> Json& Json::set(const char* key, uint value) { String(key); Int(static_cast(value)); return *this; } -template<> Json& Json::set(const char* key, time_t value) { String(key); Int64(value); return *this; } namespace { // Default values when none were supplied in $LAMINAR_CONF_FILE (/etc/laminar.conf)