diff --git a/amxmodx/CCmd.cpp b/amxmodx/CCmd.cpp index 82663c4b..64fb3e04 100755 --- a/amxmodx/CCmd.cpp +++ b/amxmodx/CCmd.cpp @@ -273,4 +273,5 @@ void CmdMngr::clearBufforedInfo() { buf_cmdaccess = 0; } -int CmdMngr::Command::uniqueid = 0; \ No newline at end of file +int CmdMngr::Command::uniqueid = 0; + diff --git a/amxmodx/Makefile b/amxmodx/Makefile index 3530a4d1..0fefbc15 100755 --- a/amxmodx/Makefile +++ b/amxmodx/Makefile @@ -6,7 +6,7 @@ MM_ROOT = ../metamod/metamod ### EDIT BELOW FOR OTHER PROJECTS ### -OPT_FLAGS = -O3 -fno-rtti -funroll-loops -s -pipe +OPT_FLAGS = -O3 -funroll-loops -s -pipe DEBUG_FLAGS = -g -ggdb3 CPP = gcc NAME = amxmodx_mm @@ -15,7 +15,7 @@ OBJECTS = meta_api.cpp CFile.cpp CVault.cpp vault.cpp float.cpp file.cpp modules CMisc.cpp CTask.cpp string.cpp amxmodx.cpp CEvent.cpp CCmd.cpp CLogEvent.cpp \ srvcmd.cpp strptime.cpp amxcore.cpp amxtime.cpp power.cpp amxxlog.cpp fakemeta.cpp \ amxxfile.cpp CLang.cpp md5.cpp emsg.cpp CForward.cpp CPlugin.cpp CModule.cpp \ - CMenu.cpp util.cpp amx.cpp amxdbg.cpp natives.cpp newmenus.cpp mmgr/mmgr.cpp + CMenu.cpp util.cpp amx.cpp amxdbg.cpp natives.cpp newmenus.cpp LINK = -lz @@ -31,10 +31,11 @@ else endif ifeq "$(MMGR)" "true" - OBJECTS += MMGR/MMGR.CPP + OBJECTS += mmgr/mmgr.cpp + CFLAGS += -DMEMORY_TEST endif -CFLAGS += -DLINUX -DNDEBUG -fPIC -Wno-deprecated -DHAVE_STDINT_H -DMEMORY_TEST +CFLAGS += -DLINUX -DNDEBUG -fPIC -Wno-deprecated -DHAVE_STDINT_H -static-libgcc -fno-rtti -fno-exceptions ifeq "$(AMD64)" "true" BINARY = $(NAME)_amd64.so diff --git a/amxmodx/emsg.cpp b/amxmodx/emsg.cpp index fbf3c35f..d9c22a31 100755 --- a/amxmodx/emsg.cpp +++ b/amxmodx/emsg.cpp @@ -312,4 +312,5 @@ void Client_ResetHUD(void* mValue) { } -*/ \ No newline at end of file +*/ + diff --git a/amxmodx/modules.cpp b/amxmodx/modules.cpp index 60c1883a..55126921 100755 --- a/amxmodx/modules.cpp +++ b/amxmodx/modules.cpp @@ -1756,3 +1756,24 @@ void *Module_ReqFnptr(const char *funcName) return NULL; } + +#ifndef MEMORY_TEST +void * ::operator new(size_t size) { + return(calloc(1, size)); +} + +void * ::operator new[](size_t size) { + return(calloc(1, size)); +} + +void ::operator delete(void * ptr) { + if(ptr) + free(ptr); +} + +void ::operator delete[](void * ptr) { + if(ptr) + free(ptr); +} +#endif + diff --git a/amxmodx/sdk/amxxmodule.cpp b/amxmodx/sdk/amxxmodule.cpp index 9dfe57be..43ded3bf 100755 --- a/amxmodx/sdk/amxxmodule.cpp +++ b/amxmodx/sdk/amxxmodule.cpp @@ -2909,6 +2909,28 @@ void operator delete[](void *reportedAddress) Mem_Deallocator(g_Mem_CurrentFilename, g_Mem_CurrentLine, g_Mem_CurrentFunc, m_alloc_delete_array, reportedAddress); } +#else + +#if !defined NO_ALLOC_OVERRIDES && !defined MEMORY_TEST +void * ::operator new(size_t size) { + return(calloc(1, size)); +} + +void * ::operator new[](size_t size) { + return(calloc(1, size)); +} + +void ::operator delete(void * ptr) { + if(ptr) + free(ptr); +} + +void ::operator delete[](void * ptr) { + if(ptr) + free(ptr); +} +#endif + #endif //MEMORY_TEST /************* stuff from dlls/util.cpp *************/ diff --git a/amxmodx/sdk/moduleconfig.h b/amxmodx/sdk/moduleconfig.h index d03a34eb..bb8c625d 100755 --- a/amxmodx/sdk/moduleconfig.h +++ b/amxmodx/sdk/moduleconfig.h @@ -27,6 +27,10 @@ // be careful of default constructors using new/malloc! // #define MEMORY_TEST +// Unless you use STL or exceptions, keep this commented. +// It allows you to compile without libstdc++.so as a dependency +// #define NO_ALLOC_OVERRIDES + // - AMXX Init functions // Also consider using FN_META_* // AMXX query @@ -465,4 +469,4 @@ #endif // USE_METAMOD -#endif // __MODULECONFIG_H__ \ No newline at end of file +#endif // __MODULECONFIG_H__