From a77a95b71bc92b55d995c01971d16a41e98faef6 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Thu, 2 Jun 2022 07:03:42 -0700 Subject: [PATCH] Add StompAlloc workspace alloc option --- BeefRT/BeefDbg/BeefDbg.vcxproj | 12 ++++++------ BeefRT/rt/StompAlloc.cpp | 14 +++++++++++--- BeefRT/rt/StompAlloc.h | 13 +++++++++++-- IDE/src/BuildContext.bf | 2 +- IDE/src/Compiler/BfCompiler.bf | 3 +++ IDE/src/Workspace.bf | 1 + IDE/src/ui/WorkspaceProperties.bf | 8 +++++++- 7 files changed, 40 insertions(+), 13 deletions(-) diff --git a/BeefRT/BeefDbg/BeefDbg.vcxproj b/BeefRT/BeefDbg/BeefDbg.vcxproj index df09d040..f8702896 100644 --- a/BeefRT/BeefDbg/BeefDbg.vcxproj +++ b/BeefRT/BeefDbg/BeefDbg.vcxproj @@ -582,7 +582,7 @@ Level3 Disabled - BFRTDBG;BP_DISABLED;BF_NO_BFAPP;BFRT_DYNAMIC;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + BFRTDBG;BP_DISABLED;BF_NO_BFAPP;BFRT_DYNAMIC;BF_STOMP_EXPORT;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) .;../;../..;../../BeefySysLib/third_party;../../BeefySysLib;../../BeefySysLib/platform/win;../gperftools/src;../gperftools/src/windows @@ -607,7 +607,7 @@ Level3 Disabled - BFRTDBG;BP_DISABLED;BF_NO_BFAPP;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + BFRTDBG;BP_DISABLED;BF_NO_BFAPP;BF_STOMP_EXPORT;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) .;../;../..;../../BeefySysLib/third_party;../../BeefySysLib;../../BeefySysLib/platform/win;../gperftools/src;../gperftools/src/windows @@ -633,7 +633,7 @@ Level3 Disabled - BFRTDBG;BP_DISABLED;BF_NO_BFAPP;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + BFRTDBG;BP_DISABLED;BF_NO_BFAPP;BF_STOMP_EXPORT;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) .;../;../..;../../BeefySysLib/third_party;../../BeefySysLib;../../BeefySysLib/platform/win;../gperftools/src;../gperftools/src/windows @@ -720,7 +720,7 @@ MaxSpeed true true - BFRTDBG;BP_DISABLED;BF_NO_BFAPP;BFRT_DYNAMIC;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + BFRTDBG;BP_DISABLED;BF_NO_BFAPP;BFRT_DYNAMIC;;BF_STOMP_EXPORT;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) .;../;../..;../../BeefySysLib/third_party;../../BeefySysLib;../../BeefySysLib/platform/win;../gperftools/src;../gperftools/src/windows false MultiThreaded @@ -742,7 +742,7 @@ MaxSpeed true true - BFRTDBG;BP_DISABLED;BF_NO_BFAPP;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + BFRTDBG;BP_DISABLED;BF_NO_BFAPP;BF_STOMP_EXPORT;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) .;../;../..;../../BeefySysLib/third_party;../../BeefySysLib;../../BeefySysLib/platform/win;../gperftools/src;../gperftools/src/windows false MultiThreaded @@ -764,7 +764,7 @@ MaxSpeed true true - BFRTDBG;BP_DISABLED;BF_NO_BFAPP;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + BFRTDBG;BP_DISABLED;BF_NO_BFAPP;BF_STOMP_EXPORT;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) .;../;../..;../../BeefySysLib/third_party;../../BeefySysLib;../../BeefySysLib/platform/win;../gperftools/src;../gperftools/src/windows false MultiThreadedDLL diff --git a/BeefRT/rt/StompAlloc.cpp b/BeefRT/rt/StompAlloc.cpp index 1f896653..cc768768 100644 --- a/BeefRT/rt/StompAlloc.cpp +++ b/BeefRT/rt/StompAlloc.cpp @@ -1,4 +1,4 @@ -#ifdef BF_USE_STOMP_ALLOC +#if defined BF_USE_STOMP_ALLOC || defined BF_STOMP_EXPORT #include "BeefySysLib/Common.h" @@ -166,7 +166,11 @@ public: static std::list gAllocRanges; static CritSect gSA_CritSect; -extern "C" void* StompAlloc(intptr size) +extern "C" +#ifdef BF_STOMP_EXPORT +__declspec(dllexport) +#endif +void* StompAlloc(intptr size) { AutoCrit autoCrit(gSA_CritSect); @@ -184,7 +188,11 @@ extern "C" void* StompAlloc(intptr size) } } -extern "C" void StompFree(void* addr) +extern "C" +#ifdef BF_STOMP_EXPORT +__declspec(dllexport) +#endif +void StompFree(void* addr) { AutoCrit autoCrit(gSA_CritSect); diff --git a/BeefRT/rt/StompAlloc.h b/BeefRT/rt/StompAlloc.h index 44e379aa..6c7c72e2 100644 --- a/BeefRT/rt/StompAlloc.h +++ b/BeefRT/rt/StompAlloc.h @@ -1,4 +1,13 @@ #pragma once -extern "C" void* StompAlloc(intptr size); -extern "C" void StompFree(void* addr); +extern "C" +#ifdef BF_STOMP_EXPORT +__declspec(dllexport) +#endif +void* StompAlloc(intptr size); + +extern "C" +#ifdef BF_STOMP_EXPORT +__declspec(dllexport) +#endif +void StompFree(void* addr); diff --git a/IDE/src/BuildContext.bf b/IDE/src/BuildContext.bf index 871fb8dd..2ffa6cb5 100644 --- a/IDE/src/BuildContext.bf +++ b/IDE/src/BuildContext.bf @@ -740,7 +740,7 @@ namespace IDE outRt.Append(dynName ? ".dll" : ".lib"); } - if ((workspaceOptions.mEnableObjectDebugFlags) || (workspaceOptions.mAllocType == .Debug)) + if ((workspaceOptions.mEnableObjectDebugFlags) || (workspaceOptions.mAllocType == .Debug) || (workspaceOptions.mAllocType == .Stomp)) { outDbg.Append("Beef", IDEApp.sRTVersionStr, "Dbg"); outDbg.Append((Workspace.PlatformType.GetPtrSizeByName(gApp.mPlatformName) == 4) ? "32" : "64"); diff --git a/IDE/src/Compiler/BfCompiler.bf b/IDE/src/Compiler/BfCompiler.bf index 2576b903..3e1af950 100644 --- a/IDE/src/Compiler/BfCompiler.bf +++ b/IDE/src/Compiler/BfCompiler.bf @@ -745,6 +745,9 @@ namespace IDE.Compiler optionFlags |= .DebugAlloc; mallocLinkName = ""; freeLinkName = ""; + case .Stomp: + mallocLinkName = "StompAlloc"; + freeLinkName = "StompFree"; case .CRT: mallocLinkName = "malloc"; freeLinkName = "free"; diff --git a/IDE/src/Workspace.bf b/IDE/src/Workspace.bf index f510cdf8..167c01e7 100644 --- a/IDE/src/Workspace.bf +++ b/IDE/src/Workspace.bf @@ -215,6 +215,7 @@ namespace IDE public enum AllocType { Debug, + Stomp, CRT, JEMalloc, TCMalloc, diff --git a/IDE/src/ui/WorkspaceProperties.bf b/IDE/src/ui/WorkspaceProperties.bf index 1c9a3db8..5631c31e 100644 --- a/IDE/src/ui/WorkspaceProperties.bf +++ b/IDE/src/ui/WorkspaceProperties.bf @@ -733,7 +733,8 @@ namespace IDE.ui AddPropertiesItem(category, "Preprocessor Macros", "mPreprocessorMacros"); AddPropertiesItem(category, "Incremental Build", "mIncrementalBuild"); AddPropertiesItem(category, "Intermediate Type", "mIntermediateType"); - var (allocCategory, allocPropEntry) = AddPropertiesItem(category, "Memory Allocator", "mAllocType"); + var (allocCategory, allocPropEntry) = AddPropertiesItem(category, "Memory Allocator", "mAllocType", + scope String[] ("Debug", "Stomp (Debug)", "CRT", "JEMalloc", "TCMalloc")); var (mallocItem, mallocPropEntry) = AddPropertiesItem(allocCategory, "Malloc", "mAllocMalloc"); var (freeItem, freePropEntry) = AddPropertiesItem(allocCategory, "Free", "mAllocFree"); allocPropEntry.mOnUpdate.Add(new () => @@ -758,6 +759,11 @@ namespace IDE.ui mallocSubItem.Label = ""; freeSubItem.Label = ""; } + else if (allocType == .Stomp) + { + mallocSubItem.Label = "StompAlloc"; + freeSubItem.Label = "StompFree"; + } else if (allocType == .CRT) { mallocSubItem.Label = "malloc";