Skip to content

Commit f6dc356

Browse files
committed
Reorganized the memory module
1 parent b9be131 commit f6dc356

11 files changed

Lines changed: 783 additions & 572 deletions

src/CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,18 +265,22 @@ Set(SOURCEPYTHON_MATHLIB_MODULE_SOURCES
265265
# Memory module
266266
# ------------------------------------------------------------------
267267
Set(SOURCEPYTHON_MEMORY_MODULE_HEADERS
268-
core/modules/memory/memory_tools.h
269-
core/modules/memory/memory_scanner.h
270-
core/modules/memory/memory_hooks.h
268+
core/modules/memory/memory_alloc.h
271269
core/modules/memory/memory_calling_convention.h
270+
core/modules/memory/memory_function.h
272271
core/modules/memory/memory_function_info.h
272+
core/modules/memory/memory_hooks.h
273+
core/modules/memory/memory_pointer.h
274+
core/modules/memory/memory_scanner.h
275+
core/modules/memory/memory_tools.h
273276
core/modules/memory/memory_utilities.h
274277
)
275278

276279
Set(SOURCEPYTHON_MEMORY_MODULE_SOURCES
277-
core/modules/memory/memory_scanner.cpp
278-
core/modules/memory/memory_tools.cpp
280+
core/modules/memory/memory_function.cpp
279281
core/modules/memory/memory_hooks.cpp
282+
core/modules/memory/memory_pointer.cpp
283+
core/modules/memory/memory_scanner.cpp
280284
core/modules/memory/memory_wrap_python.cpp
281285
)
282286

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* =============================================================================
3+
* Source Python
4+
* Copyright (C) 2015 Source Python Development Team. All rights reserved.
5+
* =============================================================================
6+
*
7+
* This program is free software; you can redistribute it and/or modify it under
8+
* the terms of the GNU General Public License, version 3.0, as published by the
9+
* Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14+
* details.
15+
*
16+
* You should have received a copy of the GNU General Public License along with
17+
* this program. If not, see <http://www.gnu.org/licenses/>.
18+
*
19+
* As a special exception, the Source Python Team gives you permission
20+
* to link the code of this program (as well as its derivative works) to
21+
* "Half-Life 2," the "Source Engine," and any Game MODs that run on software
22+
* by the Valve Corporation. You must obey the GNU General Public License in
23+
* all respects for all other code used. Additionally, the Source.Python
24+
* Development Team grants this exception to all derivative works.
25+
*/
26+
27+
#ifndef _MEMORY_ALLOC_H
28+
#define _MEMORY_ALLOC_H
29+
30+
// ============================================================================
31+
// >> INCLUDES
32+
// ============================================================================
33+
#include <malloc.h>
34+
#include "memalloc.h"
35+
36+
37+
// ============================================================================
38+
// >> UTIL_GetMemSize
39+
// ============================================================================
40+
inline size_t UTIL_GetMemSize(void* ptr)
41+
{
42+
#ifdef _WIN32
43+
return g_pMemAlloc->GetSize(ptr);
44+
#elif defined(__linux__)
45+
return malloc_usable_size(ptr);
46+
#else
47+
#error "Unsupported platform."
48+
#endif
49+
}
50+
51+
52+
// ============================================================================
53+
// >> UTIL_Alloc
54+
// ============================================================================
55+
inline void* UTIL_Alloc(size_t size)
56+
{
57+
void* pPtr = NULL;
58+
#ifdef _WIN32
59+
pPtr = g_pMemAlloc->IndirectAlloc(size);
60+
#elif defined(__linux__)
61+
pPtr = malloc(size);
62+
#else
63+
#error "Unsupported platform."
64+
#endif
65+
memset(pPtr, 0, size);
66+
return pPtr;
67+
}
68+
69+
70+
// ============================================================================
71+
// >> UTIL_Realloc
72+
// ============================================================================
73+
inline void* UTIL_Realloc(void* ptr, size_t size)
74+
{
75+
void* pPtr = NULL;
76+
#ifdef _WIN32
77+
pPtr = g_pMemAlloc->Realloc(ptr, size);
78+
#elif defined(__linux__)
79+
pPtr = realloc(ptr, size);
80+
#else
81+
#error "Unsupported platform."
82+
#endif
83+
return pPtr;
84+
}
85+
86+
87+
// ============================================================================
88+
// >> UTIL_Dealloc
89+
// ============================================================================
90+
inline void UTIL_Dealloc(void* ptr)
91+
{
92+
#ifdef _WIN32
93+
g_pMemAlloc->Free(ptr);
94+
#elif defined(__linux__)
95+
free(ptr);
96+
#else
97+
#error "Unsupported platform."
98+
#endif
99+
}
100+
101+
#endif // _MEMORY_ALLOC_H

src/core/modules/memory/memory_calling_convention.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#ifndef _MEMORY_CALLING_CONVENTION_H
3434
#define _MEMORY_CALLING_CONVENTION_H
3535

36-
#include "modules/memory/memory_tools.h"
36+
#include "modules/memory/memory_function.h"
3737
#include <boost/type_traits.hpp>
3838

3939
#include <boost/preprocessor/iteration/iterate.hpp>

0 commit comments

Comments
 (0)