1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-20 04:26:03 +08:00

Fix memoverride.cpp compilation

This commit is contained in:
GAMMACASE
2023-09-09 11:07:57 +03:00
committed by Nicholas Hastings
parent 6e2878fb19
commit ae308873b7

View File

@ -76,6 +76,11 @@ inline void *ReallocUnattributed( void *pMem, size_t nSize )
// under linux this malloc() overrides the libc malloc() and so we // under linux this malloc() overrides the libc malloc() and so we
// end up in a recursion (as MemAlloc_Alloc() calls malloc) // end up in a recursion (as MemAlloc_Alloc() calls malloc)
#if _MSC_VER >= 1400 #if _MSC_VER >= 1400
#if _MSC_VER >= 1900
#define _CRTNOALIAS
#endif
#define ALLOC_CALL _CRTNOALIAS _CRTRESTRICT #define ALLOC_CALL _CRTNOALIAS _CRTRESTRICT
#define FREE_CALL _CRTNOALIAS #define FREE_CALL _CRTNOALIAS
#else #else
@ -133,24 +138,42 @@ void *_malloc_base( size_t nSize )
} }
#endif #endif
#if ( defined ( _MSC_VER ) && _MSC_VER >= 1900 )
_CRTRESTRICT void *_calloc_base(size_t nCount, size_t nSize)
{
void *pMem = AllocUnattributed(nCount * nSize);
memset(pMem, 0, nCount * nSize);
return pMem;
}
#else
void *_calloc_base(size_t nSize) void *_calloc_base(size_t nSize)
{ {
void *pMem = AllocUnattributed(nSize); void *pMem = AllocUnattributed(nSize);
memset(pMem, 0, nSize); memset(pMem, 0, nSize);
return pMem; return pMem;
} }
#endif
void *_realloc_base( void *pMem, size_t nSize ) void *_realloc_base( void *pMem, size_t nSize )
{ {
return ReallocUnattributed( pMem, nSize ); return ReallocUnattributed( pMem, nSize );
} }
#if ( defined ( _MSC_VER ) && _MSC_VER >= 1900 )
void *_recalloc_base( void *pMem, size_t nCount, size_t nSize )
{
void *pMemOut = ReallocUnattributed( pMem, nCount * nSize );
memset(pMemOut, 0, nCount * nSize);
return pMemOut;
}
#else
void *_recalloc_base(void *pMem, size_t nSize) void *_recalloc_base(void *pMem, size_t nSize)
{ {
void *pMemOut = ReallocUnattributed(pMem, nSize); void *pMemOut = ReallocUnattributed(pMem, nSize);
memset(pMemOut, 0, nSize); memset(pMemOut, 0, nSize);
return pMemOut; return pMemOut;
} }
#endif
void _free_base( void *pMem ) void _free_base( void *pMem )
{ {
@ -175,7 +198,11 @@ void * __cdecl _malloc_crt(size_t size)
void * __cdecl _calloc_crt(size_t count, size_t size) void * __cdecl _calloc_crt(size_t count, size_t size)
{ {
#if (defined( _MSC_VER ) && _MSC_VER >= 1900)
return _calloc_base(count, size);
#else
return _calloc_base(count * size); return _calloc_base(count * size);
#endif
} }
void * __cdecl _realloc_crt(void *ptr, size_t size) void * __cdecl _realloc_crt(void *ptr, size_t size)
@ -185,7 +212,12 @@ void * __cdecl _realloc_crt(void *ptr, size_t size)
void * __cdecl _recalloc_crt(void *ptr, size_t count, size_t size) void * __cdecl _recalloc_crt(void *ptr, size_t count, size_t size)
{ {
#if (defined( _MSC_VER ) && _MSC_VER >= 1900)
return _recalloc_base(ptr, count, size);
#else
return _recalloc_base(ptr, size * count); return _recalloc_base(ptr, size * count);
#endif
} }
ALLOC_CALL void * __cdecl _recalloc ( void * memblock, size_t count, size_t size ) ALLOC_CALL void * __cdecl _recalloc ( void * memblock, size_t count, size_t size )
@ -195,10 +227,17 @@ ALLOC_CALL void * __cdecl _recalloc ( void * memblock, size_t count, size_t size
return pMem; return pMem;
} }
size_t _msize_base( void *pMem ) #if ( defined ( _MSC_VER ) && _MSC_VER >= 1900 )
size_t _msize_base( void *pMem ) _CRT_NOEXCEPT
{ {
return g_pMemAlloc->GetSize(pMem); return g_pMemAlloc->GetSize(pMem);
} }
#else
size_t _msize_base(void *pMem) _CRT_NOEXCEPT
{
return g_pMemAlloc->GetSize(pMem);
}
#endif
size_t _msize( void *pMem ) size_t _msize( void *pMem )
{ {
@ -295,12 +334,12 @@ void *malloc_db( size_t nSize, const char *pFileName, int nLine )
void free_db( void *pMem, const char *pFileName, int nLine ) void free_db( void *pMem, const char *pFileName, int nLine )
{ {
g_pMemAlloc->Free(pMem, pFileName, nLine); g_pMemAlloc->Free(pMem/*, pFileName, nLine*/);
} }
void *realloc_db( void *pMem, size_t nSize, const char *pFileName, int nLine ) void *realloc_db( void *pMem, size_t nSize, const char *pFileName, int nLine )
{ {
return g_pMemAlloc->Realloc(pMem, nSize, pFileName, nLine); return g_pMemAlloc->Realloc(pMem, nSize/*, pFileName, nLine*/);
} }
} // end extern "C" } // end extern "C"
@ -451,7 +490,7 @@ void *__cdecl _realloc_dbg( void *pMem, size_t nNewSize, int nBlockUse,
const char *pFileName, int nLine ) const char *pFileName, int nLine )
{ {
AttribIfCrt(); AttribIfCrt();
return g_pMemAlloc->Realloc(pMem, nNewSize, pFileName, nLine); return g_pMemAlloc->Realloc(pMem, nNewSize/*, pFileName, nLine*/);
} }
void *__cdecl _expand_dbg( void *pMem, size_t nNewSize, int nBlockUse, void *__cdecl _expand_dbg( void *pMem, size_t nNewSize, int nBlockUse,
@ -599,6 +638,7 @@ int _CrtSetDbgFlag( int nNewFlag )
#define AFNAME(var) __p_ ## var #define AFNAME(var) __p_ ## var
#define AFRET(var) &var #define AFRET(var) &var
#if !( defined( _MSC_VER ) && _MSC_VER >= 1900)
int _crtDbgFlag = _CRTDBG_ALLOC_MEM_DF; int _crtDbgFlag = _CRTDBG_ALLOC_MEM_DF;
int* AFNAME(_crtDbgFlag)(void) int* AFNAME(_crtDbgFlag)(void)
{ {
@ -610,6 +650,7 @@ long* AFNAME(_crtBreakAlloc) (void)
{ {
return AFRET(_crtBreakAlloc); return AFRET(_crtBreakAlloc);
} }
#endif
void __cdecl _CrtSetDbgBlockType( void *pMem, int nBlockUse ) void __cdecl _CrtSetDbgBlockType( void *pMem, int nBlockUse )
{ {
@ -712,7 +753,7 @@ int __cdecl _CrtDbgReport( int nRptType, const char * szFile,
#if _MSC_VER >= 1400 #if _MSC_VER >= 1400
#if defined( _DEBUG ) #if defined( _DEBUG ) && _MSC_VER < 1900
// wrapper which passes no debug info; not available in debug // wrapper which passes no debug info; not available in debug
void __cdecl _invalid_parameter_noinfo(void) void __cdecl _invalid_parameter_noinfo(void)
@ -745,12 +786,21 @@ int __cdecl _CrtDbgReportW( int nRptType, const wchar_t *szFile, int nLine,
return 0; return 0;
} }
#if ( defined(_MSC_VER) && _MSC_VER >= 1900)
int __cdecl _VCrtDbgReportA(int nRptType, void *pReturnAddr, const char *szFile, int nLine,
const char *szModule, const char *szFormat, va_list arglist)
{
Assert(0);
return 0;
}
#else
int __cdecl _VCrtDbgReportA(int nRptType, const wchar_t *szFile, int nLine, int __cdecl _VCrtDbgReportA(int nRptType, const wchar_t *szFile, int nLine,
const wchar_t *szModule, const wchar_t *szFormat, va_list arglist) const wchar_t *szModule, const wchar_t *szFormat, va_list arglist)
{ {
Assert(0); Assert(0);
return 0; return 0;
} }
#endif
int __cdecl _CrtSetReportHook2( int mode, _CRT_REPORT_HOOK pfnNewHook ) int __cdecl _CrtSetReportHook2( int mode, _CRT_REPORT_HOOK pfnNewHook )
{ {
@ -1164,6 +1214,8 @@ SIZE_T WINAPI XMemSize( PVOID pAddress, DWORD dwAllocAttributes )
#define MAX_MODIFIER_LEN 0 /* max modifier name length - n/a */ #define MAX_MODIFIER_LEN 0 /* max modifier name length - n/a */
#define MAX_LC_LEN (MAX_LANG_LEN+MAX_CTRY_LEN+MAX_MODIFIER_LEN+3) #define MAX_LC_LEN (MAX_LANG_LEN+MAX_CTRY_LEN+MAX_MODIFIER_LEN+3)
#if 0
// GAMMACASE: Disabled due to being too outdated
struct _is_ctype_compatible { struct _is_ctype_compatible {
unsigned long id; unsigned long id;
int is_clike; int is_clike;
@ -1317,7 +1369,7 @@ class _LocaleUpdate
return &localeinfo; return &localeinfo;
} }
}; };
#endif
#pragma warning(push) #pragma warning(push)
#pragma warning(disable: 4483) #pragma warning(disable: 4483)