forked from bartvdbraak/blender
use strict flags for guarded alloc
This commit is contained in:
parent
2924a02a35
commit
9ad5f32fc0
@ -190,7 +190,7 @@ extern "C" {
|
||||
* Are the start/end block markers still correct ?
|
||||
*
|
||||
* @retval 0 for correct memory, 1 for corrupted memory. */
|
||||
int MEM_check_memory_integrity(void);
|
||||
bool MEM_check_memory_integrity(void);
|
||||
|
||||
/** Set thread locking functions for safe memory allocation from multiple
|
||||
* threads, pass NULL pointers to disable thread locking again. */
|
||||
@ -207,13 +207,13 @@ extern "C" {
|
||||
/** Get mapped memory usage. */
|
||||
uintptr_t MEM_get_mapped_memory_in_use(void);
|
||||
/** Get amount of memory blocks in use. */
|
||||
int MEM_get_memory_blocks_in_use(void);
|
||||
unsigned int MEM_get_memory_blocks_in_use(void);
|
||||
|
||||
/** Reset the peak memory statistic to zero. */
|
||||
void MEM_reset_peak_memory(void);
|
||||
|
||||
/** Get the peak memory usage in bytes, including mmap allocations. */
|
||||
uintptr_t MEM_get_peak_memory(void)
|
||||
size_t MEM_get_peak_memory(void)
|
||||
#if MEM_GNU_ATTRIBUTES
|
||||
__attribute__((warn_unused_result))
|
||||
#endif
|
||||
|
@ -37,6 +37,9 @@
|
||||
#include <stdarg.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* to ensure strict conversions */
|
||||
#include "../../source/blender/blenlib/BLI_strict_flags.h"
|
||||
|
||||
/* mmap exception */
|
||||
#if defined(WIN32)
|
||||
# include "mmap_win.h"
|
||||
@ -61,15 +64,6 @@
|
||||
|
||||
#include "atomic_ops.h"
|
||||
|
||||
/* Blame Microsoft for LLP64 and no inttypes.h, quick workaround needed: */
|
||||
#if defined(WIN64)
|
||||
# define SIZET_FORMAT "%I64u"
|
||||
# define SIZET_ARG(a) ((unsigned long long)(a))
|
||||
#else
|
||||
# define SIZET_FORMAT "%lu"
|
||||
# define SIZET_ARG(a) ((unsigned long)(a))
|
||||
#endif
|
||||
|
||||
/* Only for debugging:
|
||||
* store original buffer's name when doing MEM_dupallocN
|
||||
* helpful to profile issues with non-freed "dup_alloc" buffers,
|
||||
@ -118,6 +112,18 @@ static void memcount_raise(const char *name)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Blame Microsoft for LLP64 and no inttypes.h, quick workaround needed: */
|
||||
#if defined(WIN64)
|
||||
# define SIZET_FORMAT "%I64u"
|
||||
# define SIZET_ARG(a) ((unsigned long long)(a))
|
||||
#else
|
||||
# define SIZET_FORMAT "%lu"
|
||||
# define SIZET_ARG(a) ((unsigned long)(a))
|
||||
#endif
|
||||
|
||||
#define SIZET_ALIGN_4(len) ((len + 3) & ~(size_t)3)
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* Data definition */
|
||||
/* --------------------------------------------------------------------- */
|
||||
@ -227,7 +233,7 @@ static void (*error_callback)(const char *) = NULL;
|
||||
static void (*thread_lock_callback)(void) = NULL;
|
||||
static void (*thread_unlock_callback)(void) = NULL;
|
||||
|
||||
static int malloc_debug_memset = 0;
|
||||
static bool malloc_debug_memset = false;
|
||||
|
||||
#ifdef malloc
|
||||
#undef malloc
|
||||
@ -298,7 +304,7 @@ static void mem_unlock_thread(void)
|
||||
thread_unlock_callback();
|
||||
}
|
||||
|
||||
int MEM_check_memory_integrity(void)
|
||||
bool MEM_check_memory_integrity(void)
|
||||
{
|
||||
const char *err_val = NULL;
|
||||
MemHead *listend;
|
||||
@ -325,7 +331,7 @@ void MEM_set_lock_callback(void (*lock)(void), void (*unlock)(void))
|
||||
|
||||
void MEM_set_memory_debug(void)
|
||||
{
|
||||
malloc_debug_memset = 1;
|
||||
malloc_debug_memset = true;
|
||||
}
|
||||
|
||||
size_t MEM_allocN_len(const void *vmemh)
|
||||
@ -518,7 +524,7 @@ void *MEM_mallocN(size_t len, const char *str)
|
||||
{
|
||||
MemHead *memh;
|
||||
|
||||
len = (len + 3) & ~3; /* allocate in units of 4 */
|
||||
len = SIZET_ALIGN_4(len);
|
||||
|
||||
memh = (MemHead *)malloc(len + sizeof(MemHead) + sizeof(MemTail));
|
||||
|
||||
@ -543,7 +549,7 @@ void *MEM_callocN(size_t len, const char *str)
|
||||
{
|
||||
MemHead *memh;
|
||||
|
||||
len = (len + 3) & ~3; /* allocate in units of 4 */
|
||||
len = SIZET_ALIGN_4(len);
|
||||
|
||||
memh = (MemHead *)calloc(len + sizeof(MemHead) + sizeof(MemTail), 1);
|
||||
|
||||
@ -566,7 +572,7 @@ void *MEM_mapallocN(size_t len, const char *str)
|
||||
{
|
||||
MemHead *memh;
|
||||
|
||||
len = (len + 3) & ~3; /* allocate in units of 4 */
|
||||
len = SIZET_ALIGN_4(len);
|
||||
|
||||
#if defined(WIN32)
|
||||
/* our windows mmap implementation is not thread safe */
|
||||
@ -632,7 +638,7 @@ void MEM_printmemlist_stats(void)
|
||||
{
|
||||
MemHead *membl;
|
||||
MemPrintBlock *pb, *printblock;
|
||||
int totpb, a, b;
|
||||
unsigned int totpb, a, b;
|
||||
#ifdef HAVE_MALLOC_H
|
||||
size_t mem_in_use_slop;
|
||||
#endif
|
||||
@ -1078,9 +1084,9 @@ static const char *check_memlist(MemHead *memh)
|
||||
return(name);
|
||||
}
|
||||
|
||||
uintptr_t MEM_get_peak_memory(void)
|
||||
size_t MEM_get_peak_memory(void)
|
||||
{
|
||||
uintptr_t _peak_mem;
|
||||
size_t _peak_mem;
|
||||
|
||||
mem_lock_thread();
|
||||
_peak_mem = peak_mem;
|
||||
@ -1118,9 +1124,9 @@ uintptr_t MEM_get_mapped_memory_in_use(void)
|
||||
return _mmap_in_use;
|
||||
}
|
||||
|
||||
int MEM_get_memory_blocks_in_use(void)
|
||||
unsigned int MEM_get_memory_blocks_in_use(void)
|
||||
{
|
||||
int _totblock;
|
||||
unsigned int _totblock;
|
||||
|
||||
mem_lock_thread();
|
||||
_totblock = totblock;
|
||||
|
Loading…
Reference in New Issue
Block a user