diff options
Diffstat (limited to 'engines/sci/scicore/sci_memory.cpp')
-rw-r--r-- | engines/sci/scicore/sci_memory.cpp | 98 |
1 files changed, 40 insertions, 58 deletions
diff --git a/engines/sci/scicore/sci_memory.cpp b/engines/sci/scicore/sci_memory.cpp index 4d0395d9dd..b80d48bcbe 100644 --- a/engines/sci/scicore/sci_memory.cpp +++ b/engines/sci/scicore/sci_memory.cpp @@ -54,8 +54,7 @@ void * -_SCI_MALLOC(size_t size, const char *file, int line, const char *funct) -{ +_SCI_MALLOC(size_t size, const char *file, int line, const char *funct) { void *res; #ifdef MALLOC_DEBUG INFO_MEMORY("_SCI_MALLOC()", size, file, line, funct); @@ -71,8 +70,7 @@ _SCI_MALLOC(size_t size, const char *file, int line, const char *funct) void * -_SCI_CALLOC(size_t num, size_t size, const char *file, int line, const char *funct) -{ +_SCI_CALLOC(size_t num, size_t size, const char *file, int line, const char *funct) { void *res; #ifdef MALLOC_DEBUG INFO_MEMORY("_SCI_CALLOC()", size, file, line, funct); @@ -83,8 +81,7 @@ _SCI_CALLOC(size_t num, size_t size, const char *file, int line, const char *fun void * -_SCI_REALLOC(void *ptr, size_t size, const char *file, int line, const char *funct) -{ +_SCI_REALLOC(void *ptr, size_t size, const char *file, int line, const char *funct) { void *res; #ifdef MALLOC_DEBUG INFO_MEMORY("_SCI_REALLOC()", size, file, line, funct); @@ -95,15 +92,13 @@ _SCI_REALLOC(void *ptr, size_t size, const char *file, int line, const char *fun void -_SCI_FREE(void *ptr, const char *file, int line, const char *funct) -{ +_SCI_FREE(void *ptr, const char *file, int line, const char *funct) { #ifdef MALLOC_DEBUG INFO_MEMORY("_SCI_FREE()", 0, file, line, funct); #endif - if (!ptr) - { + if (!ptr) { fprintf(stderr, "_SCI_FREE() [%s (%s) : %u]\n", - file, funct, line); + file, funct, line); fprintf(stderr, " attempt to free NULL pointer\n"); BREAKPOINT(); } @@ -112,16 +107,14 @@ _SCI_FREE(void *ptr, const char *file, int line, const char *funct) void * -_SCI_MEMDUP(const void *ptr, size_t size, const char *file, int line, const char *funct) -{ +_SCI_MEMDUP(const void *ptr, size_t size, const char *file, int line, const char *funct) { void *res; #ifdef MALLOC_DEBUG INFO_MEMORY("_SCI_MEMDUP()", size, file, line, funct); #endif - if (!ptr) - { + if (!ptr) { fprintf(stderr, "_SCI_MEMDUP() [%s (%s) : %u]\n", - file, funct, line); + file, funct, line); fprintf(stderr, " attempt to memdup NULL pointer\n"); BREAKPOINT(); } @@ -132,16 +125,14 @@ _SCI_MEMDUP(const void *ptr, size_t size, const char *file, int line, const char char * -_SCI_STRDUP(const char *src, const char *file, int line, const char *funct) -{ +_SCI_STRDUP(const char *src, const char *file, int line, const char *funct) { void *res; #ifdef MALLOC_DEBUG INFO_MEMORY("_SCI_STRDUP()", 0, file, line, funct); #endif - if (!src) - { + if (!src) { fprintf(stderr, "_SCI_STRDUP() [%s (%s) : %u]\n", - file, funct, line); + file, funct, line); fprintf(stderr, " attempt to strdup NULL pointer\n"); BREAKPOINT(); } @@ -151,18 +142,16 @@ _SCI_STRDUP(const char *src, const char *file, int line, const char *funct) char * -_SCI_STRNDUP(const char *src, size_t length, const char *file, int line, const char *funct) -{ +_SCI_STRNDUP(const char *src, size_t length, const char *file, int line, const char *funct) { void *res; char *strres; size_t rlen = (int)MIN(strlen(src), length) + 1; #ifdef MALLOC_DEBUG INFO_MEMORY("_SCI_STRNDUP()", 0, file, line, funct); #endif - if (!src) - { + if (!src) { fprintf(stderr, "_SCI_STRNDUP() [%s (%s) : %u]\n", - file, funct, line); + file, funct, line); fprintf(stderr, " attempt to strndup NULL pointer\n"); BREAKPOINT(); } @@ -180,14 +169,13 @@ _SCI_STRNDUP(const char *src, size_t length, const char *file, int line, const c #ifdef _MSC_VER void -debug_win32_memory(int dbg_setting) -{ +debug_win32_memory(int dbg_setting) { #if defined(NDEBUG) fprintf(stderr, - "WARNING: Cannot debug Win32 memory in release mode.\n"); + "WARNING: Cannot debug Win32 memory in release mode.\n"); #elif defined(SATISFY_PURIFY) fprintf(stderr, - "WARNING: Cannot debug Win32 memory in this mode.\n"); + "WARNING: Cannot debug Win32 memory in this mode.\n"); #else int tmpFlag; @@ -196,32 +184,30 @@ debug_win32_memory(int dbg_setting) if (dbg_setting > 0) tmpFlag |= _CRTDBG_CHECK_ALWAYS_DF; - /* call _CrtCheckMemory at every request */ + /* call _CrtCheckMemory at every request */ if (dbg_setting > 1) - tmpFlag |= _CRTDBG_LEAK_CHECK_DF; - /* perform automatic leak checking at program exit */ + tmpFlag |= _CRTDBG_LEAK_CHECK_DF; + /* perform automatic leak checking at program exit */ if (dbg_setting > 2) - tmpFlag |= _CRTDBG_DELAY_FREE_MEM_DF; - /* enable debug heap allocations */ + tmpFlag |= _CRTDBG_DELAY_FREE_MEM_DF; + /* enable debug heap allocations */ - if (dbg_setting > 3) - { + if (dbg_setting > 3) { PANIC((stderr, "Invalid value for debug_win32_memory!\n")); BREAKPOINT(); } - if (dbg_setting <= 0) - { + if (dbg_setting <= 0) { /* turn off above */ tmpFlag &= ~_CRTDBG_CHECK_ALWAYS_DF; - tmpFlag &= ~_CRTDBG_DELAY_FREE_MEM_DF; - tmpFlag &= ~_CRTDBG_LEAK_CHECK_DF; + tmpFlag &= ~_CRTDBG_DELAY_FREE_MEM_DF; + tmpFlag &= ~_CRTDBG_LEAK_CHECK_DF; } /* set new state for flag */ - _CrtSetDbgFlag( tmpFlag ); + _CrtSetDbgFlag(tmpFlag); #endif } #endif @@ -245,11 +231,10 @@ debug_win32_memory(int dbg_setting) extern void * -sci_refcount_alloc(size_t length) -{ + sci_refcount_alloc(size_t length) { guint32 *data = (guint32*)sci_malloc(REFCOUNT_OVERHEAD + length); #ifdef TRACE_REFCOUNT -fprintf(stderr, "[] REF: Real-alloc at %p\n", data); + fprintf(stderr, "[] REF: Real-alloc at %p\n", data); #endif data += 3; @@ -257,32 +242,30 @@ fprintf(stderr, "[] REF: Real-alloc at %p\n", data); data[-3] = REFCOUNT_MAGIC_LIVE_2; REFCOUNT(data) = 1; #ifdef TRACE_REFCOUNT -fprintf(stderr, "[] REF: Alloc'd %p (ref=%d) OK=%d\n", data, REFCOUNT(data), - REFCOUNT_CHECK(data)); + fprintf(stderr, "[] REF: Alloc'd %p (ref=%d) OK=%d\n", data, REFCOUNT(data), + REFCOUNT_CHECK(data)); #endif return data; } extern void * -sci_refcount_incref(void *data) -{ + sci_refcount_incref(void *data) { if (!REFCOUNT_CHECK(data)) { BREAKPOINT(); } else REFCOUNT(data)++; #ifdef TRACE_REFCOUNT -fprintf(stderr, "[] REF: Inc'ing %p (now ref=%d)\n", data, REFCOUNT(data)); + fprintf(stderr, "[] REF: Inc'ing %p (now ref=%d)\n", data, REFCOUNT(data)); #endif return data; } extern void -sci_refcount_decref(void *data) -{ + sci_refcount_decref(void *data) { #ifdef TRACE_REFCOUNT -fprintf(stderr, "[] REF: Dec'ing %p (prev ref=%d) OK=%d\n", data, REFCOUNT(data), - REFCOUNT_CHECK(data)); + fprintf(stderr, "[] REF: Dec'ing %p (prev ref=%d) OK=%d\n", data, REFCOUNT(data), + REFCOUNT_CHECK(data)); #endif if (!REFCOUNT_CHECK(data)) { BREAKPOINT(); @@ -293,18 +276,17 @@ fprintf(stderr, "[] REF: Dec'ing %p (prev ref=%d) OK=%d\n", data, REFCOUNT(data) fdata[-3] = REFCOUNT_MAGIC_DEAD_2; #ifdef TRACE_REFCOUNT -fprintf(stderr, "[] REF: Freeing (%p)...\n", fdata - 3); + fprintf(stderr, "[] REF: Freeing (%p)...\n", fdata - 3); #endif sci_free(fdata - 3); #ifdef TRACE_REFCOUNT -fprintf(stderr, "[] REF: Done.\n"); + fprintf(stderr, "[] REF: Done.\n"); #endif } } extern void * -sci_refcount_memdup(void *data, size_t len) -{ + sci_refcount_memdup(void *data, size_t len) { void *dest = sci_refcount_alloc(len); memcpy(dest, data, len); return dest; |