From 8b5dd60a662f9dc9470a702b56399dc8afbae358 Mon Sep 17 00:00:00 2001 From: alexpeshkoff Date: Thu, 19 Apr 2007 09:19:11 +0000 Subject: [PATCH] fixed posix build after latest changes --- src/common/classes/rwlock.h | 137 +++++++++++++++++------------------- src/intl/lc_icu.cpp | 2 +- src/jrd/IntlManager.cpp | 2 +- src/jrd/IntlUtil.cpp | 2 +- src/jrd/SysFunction.cpp | 45 ++++++------ src/jrd/common.h | 7 ++ src/jrd/intl_builtin.cpp | 4 +- src/jrd/unicode_util.cpp | 4 +- 8 files changed, 104 insertions(+), 99 deletions(-) diff --git a/src/common/classes/rwlock.h b/src/common/classes/rwlock.h index 7f1fd4f9d3..a9386026e0 100644 --- a/src/common/classes/rwlock.h +++ b/src/common/classes/rwlock.h @@ -60,66 +60,6 @@ private: RWLock(const RWLock& source); public: - // RAII holder of begin/end read - class ReadGuard - { - public: - explicit ReadGuard(RWLock& alock) - : lock(&alock) - { - lock->beginRead(); - } - - ~ReadGuard() - { - release(); - } - - void release() - { - if (lock) - { - lock->endRead(); - lock = NULL; - } - } - - private: - // Forbid copy constructor - ReadGuard(const ReadGuard& source); - RWLock* lock; - }; - - // RAII holder of begin/end write - class WriteGuard - { - public: - explicit WriteGuard(RWLock& alock) - : lock(&alock) - { - lock->beginWrite(); - } - - ~WriteGuard() - { - release(); - } - - void release() - { - if (lock) - { - lock->endWrite(); - lock = NULL; - } - } - - private: - // Forbid copy constructor - WriteGuard(const WriteGuard& source); - RWLock* lock; - }; - RWLock() : lock(0), blockedReaders(0), blockedWriters(0) { readers_semaphore = CreateSemaphore(NULL, 0 /*initial count*/, @@ -217,11 +157,8 @@ public: if (lock.exchangeAdd(LOCK_WRITER_OFFSET) == -LOCK_WRITER_OFFSET) unblockWaiting(); } -}; -} // namespace Firebird - #else #ifdef MULTI_THREAD @@ -292,9 +229,6 @@ public: if (rw_unlock(&lock)) system_call_failed::raise("rw_unlock"); } -}; - -} // namespace Firebird @@ -373,9 +307,6 @@ public: if (pthread_rwlock_unlock(&lock)) system_call_failed::raise("pthread_rwlock_unlock"); } -}; - -} // namespace Firebird #endif /*solaris threading (not posix)*/ @@ -399,15 +330,75 @@ public: bool tryBeginWrite() { return true; } void beginWrite() { } void endWrite() { } -}; - -} // namespace Firebird #endif /*MULTI_THREAD*/ #endif /*!WIN_NT*/ -namespace Firebird { +// common for all platforms part of class + +public: + // RAII holder of begin/end read + class ReadGuard + { + public: + explicit ReadGuard(RWLock& alock) + : lock(&alock) + { + lock->beginRead(); + } + + ~ReadGuard() + { + release(); + } + + void release() + { + if (lock) + { + lock->endRead(); + lock = NULL; + } + } + + private: + // Forbid copy constructor + ReadGuard(const ReadGuard& source); + RWLock* lock; + }; + + // RAII holder of begin/end write + class WriteGuard + { + public: + explicit WriteGuard(RWLock& alock) + : lock(&alock) + { + lock->beginWrite(); + } + + ~WriteGuard() + { + release(); + } + + void release() + { + if (lock) + { + lock->endWrite(); + lock = NULL; + } + } + + private: + // Forbid copy constructor + WriteGuard(const WriteGuard& source); + RWLock* lock; + }; +}; + // RAII holder of read lock class ReadLockGuard { diff --git a/src/intl/lc_icu.cpp b/src/intl/lc_icu.cpp index d4639dcff4..f573a011bb 100644 --- a/src/intl/lc_icu.cpp +++ b/src/intl/lc_icu.cpp @@ -119,7 +119,7 @@ bool LCICU_setup_attributes(const ASCII* name, const ASCII* charSetName, const A if (len > 8 && strcmp(name + len - 8, "_UNICODE") == 0) { - AutoPtr cs = new charset; + AutoPtr cs(new charset); memset(cs, 0, sizeof(*cs)); // test if that charset exist diff --git a/src/jrd/IntlManager.cpp b/src/jrd/IntlManager.cpp index 588b10e313..86679508c6 100644 --- a/src/jrd/IntlManager.cpp +++ b/src/jrd/IntlManager.cpp @@ -368,7 +368,7 @@ Firebird::string IntlManager::getConfigInfo(const ConfObj& confObj) if (configInfo.hasData()) configInfo.append(";"); - configInfo.append(string(el->name) + "=" + values); + configInfo.append(string(el->name.c_str()) + "=" + values); } return configInfo; diff --git a/src/jrd/IntlUtil.cpp b/src/jrd/IntlUtil.cpp index c0da59d6c3..75f2bd9542 100644 --- a/src/jrd/IntlUtil.cpp +++ b/src/jrd/IntlUtil.cpp @@ -475,7 +475,7 @@ bool IntlUtil::readOneChar(Jrd::CharSet* cs, const UCHAR** s, const UCHAR* end, bool IntlUtil::setupIcuAttributes(charset* cs, const string& specificAttributes, const string& configInfo, string& newSpecificAttributes) { - AutoPtr charSet = Jrd::CharSet::createInstance(*getDefaultMemoryPool(), 0, cs); + AutoPtr charSet(Jrd::CharSet::createInstance(*getDefaultMemoryPool(), 0, cs)); IntlUtil::SpecificAttributesMap map; if (!IntlUtil::parseSpecificAttributes(charSet, specificAttributes.length(), diff --git a/src/jrd/SysFunction.cpp b/src/jrd/SysFunction.cpp index 3836778218..1e520e2918 100644 --- a/src/jrd/SysFunction.cpp +++ b/src/jrd/SysFunction.cpp @@ -1361,7 +1361,7 @@ static dsc* evlHash(Jrd::thread_db* tdbb, SysFunction* function, Jrd::jrd_nod* a { impure->vlu_misc.vlu_int64 = (impure->vlu_misc.vlu_int64 << 4) + *address; - SINT64 n = impure->vlu_misc.vlu_int64 & 0xF000000000000000i64; + SINT64 n = impure->vlu_misc.vlu_int64 & CONST64(0xF000000000000000); if (n) impure->vlu_misc.vlu_int64 ^= n >> 56; impure->vlu_misc.vlu_int64 &= ~n; @@ -1629,7 +1629,7 @@ static dsc* evlOverlay(Jrd::thread_db* tdbb, SysFunction* function, Jrd::jrd_nod if (!value->isBlob() && !placing->isBlob()) { - if (len1 - length + len2 > MAX_COLUMN_SIZE - sizeof(USHORT)) + if (len1 - length + len2 > static_cast(MAX_COLUMN_SIZE - sizeof(USHORT))) status_exception::raise(isc_arith_except, 0); dsc desc; @@ -1716,7 +1716,7 @@ static dsc* evlPad(Jrd::thread_db* tdbb, SysFunction* function, Jrd::jrd_nod* ar const dsc* padLenDsc = EVL_expr(tdbb, args->nod_arg[1]); if (request->req_flags & req_null) // return NULL if padLenDsc is NULL return NULL; - SLONG padLen = MOV_get_long(padLenDsc, 0); + ULONG padLen = MOV_get_long(padLenDsc, 0); const dsc* value2 = NULL; if (args->nod_count >= 3) @@ -1732,7 +1732,7 @@ static dsc* evlPad(Jrd::thread_db* tdbb, SysFunction* function, Jrd::jrd_nod* ar MoveBuffer buffer1; UCHAR* address1; ULONG length1 = MOV_make_string2(tdbb, value1, ttype, &address1, buffer1, false); - SLONG charLength1 = cs->length(length1, address1, true); + ULONG charLength1 = cs->length(length1, address1, true); MoveBuffer buffer2; UCHAR* address2; @@ -1746,7 +1746,7 @@ static dsc* evlPad(Jrd::thread_db* tdbb, SysFunction* function, Jrd::jrd_nod* ar else length2 = MOV_make_string2(tdbb, value2, ttype, &address2, buffer2, false); - SLONG charLength2 = cs->length(length2, address2, true); + ULONG charLength2 = cs->length(length2, address2, true); blb* newBlob = NULL; @@ -2062,9 +2062,9 @@ static dsc* evlReplace(Jrd::thread_db* tdbb, SysFunction* function, Jrd::jrd_nod // make descriptor for return value if (!firstBlob) { - int searchedLen = canonicals[0].getCount() / canonicalWidth; - int findLen = canonicals[1].getCount() / canonicalWidth; - int replacementLen = lengths[2] / cs->minBytesPerChar(); + unsigned int searchedLen = canonicals[0].getCount() / canonicalWidth; + unsigned int findLen = canonicals[1].getCount() / canonicalWidth; + unsigned int replacementLen = lengths[2] / cs->minBytesPerChar(); USHORT len = MIN(MAX_COLUMN_SIZE, cs->maxBytesPerChar() * MAX(searchedLen, searchedLen + @@ -2427,15 +2427,20 @@ SysFunction::SysFunction(const char* s, int minCount, int maxCount, MakeFunc mf, #define SF(a, b, c, d, e, f) {a, b, c, d, e, f} #endif +#ifdef _MSC_VER +typedef StdMathFunc VoidPtrStdMathFunc; +#else +typedef void* VoidPtrStdMathFunc; +#endif SysFunction SysFunction::functions[] = { SF("ABS", 1, 1, makeAbs, evlAbs, NULL), - SF("ACOS", 1, 1, makeDoubleResult, evlStdMath, (StdMathFunc) acos), + SF("ACOS", 1, 1, makeDoubleResult, evlStdMath, (VoidPtrStdMathFunc) acos), SF("ASCII_CHAR", 1, 1, makeAsciiChar, evlAsciiChar, NULL), SF("ASCII_VAL", 1, 1, makeShortResult, evlAsciiVal, NULL), - SF("ASIN", 1, 1, makeDoubleResult, evlStdMath, (StdMathFunc) asin), - SF("ATAN", 1, 1, makeDoubleResult, evlStdMath, (StdMathFunc) atan), + SF("ASIN", 1, 1, makeDoubleResult, evlStdMath, (VoidPtrStdMathFunc) asin), + SF("ATAN", 1, 1, makeDoubleResult, evlStdMath, (VoidPtrStdMathFunc) atan), SF("ATAN2", 2, 2, makeDoubleResult, evlAtan2, NULL), SF("BIN_AND", 1, -1, makeBin, evlBin, (void*) funBinAnd), SF("BIN_OR", 1, -1, makeBin, evlBin, (void*) funBinOr), @@ -2444,9 +2449,9 @@ SysFunction SysFunction::functions[] = SF("BIN_XOR", 1, -1, makeBin, evlBin, (void*) funBinXor), SF("CEIL", 1, 1, makeCeilFloor, evlCeil, NULL), SF("CEILING", 1, 1, makeCeilFloor, evlCeil, NULL), - SF("COS", 1, 1, makeDoubleResult, evlStdMath, (StdMathFunc) cos), - SF("COSH", 1, 1, makeDoubleResult, evlStdMath, (StdMathFunc) cosh), - SF("COT", 1, 1, makeDoubleResult, evlStdMath, (StdMathFunc) cot), + SF("COS", 1, 1, makeDoubleResult, evlStdMath, (VoidPtrStdMathFunc) cos), + SF("COSH", 1, 1, makeDoubleResult, evlStdMath, (VoidPtrStdMathFunc) cosh), + SF("COT", 1, 1, makeDoubleResult, evlStdMath, (VoidPtrStdMathFunc) cot), SF("DATEADD", 3, 3, makeDateAdd, evlDateAdd, NULL), SF("DATEDIFF", 3, 3, makeInt64Result, evlDateDiff, NULL), SF("EXP", 1, 1, makeDoubleResult, evlExp, NULL), @@ -2456,7 +2461,7 @@ SysFunction SysFunction::functions[] = SF("LEFT", 2, 2, makeLeftRight, evlLeft, NULL), SF("LN", 1, 1, makeDoubleResult, evlLn, NULL), SF("LOG", 2, 2, makeDoubleResult, evlLog, NULL), - SF("LOG10", 1, 1, makeDoubleResult, evlStdMath, (StdMathFunc) log10), + SF("LOG10", 1, 1, makeDoubleResult, evlStdMath, (VoidPtrStdMathFunc) log10), SF("LPAD", 2, 3, makePad, evlPad, (void*) funLPad), SF("MAXVALUE", 1, -1, makeFromListResult, evlMaxMinValue, (void*) funMaxValue), SF("MINVALUE", 1, -1, makeFromListResult, evlMaxMinValue, (void*) funMinValue), @@ -2472,13 +2477,13 @@ SysFunction SysFunction::functions[] = SF("ROUND", 2, 2, makeRound, evlRound, NULL), SF("RPAD", 2, 3, makePad, evlPad, (void*) funRPad), SF("SIGN", 1, 1, makeShortResult, evlSign, NULL), - SF("SIN", 1, 1, makeDoubleResult, evlStdMath, (StdMathFunc) sin), - SF("SINH", 1, 1, makeDoubleResult, evlStdMath, (StdMathFunc) sinh), + SF("SIN", 1, 1, makeDoubleResult, evlStdMath, (VoidPtrStdMathFunc) sin), + SF("SINH", 1, 1, makeDoubleResult, evlStdMath, (VoidPtrStdMathFunc) sinh), SF("SQRT", 1, 1, makeDoubleResult, evlSqrt, NULL), - SF("TAN", 1, 1, makeDoubleResult, evlStdMath, (StdMathFunc) tan), - SF("TANH", 1, 1, makeDoubleResult, evlStdMath, (StdMathFunc) tanh), + SF("TAN", 1, 1, makeDoubleResult, evlStdMath, (VoidPtrStdMathFunc) tan), + SF("TANH", 1, 1, makeDoubleResult, evlStdMath, (VoidPtrStdMathFunc) tanh), SF("TRUNC", 1, 1, makeTrunc, evlTrunc, NULL), - SF("", 0, NULL, NULL, NULL, NULL) + SF("", 0, 0, NULL, NULL, NULL) }; diff --git a/src/jrd/common.h b/src/jrd/common.h index e5e38cebb2..b455aa0e51 100644 --- a/src/jrd/common.h +++ b/src/jrd/common.h @@ -1047,6 +1047,13 @@ void GDS_breakpoint(int); #define STRINGIZE_AUX(x) #x #define STRINGIZE(x) STRINGIZE_AUX(x) +#ifdef _MSC_VER +#define CONST64(a) (a##i64) +#else +#define CONST64(a) (a##L) +#endif + + /* switch name and state table. This structure should be used in all * command line tools to facilitate parsing options.*/ struct in_sw_tab_t { diff --git a/src/jrd/intl_builtin.cpp b/src/jrd/intl_builtin.cpp index 802e034143..26af4c9c0e 100644 --- a/src/jrd/intl_builtin.cpp +++ b/src/jrd/intl_builtin.cpp @@ -1235,6 +1235,7 @@ static INTL_BOOL cs_utf32_well_formed(charset* cs, } +#ifdef NOT_USED_OR_REPLACED static ULONG cvt_ascii_to_unicode(csconvert* obj, ULONG nSrc, const UCHAR* pSrc, ULONG nDest, USHORT* pDest, USHORT* err_code, ULONG* err_position) @@ -1321,6 +1322,7 @@ static ULONG cvt_unicode_to_ascii(csconvert* obj, ULONG nSrc, const USHORT* pSrc return ((pDest - pStart) * sizeof(*pDest)); } +#endif //NOT_USED_OR_REPLACED static ULONG cvt_none_to_unicode(csconvert* obj, ULONG nSrc, const UCHAR* pSrc, @@ -1843,7 +1845,7 @@ ULONG INTL_builtin_setup_attributes(const ASCII* textTypeName, const ASCII* char // the preprocessor, but this is a task for another day. if (strstr(textTypeName, "UNICODE") && strcmp(textTypeName, "UNICODE_FSS") != 0) { - Firebird::AutoPtr cs = new charset; + Firebird::AutoPtr cs(new charset); memset(cs, 0, sizeof(*cs)); // test if that charset exists diff --git a/src/jrd/unicode_util.cpp b/src/jrd/unicode_util.cpp index 7769259b1f..947951fcc4 100644 --- a/src/jrd/unicode_util.cpp +++ b/src/jrd/unicode_util.cpp @@ -34,7 +34,7 @@ #include "../common/classes/GenericMap.h" #include "../common/classes/init.h" #include "../common/classes/objects_array.h" -#include "../common/classes/RWLock.h" +#include "../common/classes/rwlock.h" #include "unicode/ustring.h" #include "unicode/uchar.h" #include "unicode/ucnv.h" @@ -118,7 +118,7 @@ static void getVersions(const string& configInfo, ObjectsArray& versions charset cs; IntlUtil::initAsciiCharset(&cs); - AutoPtr ascii = Jrd::CharSet::createInstance(*getDefaultMemoryPool(), 0, &cs); + AutoPtr ascii(Jrd::CharSet::createInstance(*getDefaultMemoryPool(), 0, &cs)); IntlUtil::SpecificAttributesMap config; IntlUtil::parseSpecificAttributes(ascii, configInfo.length(),