From d0d7ab36c5c61ca51d7b46a557b5206f8b8a9704 Mon Sep 17 00:00:00 2001 From: Xottab-DUTY Date: Sat, 13 Jan 2018 08:49:35 +0500 Subject: [PATCH] xrCore/xrMemory: x64 corrections And other corrections --- src/xrCore/_std_extensions.h | 3 +-- src/xrCore/xrMemory.cpp | 7 ++----- src/xrCore/xrMemory.h | 21 ++++++++++----------- src/xrCore/xrMemory_subst_msvc.cpp | 2 +- src/xrMisc/xrMisc_xrMemory.cpp | 4 ++-- 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/xrCore/_std_extensions.h b/src/xrCore/_std_extensions.h index 7f0ff9a6ab9..31ff266f61a 100644 --- a/src/xrCore/_std_extensions.h +++ b/src/xrCore/_std_extensions.h @@ -171,13 +171,12 @@ IC s32 _max(s32 x, s32 y) { return x - ((x - y) & ((x - y) >> (sizeof(s32) * 8 - IC s64 _abs(s64 x) { return (x >= 0) ? x : s64(-x); } IC s64 _min(s64 x, s64 y) { return y + ((x - y) & ((x - y) >> (sizeof(s64) * 8 - 1))); }; IC s64 _max(s64 x, s64 y) { return x - ((x - y) & ((x - y) >> (sizeof(s64) * 8 - 1))); }; -IC u32 xr_strlen(const char* S); // string management // return pointer to ".ext" IC char* strext(const char* S) { return (char*)strrchr(S, '.'); } -IC u32 xr_strlen(const char* S) { return (u32)strlen(S); } +IC size_t xr_strlen(const char* S) { return strlen(S); } IC char* xr_strupr(char* S) { return _strupr(S); } IC char* xr_strlwr(char* S) { return _strlwr(S); } #ifdef BREAK_AT_STRCMP diff --git a/src/xrCore/xrMemory.cpp b/src/xrCore/xrMemory.cpp index 2af19a468dd..d9d23f995df 100644 --- a/src/xrCore/xrMemory.cpp +++ b/src/xrCore/xrMemory.cpp @@ -256,10 +256,10 @@ void xrMemory::mem_statistic(const char* fn) #endif // DEBUG_MEMORY_MANAGER // xr_strdup -char* xr_strdup(const char* string) +pstr xr_strdup(pcstr string) { VERIFY(string); - u32 len = u32(xr_strlen(string)) + 1; + size_t len = xr_strlen(string) + 1; char* memory = (char*)Memory.mem_alloc(len); CopyMemory(memory, string, len); return memory; @@ -273,6 +273,3 @@ XRCORE_API BOOL is_stack_ptr(void* _ptr) ptrdiff_t difference = (ptrdiff_t)_abs(s64(ptrdiff_t(ptr_local) - ptrdiff_t(ptr_refsound))); return (difference < (512 * 1024)); } - -XRCORE_API void* xr_malloc(size_t size) { return Memory.mem_alloc(size); } -XRCORE_API void* xr_realloc(void* P, size_t size) { return Memory.mem_realloc(P, size); } diff --git a/src/xrCore/xrMemory.h b/src/xrCore/xrMemory.h index 684008f948a..ef816772849 100644 --- a/src/xrCore/xrMemory.h +++ b/src/xrCore/xrMemory.h @@ -69,7 +69,7 @@ class XRCORE_API xrMemory void mem_statistic(const char* fn); #endif // DEBUG_MEMORY_NAME void* mem_alloc(size_t size); - void* mem_realloc(void* p, size_t size); + void* mem_realloc(void* p, const size_t size); void mem_free(void* p); }; @@ -79,7 +79,7 @@ extern XRCORE_API xrMemory Memory; #undef CopyMemory #undef FillMemory #define ZeroMemory(a, b) memset(a, 0, b) -#define CopyMemory(a, b, c) memcpy(a, b, c) //. CopyMemory(a,b,c) +#define CopyMemory(a, b, c) memcpy(a, b, c) #define FillMemory(a, b, c) memset(a, c, b) // delete @@ -91,24 +91,23 @@ extern XRCORE_API xrMemory Memory; // generic "C"-like allocations/deallocations template -IC T* xr_alloc(size_t count) +T* xr_alloc(const size_t count) { return (T*)Memory.mem_alloc(count * sizeof(T)); } template -IC void xr_free(T*& P) throw() +void xr_free(T*& P) throw() { if (P) { Memory.mem_free((void*)P); P = nullptr; - }; + } } +inline void* xr_malloc(const size_t size) { return Memory.mem_alloc(size); } +inline void* xr_realloc(void* P, const size_t size) { return Memory.mem_realloc(P, size); } -XRCORE_API void* xr_malloc(size_t size); -XRCORE_API void* xr_realloc(void* P, size_t size); - -XRCORE_API char* xr_strdup(const char* string); +XRCORE_API pstr xr_strdup(pcstr string); // Global new/delete override #ifndef NO_XRNEW @@ -117,9 +116,9 @@ XRCORE_API char* xr_strdup(const char* string); #endif // XXX: Implementations of operator new/delete are in xrMisc/xrMemory.cpp, since they need // to be in a static link library. -void* operator new(size_t size); +void* operator new(const size_t size); void operator delete(void* p); -void* operator new[](size_t size); +void* operator new[](const size_t size); void operator delete[](void* p); #endif diff --git a/src/xrCore/xrMemory_subst_msvc.cpp b/src/xrCore/xrMemory_subst_msvc.cpp index 141b9cd3d43..e2b09de56af 100644 --- a/src/xrCore/xrMemory_subst_msvc.cpp +++ b/src/xrCore/xrMemory_subst_msvc.cpp @@ -123,7 +123,7 @@ void xrMemory::mem_free(void* P) extern BOOL g_bDbgFillMemory; -void* xrMemory::mem_realloc(void* P, size_t size) +void* xrMemory::mem_realloc(void* P, const size_t size) { stat_calls++; if (g_use_pure_alloc) diff --git a/src/xrMisc/xrMisc_xrMemory.cpp b/src/xrMisc/xrMisc_xrMemory.cpp index 607f8af0bfc..1cace53c0b8 100644 --- a/src/xrMisc/xrMisc_xrMemory.cpp +++ b/src/xrMisc/xrMisc_xrMemory.cpp @@ -8,8 +8,8 @@ #endif #ifndef NO_XRNEW -void* operator new(size_t size) { return Memory.mem_alloc(size); } -void* operator new[](size_t size) { return Memory.mem_alloc(size); } +void* operator new(const size_t size) { return Memory.mem_alloc(size); } +void* operator new[](const size_t size) { return Memory.mem_alloc(size); } void operator delete(void* p) throw() { Memory.mem_free(p); } void operator delete[](void* p) throw() { Memory.mem_free(p); }