From aec6d4eca4779cd6c2238b0381d20e6a6f50c61e Mon Sep 17 00:00:00 2001 From: arthurdead Date: Sat, 3 Dec 2022 08:37:48 -0300 Subject: [PATCH] add Size back to utlvector, fix stackalloc/free definitions --- public/tier0/platform.h | 36 ++++++++++-------------------------- public/tier1/utlvector.h | 1 + 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/public/tier0/platform.h b/public/tier0/platform.h index 1cf4fa3e..b536c398 100644 --- a/public/tier0/platform.h +++ b/public/tier0/platform.h @@ -381,8 +381,17 @@ typedef void * HINSTANCE; //----------------------------------------------------------------------------- // Stack-based allocation related helpers //----------------------------------------------------------------------------- +#ifdef _WIN32 +// Alloca defined for this platform +#define stackalloc( _size ) _alloca( ALIGN_VALUE( _size, 16 ) ) +#define stackfree( _p ) +#elif defined(_LINUX) || defined(__APPLE__) +// Alloca defined for this platform +#define stackalloc( _size ) alloca( ALIGN_VALUE( _size, 16 ) ) +#define stackfree( _p ) +#endif + #if defined( GNUC ) - #define stackalloc( _size ) alloca( ALIGN_VALUE( _size, 16 ) ) #ifdef _LINUX #define mallocsize( _p ) ( malloc_usable_size( _p ) ) #elif defined(OSX) @@ -391,12 +400,9 @@ typedef void * HINSTANCE; #error #endif #elif defined ( _WIN32 ) - #define stackalloc( _size ) _alloca( ALIGN_VALUE( _size, 16 ) ) #define mallocsize( _p ) ( _msize( _p ) ) #endif -#define stackfree( _p ) 0 - // Linux had a few areas where it didn't construct objects in the same order that Windows does. // So when CVProfile::CVProfile() would access g_pMemAlloc, it would crash because the allocator wasn't initalized yet. #if defined(_LINUX) || defined(__APPLE__) @@ -498,28 +504,6 @@ typedef void * HINSTANCE; // as little code as possible, and throw an assertion in debug. #define NO_DEFAULT default: UNREACHABLE(); -#ifdef _WIN32 -// Alloca defined for this platform -#define stackalloc( _size ) _alloca( ALIGN_VALUE( _size, 16 ) ) -#define stackfree( _p ) -#elif defined(_LINUX) || defined(__APPLE__) -// Alloca defined for this platform -#define stackalloc( _size ) alloca( ALIGN_VALUE( _size, 16 ) ) -#define stackfree( _p ) -#endif - -#if defined( GNUC ) -#ifdef _LINUX - #define mallocsize( _p ) ( malloc_usable_size( _p ) ) -#elif defined(OSX) - #define mallocsize( _p ) ( malloc_size( _p ) ) -#else -#error -#endif -#elif defined ( _WIN32 ) - #define mallocsize( _p ) ( _msize( _p ) ) -#endif - #ifdef _WIN32 #define RESTRICT __restrict #define RESTRICT_FUNC __declspec(restrict) diff --git a/public/tier1/utlvector.h b/public/tier1/utlvector.h index 51614938..732fd3c0 100644 --- a/public/tier1/utlvector.h +++ b/public/tier1/utlvector.h @@ -66,6 +66,7 @@ public: // Returns the number of elements in the vector int Count() const; + int Size() const { return Count(); } // Is element index valid? bool IsValidIndex( int i ) const;