Skip to content

Commit d0d7ab3

Browse files
committed
xrCore/xrMemory: x64 corrections
And other corrections
1 parent 0c41571 commit d0d7ab3

File tree

5 files changed

+16
-21
lines changed

5 files changed

+16
-21
lines changed

src/xrCore/_std_extensions.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,12 @@ IC s32 _max(s32 x, s32 y) { return x - ((x - y) & ((x - y) >> (sizeof(s32) * 8 -
171171
IC s64 _abs(s64 x) { return (x >= 0) ? x : s64(-x); }
172172
IC s64 _min(s64 x, s64 y) { return y + ((x - y) & ((x - y) >> (sizeof(s64) * 8 - 1))); };
173173
IC s64 _max(s64 x, s64 y) { return x - ((x - y) & ((x - y) >> (sizeof(s64) * 8 - 1))); };
174-
IC u32 xr_strlen(const char* S);
175174

176175
// string management
177176

178177
// return pointer to ".ext"
179178
IC char* strext(const char* S) { return (char*)strrchr(S, '.'); }
180-
IC u32 xr_strlen(const char* S) { return (u32)strlen(S); }
179+
IC size_t xr_strlen(const char* S) { return strlen(S); }
181180
IC char* xr_strupr(char* S) { return _strupr(S); }
182181
IC char* xr_strlwr(char* S) { return _strlwr(S); }
183182
#ifdef BREAK_AT_STRCMP

src/xrCore/xrMemory.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,10 @@ void xrMemory::mem_statistic(const char* fn)
256256
#endif // DEBUG_MEMORY_MANAGER
257257

258258
// xr_strdup
259-
char* xr_strdup(const char* string)
259+
pstr xr_strdup(pcstr string)
260260
{
261261
VERIFY(string);
262-
u32 len = u32(xr_strlen(string)) + 1;
262+
size_t len = xr_strlen(string) + 1;
263263
char* memory = (char*)Memory.mem_alloc(len);
264264
CopyMemory(memory, string, len);
265265
return memory;
@@ -273,6 +273,3 @@ XRCORE_API BOOL is_stack_ptr(void* _ptr)
273273
ptrdiff_t difference = (ptrdiff_t)_abs(s64(ptrdiff_t(ptr_local) - ptrdiff_t(ptr_refsound)));
274274
return (difference < (512 * 1024));
275275
}
276-
277-
XRCORE_API void* xr_malloc(size_t size) { return Memory.mem_alloc(size); }
278-
XRCORE_API void* xr_realloc(void* P, size_t size) { return Memory.mem_realloc(P, size); }

src/xrCore/xrMemory.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class XRCORE_API xrMemory
6969
void mem_statistic(const char* fn);
7070
#endif // DEBUG_MEMORY_NAME
7171
void* mem_alloc(size_t size);
72-
void* mem_realloc(void* p, size_t size);
72+
void* mem_realloc(void* p, const size_t size);
7373
void mem_free(void* p);
7474
};
7575

@@ -79,7 +79,7 @@ extern XRCORE_API xrMemory Memory;
7979
#undef CopyMemory
8080
#undef FillMemory
8181
#define ZeroMemory(a, b) memset(a, 0, b)
82-
#define CopyMemory(a, b, c) memcpy(a, b, c) //. CopyMemory(a,b,c)
82+
#define CopyMemory(a, b, c) memcpy(a, b, c)
8383
#define FillMemory(a, b, c) memset(a, c, b)
8484

8585
// delete
@@ -91,24 +91,23 @@ extern XRCORE_API xrMemory Memory;
9191

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

9797

9898
template <class T>
99-
IC void xr_free(T*& P) throw()
99+
void xr_free(T*& P) throw()
100100
{
101101
if (P)
102102
{
103103
Memory.mem_free((void*)P);
104104
P = nullptr;
105-
};
105+
}
106106
}
107+
inline void* xr_malloc(const size_t size) { return Memory.mem_alloc(size); }
108+
inline void* xr_realloc(void* P, const size_t size) { return Memory.mem_realloc(P, size); }
107109

108-
XRCORE_API void* xr_malloc(size_t size);
109-
XRCORE_API void* xr_realloc(void* P, size_t size);
110-
111-
XRCORE_API char* xr_strdup(const char* string);
110+
XRCORE_API pstr xr_strdup(pcstr string);
112111

113112
// Global new/delete override
114113
#ifndef NO_XRNEW
@@ -117,9 +116,9 @@ XRCORE_API char* xr_strdup(const char* string);
117116
#endif
118117
// XXX: Implementations of operator new/delete are in xrMisc/xrMemory.cpp, since they need
119118
// to be in a static link library.
120-
void* operator new(size_t size);
119+
void* operator new(const size_t size);
121120
void operator delete(void* p);
122-
void* operator new[](size_t size);
121+
void* operator new[](const size_t size);
123122
void operator delete[](void* p);
124123
#endif
125124

src/xrCore/xrMemory_subst_msvc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void xrMemory::mem_free(void* P)
123123

124124
extern BOOL g_bDbgFillMemory;
125125

126-
void* xrMemory::mem_realloc(void* P, size_t size)
126+
void* xrMemory::mem_realloc(void* P, const size_t size)
127127
{
128128
stat_calls++;
129129
if (g_use_pure_alloc)

src/xrMisc/xrMisc_xrMemory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#endif
99

1010
#ifndef NO_XRNEW
11-
void* operator new(size_t size) { return Memory.mem_alloc(size); }
12-
void* operator new[](size_t size) { return Memory.mem_alloc(size); }
11+
void* operator new(const size_t size) { return Memory.mem_alloc(size); }
12+
void* operator new[](const size_t size) { return Memory.mem_alloc(size); }
1313

1414
void operator delete(void* p) throw() { Memory.mem_free(p); }
1515
void operator delete[](void* p) throw() { Memory.mem_free(p); }

0 commit comments

Comments
 (0)