1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #ifndef _TOOLKIT_MEMORY_TRACE_H__
- #define _TOOLKIT_MEMORY_TRACE_H__
- #include "config.h"
- #pragma once
- #ifdef malloc
- #undef malloc
- #endif
- #ifdef calloc
- #undef calloc
- #endif
- #ifdef realloc
- #undef realloc
- #endif
- #ifdef free
- #undef free
- #endif
- #ifdef strdup
- #undef strdup
- #endif
- #ifdef _strdup
- #undef _strdup
- #endif
- #ifndef __GNUC__
- #ifndef __attribute__
- #define __attribute__(x) /* nothing */
- #endif
- #endif
- #define MEMTRACE_LOCATION __FILE__, __FUNCTION__, __LINE__
- /** Override malloc with toolkit_malloc. */
- #define zalloc(x) toolkit_memtrace_zalloc(x, MEMTRACE_LOCATION)
- /** Override malloc with toolkit_malloc. */
- #define malloc(x) toolkit_memtrace_malloc(x, MEMTRACE_LOCATION)
- /** Override calloc with toolkit_calloc. */
- #define calloc(x,y) toolkit_memtrace_calloc(x, y, MEMTRACE_LOCATION)
- /** Override calloc with toolkit_czalloc. */
- #define czalloc(x,y) toolkit_memtrace_czalloc(x, y, MEMTRACE_LOCATION)
- /** Override realloc with toolkit_realloc. */
- #define realloc(x,y) toolkit_memtrace_realloc(x, y, MEMTRACE_LOCATION)
- /** Override free with toolkit_free. */
- #define free(x) toolkit_memtrace_free(x, MEMTRACE_LOCATION)
- /** Override strdup() with toolkit_strdup() */
- #define strdup(x) toolkit_memtrace_strdup(x, MEMTRACE_LOCATION)
- //#define _strdup(x) toolkit_memtrace_strdup(x, MEMTRACE_LOCATION)
- #ifdef __cplusplus
- extern "C" {
- #endif
- TOOLKIT_API const char* tk_get_program_name();
- TOOLKIT_API void tk_set_program_name(const char* name);
- TOOLKIT_API void* toolkit_memtrace_zalloc(size_t bytes, const char* file, const char* function, int line);
- TOOLKIT_API void* toolkit_memtrace_malloc(size_t bytes, const char* file, const char* function, int line)
- __attribute__((no_instrument_function))
- __attribute__((malloc));
- TOOLKIT_API void* toolkit_memtrace_calloc(size_t elem, size_t ele_size, const char* file, const char* function, int line)
- __attribute__((no_instrument_function))
- __attribute__((malloc));
- TOOLKIT_API void* toolkit_memtrace_czalloc(size_t elem, size_t ele_size, const char* file, const char* function, int line);
- TOOLKIT_API void* toolkit_memtrace_realloc(void* space, size_t bytes, const char* file, const char* function, int line)
- __attribute__((no_instrument_function))
- __attribute__((warn_unused_result))
- __attribute__((malloc));
- TOOLKIT_API void toolkit_memtrace_free(void* pvSpace, const char* file, const char* function, int line)
- __attribute__((no_instrument_function));
- TOOLKIT_API char* toolkit_memtrace_strdup(const char* string, const char* file, const char* function, int line)
- __attribute__((nonnull));
- #ifdef __cplusplus
- }//extern "C" {
- #endif
- #endif /*_TOOLKIT_MEMORY_TRACE_H__*/
|