Skip to content

Commit

Permalink
xrCore/xrMemory: x64 corrections
Browse files Browse the repository at this point in the history
And other corrections
  • Loading branch information
Xottab-DUTY committed Jan 13, 2018
1 parent 0c41571 commit d0d7ab3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/xrCore/_std_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions src/xrCore/xrMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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); }
21 changes: 10 additions & 11 deletions src/xrCore/xrMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand All @@ -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
Expand All @@ -91,24 +91,23 @@ extern XRCORE_API xrMemory Memory;

// generic "C"-like allocations/deallocations
template <class T>
IC T* xr_alloc(size_t count)
T* xr_alloc(const size_t count)
{ return (T*)Memory.mem_alloc(count * sizeof(T)); }


template <class T>
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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/xrMemory_subst_msvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/xrMisc/xrMisc_xrMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down

0 comments on commit d0d7ab3

Please sign in to comment.