From 3e3d713b3bdba22d671b11ae70269a29fa502a3a Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 23 Oct 2011 17:53:59 -0700 Subject: [PATCH] Fixes to CoreLib and CoreLibExe. --- Sources/Plasma/CoreLib/hsCritSect.cpp | 19 +++++++++++++++++++ Sources/Plasma/CoreLib/hsCritSect.h | 3 +++ Sources/Plasma/CoreLib/hsMatrix44.cpp | 6 ++++-- Sources/Plasma/CoreLibExe/hsExeError.cpp | 10 +++++++--- Sources/Plasma/CoreLibExe/hsExeMalloc.cpp | 4 +++- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/Sources/Plasma/CoreLib/hsCritSect.cpp b/Sources/Plasma/CoreLib/hsCritSect.cpp index 4dc347cb..93e299b5 100644 --- a/Sources/Plasma/CoreLib/hsCritSect.cpp +++ b/Sources/Plasma/CoreLib/hsCritSect.cpp @@ -80,4 +80,23 @@ void CCritSect::Enter () { void CCritSect::Leave () { LeaveCriticalSection(&m_handle); } +#elif HS_BUILD_FOR_UNIX +//=========================================================================== +CCritSect::CCritSect () { + m_handle = PTHREAD_MUTEX_INITIALIZER; +} + +//=========================================================================== +CCritSect::~CCritSect () { +} + +//=========================================================================== +void CCritSect::Enter () { + pthread_mutex_lock(&m_handle); +} + +//=========================================================================== +void CCritSect::Leave () { + pthread_mutex_unlock(&m_handle); +} #endif diff --git a/Sources/Plasma/CoreLib/hsCritSect.h b/Sources/Plasma/CoreLib/hsCritSect.h index 7d5193d9..803ef6dc 100644 --- a/Sources/Plasma/CoreLib/hsCritSect.h +++ b/Sources/Plasma/CoreLib/hsCritSect.h @@ -61,6 +61,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #ifdef HS_BUILD_FOR_WIN32 typedef CRITICAL_SECTION CritSectHandle; +#elif HS_BUILD_FOR_UNIX +# include +typedef pthread_mutex_t CritSectHandle; #else # error "CCritSect: Not implemented on this platform" #endif diff --git a/Sources/Plasma/CoreLib/hsMatrix44.cpp b/Sources/Plasma/CoreLib/hsMatrix44.cpp index 3aad0d4f..30a6bfd1 100644 --- a/Sources/Plasma/CoreLib/hsMatrix44.cpp +++ b/Sources/Plasma/CoreLib/hsMatrix44.cpp @@ -427,7 +427,8 @@ void hsMatrix44::MakeZRotation(hsScalar radians) // hsMatrix44& hsMatrix44::Make(const hsPoint3* f, const hsPoint3* at, const hsVector3* up) { - MakeTranslateMat(&hsVector3(f->fX, f->fY, f->fZ)); + hsVector3 trans(f->fX, f->fY, f->fZ); + MakeTranslateMat(&trans); hsVector3 back (f,at); // Z back.Normalize(); @@ -458,7 +459,8 @@ hsMatrix44& hsMatrix44::Make(const hsPoint3* f, const hsPoint3* at, const hsVect // hsMatrix44& hsMatrix44::MakeUpPreserving(const hsPoint3* f, const hsPoint3* at, const hsVector3* up) { - MakeTranslateMat(&hsVector3(f->fX, f->fY, f->fZ)); + hsVector3 trans(f->fX, f->fY, f->fZ); + MakeTranslateMat(&trans); hsVector3 topHead = *up; topHead.Normalize(); diff --git a/Sources/Plasma/CoreLibExe/hsExeError.cpp b/Sources/Plasma/CoreLibExe/hsExeError.cpp index 5f1e6ba3..ef31f3b7 100644 --- a/Sources/Plasma/CoreLibExe/hsExeError.cpp +++ b/Sources/Plasma/CoreLibExe/hsExeError.cpp @@ -56,7 +56,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com ***/ static bool s_skipBreak; +#if HS_BUILD_FOR_WIN32 static CCritSect * s_critsect; +#endif // User options static bool s_options[kNumErrorOptions]; @@ -69,12 +71,14 @@ static bool s_options[kNumErrorOptions]; ***/ //=========================================================================== +#if HS_BUILD_FOR_WIN32 AUTO_INIT_FUNC(hsExeErrorInit) { // The critical section has to be initialized // before program startup and never freed static byte rawMemory[sizeof(CCritSect)]; s_critsect = new(rawMemory) CCritSect; } +#endif //============================================================================ static void DoAssert (int line, const char file[], const char msg[]) { @@ -118,7 +122,7 @@ static void DoAssert (int line, const char file[], const char msg[]) { //============================================================================ #pragma auto_inline(off) -void __cdecl ErrorFatal (int line, const char file[], const char fmt[], ...) { +void CDECL ErrorFatal (int line, const char file[], const char fmt[], ...) { char buffer[256]; va_list args; va_start(args, fmt); @@ -135,7 +139,7 @@ void __cdecl ErrorFatal (int line, const char file[], const char fmt[], ...) { //============================================================================ #pragma auto_inline(off) -void __cdecl ErrorAssert (int line, const char file[], const char fmt[], ...) { +void CDECL ErrorAssert (int line, const char file[], const char fmt[], ...) { char buffer[256]; va_list args; va_start(args, fmt); @@ -250,7 +254,7 @@ void DebugMsgV (const char fmt[], va_list args) { } //============================================================================ -void __cdecl DebugMsg (const char fmt[], ...) { +void CDECL DebugMsg (const char fmt[], ...) { #ifdef HS_DEBUGGING va_list args; diff --git a/Sources/Plasma/CoreLibExe/hsExeMalloc.cpp b/Sources/Plasma/CoreLibExe/hsExeMalloc.cpp index 86bdc875..cb905b1f 100644 --- a/Sources/Plasma/CoreLibExe/hsExeMalloc.cpp +++ b/Sources/Plasma/CoreLibExe/hsExeMalloc.cpp @@ -591,14 +591,16 @@ void * MemRealloc (void * ptr, unsigned bytes, unsigned flags, const char file[] //=========================================================================== unsigned MemSize (void * ptr) { ASSERT(ptr); - unsigned result; + unsigned result = 0; #ifdef MEM_DEBUG const _CrtMemBlockHeader * pHead = pHdr(ptr); unsigned block = pHead->nBlockUse; #endif +#if HS_BUILD_FOR_WIN32 result = (unsigned)_msize_dbg(ptr, block); +#endif return result; }