Browse Source

Corelib fixes for mingw support.

Darryl Pogue 13 years ago
parent
commit
942a007f4b
  1. 2
      Sources/Plasma/CoreLib/HeadSpin.cpp
  2. 12
      Sources/Plasma/CoreLib/hsConfig.h
  3. 36
      Sources/Plasma/CoreLib/hsMalloc.h
  4. 1
      Sources/Plasma/CoreLib/hsMemory.h
  5. 36
      Sources/Plasma/CoreLib/hsStlUtils.h
  6. 14
      Sources/Plasma/CoreLib/hsStream.cpp
  7. 6
      Sources/Plasma/CoreLib/hsTypes.h
  8. 70
      Sources/Plasma/CoreLib/hsUtils.h

2
Sources/Plasma/CoreLib/HeadSpin.cpp

@ -37,7 +37,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#endif #endif
#if HS_BUILD_FOR_WIN32 #if HS_BUILD_FOR_WIN32
#ifdef _MSC_VER
# include <crtdbg.h> /* for _RPT_BASE */ # include <crtdbg.h> /* for _RPT_BASE */
#endif
# define WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN
# define WIN32_EXTRA_LEAN # define WIN32_EXTRA_LEAN
# include <windows.h> // For OutputDebugString() # include <windows.h> // For OutputDebugString()

12
Sources/Plasma/CoreLib/hsConfig.h

@ -74,8 +74,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
// 4018: signed/unsigned mismatch // 4018: signed/unsigned mismatch
// 4786: 255 character debug limit // 4786: 255 character debug limit
// 4284: STL template defined operator-> for a class it doesn't make sense for (int, etc) // 4284: STL template defined operator-> for a class it doesn't make sense for (int, etc)
#if !__MWERKS__ // 4800: 'int': forcing value to bool 'true' or 'false' (performance warning)
#pragma warning( disable : 4305 4503 4018 4786 4284) #ifdef _MSC_VER
#pragma warning( disable : 4305 4503 4018 4786 4284 4800)
#endif #endif
// VC++ version greater than 6.0, must be building for .NET // VC++ version greater than 6.0, must be building for .NET
@ -88,6 +89,13 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#endif #endif
#ifdef HS_BUILD_FOR_WIN32
# define CDECL __cdecl
#else
# define CDECL
#endif
/////////////////////Debugging Defines /////////////////////////////////// /////////////////////Debugging Defines ///////////////////////////////////
#if (defined(_DEBUG)||defined(UNIX_DEBUG)) && !defined(HS_DISABLE_ASSERT) #if (defined(_DEBUG)||defined(UNIX_DEBUG)) && !defined(HS_DISABLE_ASSERT)

36
Sources/Plasma/CoreLib/hsMalloc.h

@ -97,21 +97,43 @@ void MemSetColor (unsigned short color);
#ifdef __cplusplus #ifdef __cplusplus
#include <new>
#ifndef _MSC_VER
#define THROW(x) throw(x)
#define THROW_EMPTY throw()
#else
#define THROW(x)
#define THROW_EMPTY
#endif
// standard new and delete // standard new and delete
inline void * __cdecl operator new (size_t bytes) { return MemAlloc((unsigned)bytes, 0, __FILE__, __LINE__); } inline void* CDECL operator new (size_t bytes) THROW(std::bad_alloc)
inline void __cdecl operator delete (void * ptr) { MemFree(ptr, 0); } { return MemAlloc((unsigned)bytes, 0, __FILE__, __LINE__); }
inline void* CDECL operator new [](size_t bytes) THROW(std::bad_alloc)
{ return MemAlloc((unsigned)bytes, 0, __FILE__, __LINE__); }
inline void CDECL operator delete (void * ptr) THROW_EMPTY
{ MemFree(ptr, 0); }
inline void CDECL operator delete [](void * ptr) THROW_EMPTY
{ MemFree(ptr, 0); }
// memcheck-friendly new // memcheck-friendly new
inline void * __cdecl operator new (size_t bytes, const char file[], unsigned line) { return MemAlloc((unsigned)bytes, 0, file, line); } inline void* CDECL operator new (size_t bytes, const char file[], unsigned line)
inline void __cdecl operator delete (void * ptr, const char [] , unsigned) { return MemFree(ptr, 0); } { return MemAlloc((unsigned)bytes, 0, file, line); }
inline void* CDECL operator new [](size_t bytes, const char file[], unsigned line)
{ return MemAlloc((unsigned)bytes, 0, file, line); }
inline void CDECL operator delete (void * ptr, const char [], unsigned)
{ return MemFree(ptr, 0); }
inline void CDECL operator delete [](void * ptr, const char [], unsigned)
{ return MemFree(ptr, 0); }
#define TRACKED_NEW new(__FILE__, __LINE__) #define TRACKED_NEW new(__FILE__, __LINE__)
// placement new // placement new
#ifndef __PLACEMENT_NEW_INLINE #if defined(_MSC_VER) && !defined(__PLACEMENT_NEW_INLINE)
#define __PLACEMENT_NEW_INLINE #define __PLACEMENT_NEW_INLINE
inline void * __cdecl operator new (size_t, void * ptr) { return ptr; } inline void* CDECL operator new (size_t, void * ptr) { return ptr; }
inline void __cdecl operator delete (void *, void *) {} inline void CDECL operator delete (void *, void *) {}
#endif // ifndef __PLACEMENT_NEW_INLINE #endif // ifndef __PLACEMENT_NEW_INLINE
#endif // ifdef __cplusplus #endif // ifdef __cplusplus

