Cleanup: trailing space guardedalloc & memutil
This commit is contained in:
parent
d8a082f914
commit
4d29312c66
|
@ -48,11 +48,11 @@
|
|||
*
|
||||
* There are currently no known issues with MEM. Note that there is a
|
||||
* second intern/ module with MEM_ prefix, for use in c++.
|
||||
*
|
||||
*
|
||||
* \subsection memdependencies Dependencies
|
||||
* - stdlib
|
||||
* - stdio
|
||||
*
|
||||
*
|
||||
* \subsection memdocs API Documentation
|
||||
* See \ref MEM_guardedalloc.h
|
||||
*/
|
||||
|
@ -146,11 +146,11 @@ extern "C" {
|
|||
extern void *(*MEM_mapallocN)(size_t len, const char *str) /* ATTR_MALLOC */ ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2);
|
||||
|
||||
/** Print a list of the names and sizes of all allocated memory
|
||||
* blocks. as a python dict for easy investigation */
|
||||
* blocks. as a python dict for easy investigation */
|
||||
extern void (*MEM_printmemlist_pydict)(void);
|
||||
|
||||
/** Print a list of the names and sizes of all allocated memory
|
||||
* blocks. */
|
||||
* blocks. */
|
||||
extern void (*MEM_printmemlist)(void);
|
||||
|
||||
/** calls the function on all allocated memory blocks. */
|
||||
|
@ -158,7 +158,7 @@ extern "C" {
|
|||
|
||||
/** Print statistics about memory usage */
|
||||
extern void (*MEM_printmemlist_stats)(void);
|
||||
|
||||
|
||||
/** Set the callback function for error output. */
|
||||
extern void (*MEM_set_error_callback)(void (*func)(const char *));
|
||||
|
||||
|
@ -171,7 +171,7 @@ extern "C" {
|
|||
/** Set thread locking functions for safe memory allocation from multiple
|
||||
* threads, pass NULL pointers to disable thread locking again. */
|
||||
extern void (*MEM_set_lock_callback)(void (*lock)(void), void (*unlock)(void));
|
||||
|
||||
|
||||
/** Attempt to enforce OSX (or other OS's) to have malloc and stack nonzero */
|
||||
extern void (*MEM_set_memory_debug)(void);
|
||||
|
||||
|
|
|
@ -197,7 +197,7 @@ static const char *check_memlist(MemHead *memh);
|
|||
/* --------------------------------------------------------------------- */
|
||||
/* vars */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
|
||||
|
||||
static unsigned int totblock = 0;
|
||||
static size_t mem_in_use = 0, mmap_in_use = 0, peak_mem = 0;
|
||||
|
@ -289,7 +289,7 @@ bool MEM_guarded_consistency_check(void)
|
|||
/* check_memlist starts from the front, and runs until it finds
|
||||
* the requested chunk. For this test, that's the last one. */
|
||||
listend = membase->last;
|
||||
|
||||
|
||||
err_val = check_memlist(listend);
|
||||
|
||||
return (err_val == NULL);
|
||||
|
@ -316,7 +316,7 @@ size_t MEM_guarded_allocN_len(const void *vmemh)
|
|||
{
|
||||
if (vmemh) {
|
||||
const MemHead *memh = vmemh;
|
||||
|
||||
|
||||
memh--;
|
||||
return memh->len;
|
||||
}
|
||||
|
@ -328,7 +328,7 @@ size_t MEM_guarded_allocN_len(const void *vmemh)
|
|||
void *MEM_guarded_dupallocN(const void *vmemh)
|
||||
{
|
||||
void *newp = NULL;
|
||||
|
||||
|
||||
if (vmemh) {
|
||||
const MemHead *memh = vmemh;
|
||||
memh--;
|
||||
|
@ -378,7 +378,7 @@ void *MEM_guarded_dupallocN(const void *vmemh)
|
|||
void *MEM_guarded_reallocN_id(void *vmemh, size_t len, const char *str)
|
||||
{
|
||||
void *newp = NULL;
|
||||
|
||||
|
||||
if (vmemh) {
|
||||
MemHead *memh = vmemh;
|
||||
memh--;
|
||||
|
@ -485,7 +485,7 @@ static void print_memhead_backtrace(MemHead *memh)
|
|||
static void make_memhead_header(MemHead *memh, size_t len, const char *str)
|
||||
{
|
||||
MemTail *memt;
|
||||
|
||||
|
||||
memh->tag1 = MEMTAG1;
|
||||
memh->name = str;
|
||||
memh->nextname = NULL;
|
||||
|
@ -522,7 +522,7 @@ void *MEM_guarded_mallocN(size_t len, const char *str)
|
|||
MemHead *memh;
|
||||
|
||||
len = SIZET_ALIGN_4(len);
|
||||
|
||||
|
||||
memh = (MemHead *)malloc(len + sizeof(MemHead) + sizeof(MemTail));
|
||||
|
||||
if (LIKELY(memh)) {
|
||||
|
@ -785,7 +785,7 @@ void MEM_guarded_printmemlist_stats(void)
|
|||
(double)pb->len / 1024.0 / (double)pb->items, pb->name);
|
||||
}
|
||||
free(printblock);
|
||||
|
||||
|
||||
mem_unlock_thread();
|
||||
|
||||
#ifdef HAVE_MALLOC_STATS
|
||||
|
@ -823,7 +823,7 @@ static void MEM_guarded_printmemlist_internal(int pydict)
|
|||
|
||||
membl = membase->first;
|
||||
if (membl) membl = MEMNEXT(membl);
|
||||
|
||||
|
||||
if (pydict) {
|
||||
print_error("# membase_debug.py\n");
|
||||
print_error("membase = [\n");
|
||||
|
@ -856,7 +856,7 @@ static void MEM_guarded_printmemlist_internal(int pydict)
|
|||
print_error("]\n\n");
|
||||
print_error(mem_printmemlist_pydict_script);
|
||||
}
|
||||
|
||||
|
||||
mem_unlock_thread();
|
||||
}
|
||||
|
||||
|
@ -940,7 +940,7 @@ void MEM_guarded_freeN(void *vmemh)
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
memh--;
|
||||
if (memh->tag1 == MEMFREE && memh->tag2 == MEMFREE) {
|
||||
MemorY_ErroR(memh->name, "double free");
|
||||
|
@ -953,7 +953,7 @@ void MEM_guarded_freeN(void *vmemh)
|
|||
{
|
||||
memt = (MemTail *)(((char *) memh) + sizeof(MemHead) + memh->len);
|
||||
if (memt->tag3 == MEMTAG3) {
|
||||
|
||||
|
||||
memh->tag1 = MEMFREE;
|
||||
memh->tag2 = MEMFREE;
|
||||
memt->tag3 = MEMFREE;
|
||||
|
|
|
@ -53,4 +53,3 @@ MEM_INLINE bool MEM_size_safe_multiply(size_t a, size_t b, size_t *result)
|
|||
}
|
||||
|
||||
#endif /* __MALLOCN_INLINE_H__ */
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|
@ -214,7 +214,7 @@ static void *mmap_findlink(volatile mmapListBase *listbase, void *ptr)
|
|||
|
||||
if (ptr == NULL) return NULL;
|
||||
if (listbase == NULL) return NULL;
|
||||
|
||||
|
||||
mm = (MemMap *)listbase->first;
|
||||
while (mm) {
|
||||
if (mm->mmap == ptr) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|
@ -29,7 +29,7 @@
|
|||
* \ingroup MEM
|
||||
* \author Andrea Weikert
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __MMAP_WIN_H__
|
||||
#define __MMAP_WIN_H__
|
||||
|
||||
|
@ -57,4 +57,3 @@ void *mmap(void *start, size_t len, int prot, int flags, int fd, off_t offset);
|
|||
intptr_t munmap(void *ptr, size_t size);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -60,10 +60,10 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* ----------------------------------------------------------------- */
|
||||
switch (argc) {
|
||||
case 2:
|
||||
case 2:
|
||||
verbose = atoi(argv[1]);
|
||||
if (verbose < 0) verbose = 0;
|
||||
break;
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
verbose = 0;
|
||||
|
@ -77,7 +77,7 @@ int main(int argc, char *argv[])
|
|||
/* ----------------------------------------------------------------- */
|
||||
/* flush mem lib output to stderr */
|
||||
MEM_set_error_callback(mem_error_cb);
|
||||
|
||||
|
||||
for (i = 0; i < NUM_BLOCKS; i++) {
|
||||
int blocksize = 10000;
|
||||
char tagstring[1000];
|
||||
|
@ -99,7 +99,7 @@ int main(int argc, char *argv[])
|
|||
else {
|
||||
fprintf(stderr, "|--* Memory tested as good (as it should be)\n|\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_BLOCKS; i++) {
|
||||
MEM_freeN(p[i]);
|
||||
|
@ -124,11 +124,11 @@ int main(int argc, char *argv[])
|
|||
for (i = 0; i< 1000; i++,ip++) *ip = i+1;
|
||||
ip = (int*) p[6];
|
||||
*(ip+10005) = 0;
|
||||
|
||||
|
||||
retval = MEM_consistency_check();
|
||||
|
||||
/* the test should have failed */
|
||||
error_status |= !retval;
|
||||
error_status |= !retval;
|
||||
if (verbose) {
|
||||
if (retval) {
|
||||
fprintf(stderr, "|--* Memory test failed (as it should be)\n");
|
||||
|
@ -136,8 +136,8 @@ int main(int argc, char *argv[])
|
|||
else {
|
||||
fprintf(stderr, "|--* Memory test FAILED to find corrupted blocks \n");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_BLOCKS; i++) {
|
||||
MEM_freeN(p[i]);
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ int main(int argc, char *argv[])
|
|||
if (verbose && error_status) {
|
||||
fprintf(stderr,"|--* Memory was corrupted\n");
|
||||
}
|
||||
/* ----------------------------------------------------------------- */
|
||||
/* ----------------------------------------------------------------- */
|
||||
if (verbose) {
|
||||
if (error_status) {
|
||||
fprintf(stderr,"|\n|--* Errors were detected\n");
|
||||
|
@ -154,10 +154,8 @@ int main(int argc, char *argv[])
|
|||
else {
|
||||
fprintf(stderr,"|\n|--* Test exited succesfully\n");
|
||||
}
|
||||
|
||||
|
||||
fprintf(stderr,"|\n*** Finished test\n\n");
|
||||
}
|
||||
return error_status;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -43,8 +43,8 @@ struct MEM_Allocator
|
|||
typedef _Tp value_type;
|
||||
|
||||
template<typename _Tp1>
|
||||
struct rebind {
|
||||
typedef MEM_Allocator<_Tp1> other;
|
||||
struct rebind {
|
||||
typedef MEM_Allocator<_Tp1> other;
|
||||
};
|
||||
|
||||
MEM_Allocator() throw() {}
|
||||
|
@ -75,16 +75,16 @@ struct MEM_Allocator
|
|||
MEM_freeN(__p);
|
||||
}
|
||||
|
||||
size_type max_size() const throw() {
|
||||
return size_t(-1) / sizeof(_Tp);
|
||||
size_type max_size() const throw() {
|
||||
return size_t(-1) / sizeof(_Tp);
|
||||
}
|
||||
|
||||
void construct(pointer __p, const _Tp& __val) {
|
||||
new(__p) _Tp(__val);
|
||||
void construct(pointer __p, const _Tp& __val) {
|
||||
new(__p) _Tp(__val);
|
||||
}
|
||||
|
||||
void destroy(pointer __p) {
|
||||
__p->~_Tp();
|
||||
void destroy(pointer __p) {
|
||||
__p->~_Tp();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -58,19 +58,19 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns the reference count of this object.
|
||||
* @return the reference count.
|
||||
*/
|
||||
inline virtual int getRef() const;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Increases the reference count of this object.
|
||||
* @return the new reference count.
|
||||
*/
|
||||
inline virtual int incRef();
|
||||
|
||||
/**
|
||||
/**
|
||||
* Decreases the reference count of this object.
|
||||
* If the reference count reaches zero, the object self-destructs.
|
||||
* @return the new reference count.
|
||||
|
@ -113,4 +113,3 @@ inline int MEM_RefCounted::decRef()
|
|||
}
|
||||
|
||||
#endif // __MEM_REFCOUNTED_H__
|
||||
|
||||
|
|
|
@ -48,21 +48,21 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns the reference count of this object.
|
||||
* @param shared The object to query.
|
||||
* @return The current reference count.
|
||||
*/
|
||||
extern int MEM_RefCountedGetRef(MEM_TRefCountedObjectPtr shared);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Increases the reference count of this object.
|
||||
* @param shared The object to query.
|
||||
* @return The new reference count.
|
||||
*/
|
||||
extern int MEM_RefCountedIncRef(MEM_TRefCountedObjectPtr shared);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Decreases the reference count of this object.
|
||||
* If the reference count reaches zero, the object self-destructs.
|
||||
* @param shared The object to query.
|
||||
|
|
Loading…
Reference in New Issue