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
#if HS_BUILD_FOR_WIN32
#ifdef _MSC_VER
# include <crtdbg.h> /* for _RPT_BASE */
#endif
# define WIN32_LEAN_AND_MEAN
# define WIN32_EXTRA_LEAN
# 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
// 4786: 255 character debug limit
// 4284: STL template defined operator-> for a class it doesn't make sense for (int, etc)
#if !__MWERKS__
#pragma warning( disable : 4305 4503 4018 4786 4284)
// 4800: 'int': forcing value to bool 'true' or 'false' (performance warning)
#ifdef _MSC_VER
#pragma warning( disable : 4305 4503 4018 4786 4284 4800)
#endif
// 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
#ifdef HS_BUILD_FOR_WIN32
# define CDECL __cdecl
#else
# define CDECL
#endif
/////////////////////Debugging Defines ///////////////////////////////////
#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
#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
inline void * __cdecl operator new (size_t bytes) { return MemAlloc((unsigned)bytes, 0, __FILE__, __LINE__); }
inline void __cdecl operator delete (void * ptr) { MemFree(ptr, 0); }
inline void* CDECL operator new (size_t bytes) THROW(std::bad_alloc)
{ 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
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 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)
{ 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__)
// placement new
#ifndef __PLACEMENT_NEW_INLINE
#if defined(_MSC_VER) && !defined(__PLACEMENT_NEW_INLINE)
#define __PLACEMENT_NEW_INLINE
inline void * __cdecl operator new (size_t, void * ptr) { return ptr; }
inline void __cdecl operator delete (void *, void *) {}
inline void* CDECL operator new (size_t, void * ptr) { return ptr; }
inline void CDECL operator delete (void *, void *) {}
#endif // ifndef __PLACEMENT_NEW_INLINE
#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
#include "hsTypes.h"
#include "hsMalloc.h"
//#include "hsTemplates.h"
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
#include "hsUtils.h"
#include <xmemory>
//#include <xmemory>
#include <functional>
#include <algorithm>
#include <string>
@ -46,20 +46,20 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
// TEMPLATE CLASS cyallocator
template<class _Ty>
class cyallocator
: public std::_Allocator_base<_Ty>
: public std::allocator<_Ty>
{ // generic cyallocator for objects of class _Ty
public:
typedef std::_Allocator_base<_Ty> _Mybase;
typedef std::allocator<_Ty> _Mybase;
typedef typename _Mybase::value_type value_type;
typedef value_type _FARQ *pointer;
typedef value_type _FARQ& reference;
typedef const value_type _FARQ *const_pointer;
typedef const value_type _FARQ& const_reference;
typedef value_type* pointer;
typedef value_type& reference;
typedef const value_type* const_pointer;
typedef const value_type& const_reference;
typedef _SIZT size_type;
typedef _PDFT difference_type;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
template<class _Other>
struct rebind
@ -106,7 +106,7 @@ public:
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
return (allocate(_Count));
}
@ -121,9 +121,9 @@ public:
std::_Destroy(_Ptr);
}
_SIZT max_size() const
size_t max_size() const
{ // estimate maximum array size
_SIZT _Count = (_SIZT)(-1) / sizeof (_Ty);
size_t _Count = (size_t)(-1) / sizeof (_Ty);
return (0 < _Count ? _Count : 1);
}
};
@ -143,13 +143,17 @@ template<class _Ty,
return (false);
}
#ifndef _CRTIMP2
#define _CRTIMP2
#endif
// CLASS cyallocator<void>
template<> class _CRTIMP2 cyallocator<void>
{ // generic cyallocator for type void
public:
typedef void _Ty;
typedef _Ty _FARQ *pointer;
typedef const _Ty _FARQ *const_pointer;
typedef _Ty* pointer;
typedef const _Ty* const_pointer;
typedef _Ty value_type;
template<class _Other>
@ -264,12 +268,12 @@ struct delete_map_ptr_T
struct stricmp_less : public std::binary_function<std::string, std::string, bool>
{
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>
{
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

14
Sources/Plasma/CoreLib/hsStream.cpp

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

6
Sources/Plasma/CoreLib/hsTypes.h

@ -521,8 +521,8 @@ hsDebugMessageProc hsSetDebugMessageProc(hsDebugMessageProc newProc);
extern hsDebugMessageProc gHSStatusProc;
hsDebugMessageProc hsSetStatusMessageProc(hsDebugMessageProc newProc);
void __cdecl ErrorAssert (int line, const char file[], const char fmt[], ...);
void __cdecl ErrorFatal (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 ErrorMinimizeAppWindow ();
enum EErrorOption {
@ -561,7 +561,7 @@ void DebugMsgV (const char fmt[], va_list args);
#define ASSERT(expr) NULL_STMT
#define ASSERTMSG(expr, msg) NULL_STMT
#define FATAL(msg) NULL_STMT
#define DEBUG_MSG NULL_STMT
#define DEBUG_MSG (void)
#define DEBUG_MSGV 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.
// Use "correct" stricmp based on the selected compiler / library
#ifdef _MSC_VER
#define stricmp _stricmp
#define strnicmp _strnicmp
#define wcsicmp _wcsicmp
#define wcsnicmp _wcsnicmp
#define strlwr _strlwr
#if HS_BUILD_FOR_WIN32
# define stricmp _stricmp
# define strnicmp _strnicmp
# define wcsicmp _wcsicmp
# define wcsnicmp _wcsnicmp
# define strlwr _strlwr
#else
#define stricmp strcasecmp
#define strnicmp strncasecmp
#define wcsicmp wcscasecmp
#define wcsnicmp wcsncasecmp
# define stricmp strcasecmp
# define strnicmp strncasecmp
# define wcsicmp wcscasecmp
# define wcsnicmp wcsncasecmp
#endif
@ -125,41 +125,31 @@ inline hsBool hsCompare(hsScalar a, hsScalar b, hsScalar delta=0.0001)
#if HS_BUILD_FOR_WIN32
#define hsVsnprintf _vsnprintf
#define hsVsnwprintf _vsnwprintf
#define snprintf _snprintf
#define snwprintf _snwprintf
#define hsSnprintf snprintf
#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
// This is for Windows
# define hsVsnprintf _vsnprintf
# define hsVsnwprintf _vsnwprintf
# define hsSnprintf _snprintf
# define hsSnwprintf _snwprintf
#define _stricmp(s1, s2) strcasecmp(s1, s2)
#define _strnicmp(s1, s2, n) strncasecmp(s1, s2, n)
#define stricmp(s1, s2) strcasecmp(s1, s2)
#define strnicmp(s1, s2, n) strncasecmp(s1, s2, n)
# define snprintf _snprintf
# define snwprintf _snwprintf
# define swprintf _snwprintf
#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
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)
# define hsWFopen(name, mode) fopen(hsWStringToString(name), hsWStringToString(mode))
#endif
#endif // HS_BUILD_FOR_UNIX || HS_BUILD_FOR_PS2
/////////////////////////////
// Physical memory functions

Loading…
Cancel
Save