diff options
author | Lukas Zeller <luz@synthesis.ch> | 2009-10-02 16:24:02 +0200 |
---|---|---|
committer | Lukas Zeller <luz@synthesis.ch> | 2009-10-03 13:42:56 +0200 |
commit | 33b024261069a123031f91c868cc6f6091902d23 (patch) | |
tree | 7cfcc8df5a7d3653ef1c0532aad97f975e7e6906 /src | |
parent | 0a54093d1c8d1c5b25ec4fd42189b990d9d769f5 (diff) |
64 bit: adjusted generic_types.h to make sure uInt32/sInt32 IS 32bits
(I am compiling under Snow Leopard 10.6, which by default creates
64-bit debug builds. Deployment builds are still 10.4/32-bit)
So far, a trick was in use which defined uInt32 such that
it had 64bit apparently to avoid some issues.
However, that caused other issues, like MD5 not working any
more (took me several hours to track down a server auth
error to this - thought is was my unilib changes).
Anyway, this is UGLY - xxx32 must be 32 bits under all
circumstances IMHO, or it is totally misleading.
Steps to improve the situation:
- uInt32/sInt32 now is really 32bit
- new types uIntArch/sIntArch are defined to designate
"architecture width integers" (but always 32bits or
more).
- UINT32_HAS_64BITS_ON_ARCH64 can be defined (now
commented out) to get back to the situation we
had until now.
- used uIntArch in platform_thread.h now.
- adapted platform_thread.cpp in unix_common
to be 64bit compatible (using uIntArch).
Is ok for 32/64bit Mac, should be as well for Linux.
- Codewarrior is 32bit only anyway, so uIntArch
remains 32bit and implementation does not need
to change. Same for other non-64bit capable
platforms.
- Some uInt32 replaced by uIntArch where appropriate
in other files. Note that generally %ld printfs
should be fed xIntArch, not xInt32, because "l"
means long and is 64bit on 64bit architecture.
- pointer that is used in sessionID generation is 64bit
on 64bit architectures, added needed casts.
The uInt32 being 64 bit issue surfaced with md5, which did
return wrong results. Added extra safeguarding in MD5 to make
sure it is stable in all cases:
- defines own types now, as in current 64bit builds
MD5 was not working because SYSYNC_UINT4 could
get 64bit (with UINT32_HAS_64BITS_ON_ARCH64 set
in generic_types.h)
- Added md5::dotest() in syncappbase when
MD5_TEST_FUNCS is defined.
Diffstat (limited to 'src')
-rw-r--r-- | src/DB_interfaces/odbc_db/odbcapiagent.cpp | 2 | ||||
-rwxr-xr-x | src/DB_interfaces/odbc_db/odbcapids.cpp | 2 | ||||
-rw-r--r-- | src/Transport_interfaces/engine/enginesessiondispatch.cpp | 2 | ||||
-rwxr-xr-x | src/platform_adapters/platform_thread.h | 8 | ||||
-rwxr-xr-x | src/platform_adapters/unix_common/platform_thread.cpp | 15 | ||||
-rwxr-xr-x | src/sysync/stdlogicds.cpp | 2 | ||||
-rwxr-xr-x | src/sysync/stringutils.cpp | 5 | ||||
-rwxr-xr-x | src/sysync/syncappbase.cpp | 3 | ||||
-rwxr-xr-x | src/sysync/syncsessiondispatch.cpp | 2 | ||||
-rwxr-xr-x | src/sysync/sysync_md5.cpp | 8 | ||||
-rwxr-xr-x | src/sysync/sysync_md5.h | 8 | ||||
-rwxr-xr-x | src/sysync_SDK/Sources/generic_types.h | 44 |
12 files changed, 58 insertions, 43 deletions
diff --git a/src/DB_interfaces/odbc_db/odbcapiagent.cpp b/src/DB_interfaces/odbc_db/odbcapiagent.cpp index b2f9795..7c48da4 100644 --- a/src/DB_interfaces/odbc_db/odbcapiagent.cpp +++ b/src/DB_interfaces/odbc_db/odbcapiagent.cpp @@ -1964,7 +1964,7 @@ SQLHDBC TODBCApiAgent::getODBCConnectionHandle(void) throw; } } - PDEBUGPRINTFX(DBG_DBAPI+DBG_EXOTIC,("Session: using connection handle 0x%lX",(uInt32)fODBCConnectionHandle)); + PDEBUGPRINTFX(DBG_DBAPI+DBG_EXOTIC,("Session: using connection handle 0x%lX",(uIntArch)fODBCConnectionHandle)); return fODBCConnectionHandle; } // TODBCApiAgent::getODBCConnectionHandle diff --git a/src/DB_interfaces/odbc_db/odbcapids.cpp b/src/DB_interfaces/odbc_db/odbcapids.cpp index 50b661c..7b4e764 100755 --- a/src/DB_interfaces/odbc_db/odbcapids.cpp +++ b/src/DB_interfaces/odbc_db/odbcapids.cpp @@ -849,7 +849,7 @@ SQLHDBC TODBCApiDS::getODBCConnectionHandle(void) PDEBUGPRINTFX(DBG_DBAPI+DBG_EXOTIC,("Datastore %s does not own a DB connection yet -> pulling connection from session level",getName())); fODBCConnectionHandle = fAgentP->pullODBCConnectionHandle(); } - PDEBUGPRINTFX(DBG_DBAPI+DBG_EXOTIC,("Datastore %s: using connection handle 0x%lX",getName(),(uInt32)fODBCConnectionHandle)); + PDEBUGPRINTFX(DBG_DBAPI+DBG_EXOTIC,("Datastore %s: using connection handle 0x%lX",getName(),(uIntArch)fODBCConnectionHandle)); return fODBCConnectionHandle; } // TODBCApiDS::getODBCConnectionHandle diff --git a/src/Transport_interfaces/engine/enginesessiondispatch.cpp b/src/Transport_interfaces/engine/enginesessiondispatch.cpp index d5422b0..3b9df70 100644 --- a/src/Transport_interfaces/engine/enginesessiondispatch.cpp +++ b/src/Transport_interfaces/engine/enginesessiondispatch.cpp @@ -337,7 +337,7 @@ TSyError TServerEngineInterface::OpenSessionInternal(SessionH &aNewSessionH, uIn time(NULL); sid = ((sid >> 16) & 0xFFFF) + ((sid << 47) & 0x7FFF000000000000LL) + // aaaa00000000dddd - (((uInt32)sessionHandleP) << 16); // 0000bbbbcccc0000 + ((((uIntPtr)sessionHandleP)&0xFFFFFFFF) << 16); // 0000bbbbcccc0000 // - make a string of it StringObjPrintf(SessionIDString,"%lld",sid); } diff --git a/src/platform_adapters/platform_thread.h b/src/platform_adapters/platform_thread.h index 26c6dde..487eaf0 100755 --- a/src/platform_adapters/platform_thread.h +++ b/src/platform_adapters/platform_thread.h @@ -34,9 +34,9 @@ namespace sysync { // get id of the running process -uInt32 myProcessID(); +uIntArch myProcessID(); // get id of the running thread -uInt32 myThreadID(); +uIntArch myThreadID(); class TThreadObject; // forward @@ -55,12 +55,12 @@ public: // starts thread (or re-starts it again after termination) bool launch( TThreadFunc aThreadFunc=NULL, // the function to execute in the thread - uInt32 aThreadFuncParam=0, // a parameter to pass to the thread + uIntArch aThreadFuncParam=0, // a parameter to pass to the thread size_t aStackSize=0, // if 0, default stack size is used bool aAutoDispose=false // if true, the thread object will dispose itself when thread has finished running ); // get thread ID - uInt32 getid(void); + uIntArch getid(void); // soft-terminates thread (sets a flag which requests execute() to terminate void terminate(void) { fTerminationRequested=true; }; // hard (emergency) terminate (aborts processing on the OS level) diff --git a/src/platform_adapters/unix_common/platform_thread.cpp b/src/platform_adapters/unix_common/platform_thread.cpp index fb915da..25829c1 100755 --- a/src/platform_adapters/unix_common/platform_thread.cpp +++ b/src/platform_adapters/unix_common/platform_thread.cpp @@ -28,16 +28,15 @@ namespace sysync { - // get id of the running process -uInt32 myProcessID() { - return (uInt32)getpid(); +uIntArch myProcessID() { + return (uIntArch)getpid(); } // myProcessID // get id of the running thread -uInt32 myThreadID() { - return (uInt32)pthread_self(); +uIntArch myThreadID() { + return (uIntArch)pthread_self(); } // myThreadID @@ -96,7 +95,7 @@ TThreadObject::~TThreadObject() // contain the platform error code for the failure to start the thread bool TThreadObject::launch( TThreadFunc aThreadFunc, // the function to execute in the thread - uInt32 aThreadFuncParam, // a parameter to pass to the thread + uIntArch aThreadFuncParam, // a parameter to pass to the thread size_t aStackSize, // if 0, default stack size is used bool aAutoDispose // if true, the thread object will dispose itself when thread has finished running ) @@ -135,8 +134,8 @@ bool TThreadObject::launch( } // TThreadObject::launch -uInt32 TThreadObject::getid(void) { - return (uInt32)fPosixThread; +uIntArch TThreadObject::getid(void) { + return (uIntArch)fPosixThread; } // TThreadObject::getid diff --git a/src/sysync/stdlogicds.cpp b/src/sysync/stdlogicds.cpp index 9d7e7a8..d96b3d4 100755 --- a/src/sysync/stdlogicds.cpp +++ b/src/sysync/stdlogicds.cpp @@ -424,7 +424,7 @@ bool TStdLogicDS::threadedStartSync(void) // Note: ThreadMayChangeNow() has been posted already by startingThread() PDEBUGPRINTFX(DBG_HOT,("******* starting background thread for reading sync set...")); fStartSyncStatus.setStatusCode(200); // assume ok - if (!fStartSyncThread.launch(StartSyncThreadFunc,(uInt32)this)) { // pass datastoreP as param + if (!fStartSyncThread.launch(StartSyncThreadFunc,(uIntArch)this)) { // pass datastoreP as param // starting thread failed PDEBUGPRINTFX(DBG_ERROR,("******* Failed starting background thread for reading sync set")); return false; diff --git a/src/sysync/stringutils.cpp b/src/sysync/stringutils.cpp index d3cc1a6..e8dee1c 100755 --- a/src/sysync/stringutils.cpp +++ b/src/sysync/stringutils.cpp @@ -544,7 +544,10 @@ sInt16 HexStrToUIntPtr(const char *aStr, uIntPtr &aIntPtr, sInt16 aMaxDigits) #if __WORDSIZE == 64 return HexStrToULongLong(aStr, aIntPtr, aMaxDigits); #else - return HexStrToULong(aStr, aIntPtr, aMaxDigits); + uInt32 l; + sInt16 n = HexStrToULong(aStr, l, aMaxDigits); + aIntPtr = (uIntPtr)l; + return n; #endif } // HexStrToUIntPtr diff --git a/src/sysync/syncappbase.cpp b/src/sysync/syncappbase.cpp index 4232448..42ed37f 100755 --- a/src/sysync/syncappbase.cpp +++ b/src/sysync/syncappbase.cpp @@ -1182,6 +1182,9 @@ TSyncAppBase::TSyncAppBase() : #endif sysync_glob_setanchor(this); #endif + #ifdef MD5_TEST_FUNCS + md5::dotest(); + #endif // init profiling TP_INIT(fTPInfo); TP_START(fTPInfo,TP_general); diff --git a/src/sysync/syncsessiondispatch.cpp b/src/sysync/syncsessiondispatch.cpp index 8a12ac8..fd1bee8 100755 --- a/src/sysync/syncsessiondispatch.cpp +++ b/src/sysync/syncsessiondispatch.cpp @@ -517,7 +517,7 @@ TSyncSessionHandle *TSyncSessionDispatch::CreateAndEnterServerSession(cAppCharP time(NULL); sid = ((sid >> 16) & 0xFFFF) + ((sid << 47) & 0x7FFF000000000000LL) + // aaaa00000000dddd - (((uInt32)sessionHP) << 16); // 0000bbbbcccc0000 + ((((uIntPtr)sessionHP)&0xFFFFFFFF) << 16); // 0000bbbbcccc0000 // - make a string of it StringObjPrintf(SessionIDString,"%lld",sid); } diff --git a/src/sysync/sysync_md5.cpp b/src/sysync/sysync_md5.cpp index ab65b34..7655e1b 100755 --- a/src/sysync/sysync_md5.cpp +++ b/src/sysync/sysync_md5.cpp @@ -104,14 +104,6 @@ void md5::Init (SYSYNC_MD5_CTX *context) /* initialize the padding space, don't know if this is necessary */ MD5_memset ((SYSYNC_POINTER)context->PADDING, 0, 64); context->PADDING[0]=0x80; - // note: this does the same thing as the original: - /* moved to SYSYNC_MD5_CTX as statics are not allowed in some environments - static uInt8 PADDING[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - */ } /* MD5 block update operation. Continues an MD5 message-digest diff --git a/src/sysync/sysync_md5.h b/src/sysync/sysync_md5.h index 5bf2fb6..f438996 100755 --- a/src/sysync/sysync_md5.h +++ b/src/sysync/sysync_md5.h @@ -50,7 +50,12 @@ typedef uInt8 *SYSYNC_POINTER; typedef uInt16 SYSYNC_UINT2; /* UINT4 defines a four byte word */ -typedef uInt32 SYSYNC_UINT4; +/* Note: "typedef uInt32 SYSYNC_UINT4;" is unreliable as uInt32 was 64bit in some weird builds */ +#if !defined(__WORDSIZE) || (__WORDSIZE < 32) +typedef unsigned long SYSYNC_UINT4; +#else +typedef unsigned int SYSYNC_UINT4; +#endif /* MD5 context. */ typedef struct { @@ -69,6 +74,7 @@ void Final (uInt8 [16], SYSYNC_MD5_CTX *); /* for test */ void String (const char *aString, char *s); void Print (uInt8 *digest, char * &s); +void dotest(void); #endif } // end namespace md5 diff --git a/src/sysync_SDK/Sources/generic_types.h b/src/sysync_SDK/Sources/generic_types.h index ebc4439..f5d4518 100755 --- a/src/sysync_SDK/Sources/generic_types.h +++ b/src/sysync_SDK/Sources/generic_types.h @@ -18,6 +18,13 @@ # include <stdint.h> #endif +#ifndef __WORDSIZE +/* 64 platforms should have this defined, so assume that */ +/* platforms without the define are 32 bit. */ +# define __WORDSIZE 32 +#endif + + #ifdef __cplusplus namespace sysync { #endif @@ -51,17 +58,27 @@ typedef unsigned long long uInt64; typedef signed long long sInt64; #endif -/* -#ifdef __PALM_OS__ -*/ +/* machine size integer, at least 32 bits */ +typedef unsigned long uIntArch; +typedef signed long sIntArch; + + +/* TODO, FIXME %%%% for now, we need uInt32 to be 64bit actually */ +//#define UINT32_HAS_64BITS_ON_ARCH64 1 + + +#if defined(UINT32_HAS_64BITS_ON_ARCH64) || defined(__PALM_OS__) || (__WORDSIZE < 32) +/* must use long to get a 32bit int (but gets 64bit in 64-bit architectures) */ typedef unsigned long uInt32; typedef signed long sInt32; -/* +#ifdef UINT32_HAS_64BITS_ON_ARCH64 + #warning "%%% UINT32_HAS_64BITS_ON_ARCH64 - which means that uInt32 is really 64bit: UGLY & DANGEROUS, please be careful" +#endif #else - typedef unsigned int uInt32; // according to the ILP32/LP64 std for all other platforms - typedef signed int sInt32; // %%%% requires some type cast fixing first %%%% +/* according to the ILP32/LP64 std for all other platforms, int is 32bit (and long is 64bit) */ +typedef unsigned int uInt32; +typedef signed int sInt32; #endif -*/ typedef unsigned short uInt16; typedef signed short sInt16; @@ -77,18 +94,13 @@ typedef signed long sIntPtr; #endif /* - application integers */ -typedef uInt32 bufferIndex; /* index into app buffers (small platforms may have 16bit here) */ -typedef uInt32 stringIndex; /* index into string (small platforms may have 16bit here) */ -typedef uInt32 stringSize; /* size of a string object */ -typedef uInt32 memSize; /* size of a memory buffer */ +typedef uIntArch bufferIndex; /* index into app buffers (small platforms may have 16bit here) */ +typedef uIntArch stringIndex; /* index into string (small platforms may have 16bit here) */ +typedef uIntArch stringSize; /* size of a string object */ +typedef uIntArch memSize; /* size of a memory buffer */ #endif /* HAVE_STDINT_H */ -#ifndef __WORDSIZE -/* 64 platforms should have this defined, so assume that */ -/* platforms without the define are 32 bit. */ -# define __WORDSIZE 32 -#endif /* undefined size types */ /* - application chars & pointers */ |