1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2024-12-23 01:59:43 +08:00

Updated for recent posix memory-handling changes.

This commit is contained in:
Nicholas Hastings 2013-07-06 11:15:58 -04:00
parent ab50f57278
commit 149b72b388
4 changed files with 63 additions and 7 deletions

View File

@ -35,14 +35,14 @@ else
CC = /usr/bin/gcc
CPLUS = /usr/bin/g++
CLINK = /usr/bin/gcc
CPP_LIB = $(SRCDS_DIR)/bin/libstdc++.so.6 $(SRCDS_DIR)/bin/libgcc_s.so.1
CPP_LIB = $(SRCDS_DIR)/bin/libstdc++.so.6
endif
# put any compiler flags you want passed here
USER_CFLAGS =
# link flags for your mod, make sure to include any special libraries here
LDFLAGS = "-lm -ldl $(LIB_DIR)/particles_i486.a $(LIB_DIR)/dmxloader_i486.a $(LIB_DIR)/mathlib_i486.a tier0_i486.so vstdlib_i486.so $(LIB_DIR)/tier1_i486.a $(LIB_DIR)/tier2_i486.a $(LIB_DIR)/tier3_i486.a $(LIB_DIR)/choreoobjects_i486.a steam_api_i486.so"
LDFLAGS = "-lm -ldl $(LIB_DIR)/particles_i486.a $(LIB_DIR)/dmxloader_i486.a $(LIB_DIR)/mathlib_i486.a libtier0_srv.so libvsdlib_srv.so $(LIB_DIR)/tier1_i486.a $(LIB_DIR)/tier2_i486.a $(LIB_DIR)/tier3_i486.a $(LIB_DIR)/choreoobjects_i486.a libsteam_api.so"
# XERCES 2.6.0 or above ( http://xml.apache.org/xerces-c/ ) is used by the vcproj to makefile converter
# it must be installed before being able to run this makefile
@ -91,7 +91,7 @@ SHLIBLDFLAGS = -shared -Wl,-Map,$@_map.txt -Wl
SHLIBSUFFIX =
endif
DEFINES +=-DVPROF_LEVEL=1 -DSWDS -D_finite=finite -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp \
DEFINES +=-DGNUC -DPOSIX -D_POSIX -DVPROF_LEVEL=1 -DSWDS -D_finite=finite -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp \
-Dstrnicmp=strncasecmp -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp
UNDEF = -Usprintf -Ustrncpy -UPROTECTED_THINGS_ENABLE

View File

@ -12,7 +12,6 @@
#include "appframework/IAppSystem.h"
#include "tier1/iconvar.h"
#include "tier0/memalloc.h"
class ConCommandBase;
class ConCommand;
@ -176,7 +175,7 @@ inline ICvar::Iterator::Iterator(ICvar *icvar)
inline ICvar::Iterator::~Iterator( void )
{
g_pMemAlloc->Free(m_pIter);
delete m_pIter;
}
inline void ICvar::Iterator::SetFirst( void )

View File

@ -14,6 +14,11 @@
#pragma once
#endif
#if defined( POSIX )
#define NO_MALLOC_OVERRIDE
#define NO_HOOK_MALLOC
#endif
// Define this in release to get memory tracking even in release builds
//#define USE_MEM_DEBUG 1
@ -24,11 +29,15 @@
// Undefine this if using a compiler lacking threadsafe RTTI (like vc6)
#define MEM_DEBUG_CLASSNAME 1
#if !defined(STEAM) && !defined(NO_MALLOC_OVERRIDE)
#include <stddef.h>
#if defined( OSX )
#include <malloc/malloc.h>
#endif
#include "tier0/mem.h"
#if !defined(STEAM) && !defined(NO_MALLOC_OVERRIDE)
struct _CrtMemState;
#define MEMALLOC_VERSION 1
@ -350,6 +359,45 @@ struct MemAllocFileLine_t
//-----------------------------------------------------------------------------
#elif defined( POSIX )
#if defined( OSX )
// Mac always aligns allocs, don't need to call posix_memalign which doesn't exist in 10.5.8 which TF2 still needs to run on
//inline void *memalign(size_t alignment, size_t size) {void *pTmp=NULL; posix_memalign(&pTmp, alignment, size); return pTmp;}
inline void *memalign(size_t alignment, size_t size) {void *pTmp=NULL; pTmp = malloc(size); return pTmp;}
#endif
inline void *_aligned_malloc( size_t nSize, size_t align ) { return memalign( align, nSize ); }
inline void _aligned_free( void *ptr ) { free( ptr ); }
inline void *MemAlloc_Alloc( size_t nSize, const char *pFileName = NULL, int nLine = 0 ) { return malloc( nSize ); }
inline void MemAlloc_Free( void *ptr, const char *pFileName = NULL, int nLine = 0 ) { free( ptr ); }
inline void *MemAlloc_AllocAligned( size_t size, size_t align, const char *pszFile = NULL, int nLine = 0 ) { return memalign( align, size ); }
inline void *MemAlloc_AllocAlignedFileLine( size_t size, size_t align, const char *pszFile = NULL, int nLine = 0 ) { return memalign( align, size ); }
inline void MemAlloc_FreeAligned( void *pMemBlock, const char *pszFile = NULL, int nLine = 0 ) { free( pMemBlock ); }
#if defined( OSX )
inline size_t _msize( void *ptr ) { return malloc_size( ptr ); }
#else
inline size_t _msize( void *ptr ) { return malloc_usable_size( ptr ); }
#endif
inline void *MemAlloc_ReallocAligned( void *ptr, size_t size, size_t align )
{
void *ptr_new_aligned = memalign( align, size );
if( ptr_new_aligned )
{
size_t old_size = _msize( ptr );
size_t copy_size = ( size < old_size ) ? size : old_size;
memcpy( ptr_new_aligned, ptr, copy_size );
free( ptr );
}
return ptr_new_aligned;
}
#endif // !STEAM && !NO_MALLOC_OVERRIDE
//-----------------------------------------------------------------------------
@ -358,9 +406,13 @@ struct MemAllocFileLine_t
#define MEM_ALLOC_CREDIT_(tag) ((void)0)
#define MEM_ALLOC_CREDIT() MEM_ALLOC_CREDIT_(__FILE__)
#define MEM_ALLOC_CREDIT_FUNCTION()
#define MEM_ALLOC_CREDIT_CLASS()
#define MEM_ALLOC_CLASSNAME(type) NULL
#define MemAlloc_PushAllocDbgInfo( pszFile, line )
#define MemAlloc_PopAllocDbgInfo()
#define MEMALLOC_DEFINE_EXTERNAL_TRACKING( tag )
#endif // !STEAM && NO_MALLOC_OVERRIDE
//-----------------------------------------------------------------------------

View File

@ -11,6 +11,11 @@
// to include this potentially multiple times (since we can deactivate debugging
// by including memdbgoff.h)
#if defined( POSIX )
#define NO_MALLOC_OVERRIDE
#define NO_HOOK_MALLOC
#endif
#if !defined(STEAM) && !defined(NO_MALLOC_OVERRIDE)
// SPECIAL NOTE #2: This must be the final include in a .cpp or .h file!!!