1
Sources/Plasma/CoreLib/hsMemory.h

@ -27,6 +27,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define hsMemoryDefined #define hsMemoryDefined
#include "hsTypes.h" #include "hsTypes.h"
#include "hsMalloc.h"
//#include "hsTemplates.h" //#include "hsTemplates.h"
class HSMemory { class HSMemory {

36
Sources/Plasma/CoreLib/hsStlUtils.h

@ -27,7 +27,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define hsStlUtils_h_inc #define hsStlUtils_h_inc
#include "hsUtils.h" #include "hsUtils.h"
#include <xmemory> //#include <xmemory>
#include <functional> #include <functional>
#include <algorithm> #include <algorithm>
#include <string> #include <string>
@ -46,20 +46,20 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
// TEMPLATE CLASS cyallocator // TEMPLATE CLASS cyallocator
template<class _Ty> template<class _Ty>
class cyallocator class cyallocator
: public std::_Allocator_base<_Ty> : public std::allocator<_Ty>
{ // generic cyallocator for objects of class _Ty { // generic cyallocator for objects of class _Ty
public: public:
typedef std::_Allocator_base<_Ty> _Mybase; typedef std::allocator<_Ty> _Mybase;
typedef typename _Mybase::value_type value_type; typedef typename _Mybase::value_type value_type;
typedef value_type _FARQ *pointer; typedef value_type* pointer;
typedef value_type _FARQ& reference; typedef value_type& reference;
typedef const value_type _FARQ *const_pointer; typedef const value_type* const_pointer;
typedef const value_type _FARQ& const_reference; typedef const value_type& const_reference;
typedef _SIZT size_type; typedef size_t size_type;
typedef _PDFT difference_type; typedef ptrdiff_t difference_type;
template<class _Other> template<class _Other>
struct rebind struct rebind
@ -106,7 +106,7 @@ public:
return (pointer)ALLOC(_Count * sizeof(_Ty)); return (pointer)ALLOC(_Count * sizeof(_Ty));
} }
pointer allocate(size_type _Count, const void _FARQ *) pointer allocate(size_type _Count, const void*)
{ // allocate array of _Count elements, ignore hint { // allocate array of _Count elements, ignore hint
return (allocate(_Count)); return (allocate(_Count));
} }
@ -121,9 +121,9 @@ public:
std::_Destroy(_Ptr); std::_Destroy(_Ptr);
} }
_SIZT max_size() const size_t max_size() const
{ // estimate maximum array size { // estimate maximum array size
_SIZT _Count = (_SIZT)(-1) / sizeof (_Ty); size_t _Count = (size_t)(-1) / sizeof (_Ty);
return (0 < _Count ? _Count : 1); return (0 < _Count ? _Count : 1);
} }
}; };
@ -143,13 +143,17 @@ template<class _Ty,
return (false); return (false);
} }
#ifndef _CRTIMP2
#define _CRTIMP2
#endif
// CLASS cyallocator<void> // CLASS cyallocator<void>
template<> class _CRTIMP2 cyallocator<void> template<> class _CRTIMP2 cyallocator<void>
{ // generic cyallocator for type void { // generic cyallocator for type void
public: public:
typedef void _Ty; typedef void _Ty;
typedef _Ty _FARQ *pointer; typedef _Ty* pointer;
typedef const _Ty _FARQ *const_pointer; typedef const _Ty* const_pointer;
typedef _Ty value_type; typedef _Ty value_type;
template<class _Other> template<class _Other>
@ -264,12 +268,12 @@ struct delete_map_ptr_T
struct stricmp_less : public std::binary_function<std::string, std::string, bool> struct stricmp_less : public std::binary_function<std::string, std::string, bool>
{ {
bool operator()(const std::string & _X, const std::string & _Y) const bool operator()(const std::string & _X, const std::string & _Y) const
{return ( _stricmp(_X.c_str(),_Y.c_str()) < 0); } {return ( stricmp(_X.c_str(),_Y.c_str()) < 0); }
}; };
struct wstricmp_less : public std::binary_function<std::wstring, std::wstring, bool> struct wstricmp_less : public std::binary_function<std::wstring, std::wstring, bool>
{ {
bool operator()(const std::wstring & _X, const std::wstring & _Y) const bool operator()(const std::wstring & _X, const std::wstring & _Y) const
{return ( _wcsicmp(_X.c_str(),_Y.c_str()) < 0); } {return ( wcsicmp(_X.c_str(),_Y.c_str()) < 0); }
}; };
// struct stricmp_char_traits // struct stricmp_char_traits

14
Sources/Plasma/CoreLib/hsStream.cpp

@ -416,15 +416,15 @@ hsBool hsStream::GetToken(char *s, UInt32 maxLen, const char beginComment, const
s[k] = 0; s[k] = 0;
if( (k > 0)&&!_stricmp(s, "skip") ) if( (k > 0)&&!stricmp(s, "skip") )
{ {
int depth = 1; int depth = 1;
while( depth && GetToken(s, maxLen, beginComment, endCom) ) while( depth && GetToken(s, maxLen, beginComment, endCom) )
{ {
if( !_stricmp(s, "skip") ) if( !stricmp(s, "skip") )
depth++; depth++;
else else
if( !_stricmp(s, "piks") ) if( !stricmp(s, "piks") )
depth--; depth--;
} }
return GetToken(s, maxLen, beginComment, endCom); return GetToken(s, maxLen, beginComment, endCom);
@ -466,15 +466,15 @@ hsBool hsStream::ReadLn(char *s, UInt32 maxLen, const char beginComment, const c
s[k] = 0; s[k] = 0;
if( (k > 0)&&!_stricmp(s, "skip") ) if( (k > 0)&&!stricmp(s, "skip") )
{ {
int depth = 1; int depth = 1;
while( depth && ReadLn(s, maxLen, beginComment, endCom) ) while( depth && ReadLn(s, maxLen, beginComment, endCom) )
{ {
if( !_stricmp(s, "skip") ) if( !stricmp(s, "skip") )
depth++; depth++;
else else
if( !_stricmp(s, "piks") ) if( !stricmp(s, "piks") )
depth--; depth--;
} }
return ReadLn(s, maxLen, beginComment, endCom); return ReadLn(s, maxLen, beginComment, endCom);
@ -987,7 +987,7 @@ hsBool hsUNIXStream::Open(const char *name, const char *mode)
hsBool hsUNIXStream::Open(const wchar *name, const wchar *mode) hsBool hsUNIXStream::Open(const wchar *name, const wchar *mode)
{ {
fPosition = 0; fPosition = 0;
fRef = _wfopen(name, mode); fRef = hsWFopen(name, mode);
return (fRef) ? true : false; return (fRef) ? true : false;
} }

6
Sources/Plasma/CoreLib/hsTypes.h

@ -521,8 +521,8 @@ hsDebugMessageProc hsSetDebugMessageProc(hsDebugMessageProc newProc);
extern hsDebugMessageProc gHSStatusProc; extern hsDebugMessageProc gHSStatusProc;
hsDebugMessageProc hsSetStatusMessageProc(hsDebugMessageProc newProc); hsDebugMessageProc hsSetStatusMessageProc(hsDebugMessageProc newProc);
void __cdecl ErrorAssert (int line, const char file[], const char fmt[], ...); void CDECL ErrorAssert (int line, const char file[], const char fmt[], ...);
void __cdecl ErrorFatal (int line, const char file[], const char fmt[], ...); void CDECL ErrorFatal (int line, const char file[], const char fmt[], ...);
void ErrorMinimizeAppWindow (); void ErrorMinimizeAppWindow ();
enum EErrorOption { enum EErrorOption {
@ -561,7 +561,7 @@ void DebugMsgV (const char fmt[], va_list args);
#define ASSERT(expr) NULL_STMT #define ASSERT(expr) NULL_STMT
#define ASSERTMSG(expr, msg) NULL_STMT #define ASSERTMSG(expr, msg) NULL_STMT
#define FATAL(msg) NULL_STMT #define FATAL(msg) NULL_STMT
#define DEBUG_MSG NULL_STMT #define DEBUG_MSG (void)
#define DEBUG_MSGV NULL_STMT #define DEBUG_MSGV NULL_STMT
#define DEBUG_BREAK_IF_DEBUGGER_PRESENT NULL_STMT #define DEBUG_BREAK_IF_DEBUGGER_PRESENT NULL_STMT

70
Sources/Plasma/CoreLib/hsUtils.h

@ -45,17 +45,17 @@ char * hsFormatStr(const char * fmt, ...); // You are responsible for returned
char * hsFormatStrV(const char * fmt, va_list args); // You are responsible for returned memory. char * hsFormatStrV(const char * fmt, va_list args); // You are responsible for returned memory.
// Use "correct" stricmp based on the selected compiler / library // Use "correct" stricmp based on the selected compiler / library
#ifdef _MSC_VER #if HS_BUILD_FOR_WIN32
#define stricmp _stricmp # define stricmp _stricmp
#define strnicmp _strnicmp # define strnicmp _strnicmp
#define wcsicmp _wcsicmp # define wcsicmp _wcsicmp
#define wcsnicmp _wcsnicmp # define wcsnicmp _wcsnicmp
#define strlwr _strlwr # define strlwr _strlwr
#else #else
#define stricmp strcasecmp # define stricmp strcasecmp
#define strnicmp strncasecmp # define strnicmp strncasecmp
#define wcsicmp wcscasecmp # define wcsicmp wcscasecmp
#define wcsnicmp wcsncasecmp # define wcsnicmp wcsncasecmp
#endif #endif
@ -125,41 +125,31 @@ inline hsBool hsCompare(hsScalar a, hsScalar b, hsScalar delta=0.0001)
#if HS_BUILD_FOR_WIN32 #if HS_BUILD_FOR_WIN32
#define hsVsnprintf _vsnprintf // This is for Windows
#define hsVsnwprintf _vsnwprintf # define hsVsnprintf _vsnprintf
#define snprintf _snprintf # define hsVsnwprintf _vsnwprintf
#define snwprintf _snwprintf # define hsSnprintf _snprintf
#define hsSnprintf snprintf # define hsSnwprintf _snwprintf
#define hsSnwprintf snwprintf
#else
#define hsVsnprintf vsnprintf
#define hsWvnwprintf vsnwprintf
#define hsSnprintf snprintf
#define hsSnwprintf snwprintf
#define _snprintf snprintf
#define _snwprintf snwprintf
#endif
#if HS_BUILD_FOR_UNIX || HS_BUILD_FOR_PS2
#define _stricmp(s1, s2) strcasecmp(s1, s2) # define snprintf _snprintf
#define _strnicmp(s1, s2, n) strncasecmp(s1, s2, n) # define snwprintf _snwprintf
#define stricmp(s1, s2) strcasecmp(s1, s2) # define swprintf _snwprintf
#define strnicmp(s1, s2, n) strncasecmp(s1, s2, n)
#define _fileno(n) fileno(n) # ifndef fileno
# define fileno(__F) _fileno(__F)
# endif
# define hsWFopen(name, mode) _wfopen(name, mode)
#else
// This is for Unix, Linux, OSX, etc.
# define hsVsnprintf vsnprintf
# define hsVsnwprintf vswprintf
# define hsSnprintf snprintf
# define hsSnwprintf swprintf
#elif HS_BUILD_FOR_MAC // HS_BUILD_FOR_UNIX || HS_BUILD_FOR_PS2 # define hsWFopen(name, mode) fopen(hsWStringToString(name), hsWStringToString(mode))
#endif
int hsStrcasecmp(const char s1[], const char s2[]);
int hsStrncasecmp(const char s1[], const char s2[], int n);
#define _stricmp(s1, s2) hsStrcasecmp(s1, s2)
#define _strnicmp(s1, s2, n) hsStrncasecmp(s1, s2, n)
#endif // HS_BUILD_FOR_UNIX || HS_BUILD_FOR_PS2
///////////////////////////// /////////////////////////////
// Physical memory functions // Physical memory functions

Loading…
Cancel
Save