📄 dmalloc.h
字号:
/* * Defines for the dmalloc library * * Copyright 2000 by Gray Watson * * This file is part of the dmalloc package. * * Permission to use, copy, modify, and distribute this software for any * purpose and without fee is hereby granted, provided * that the above copyright notice and this permission notice appear * in all copies, and that the name of Gray Watson not be used in * advertising or publicity pertaining to distribution of the document * or software without specific, written prior permission. * * Gray Watson makes no representations about the suitability of the * software described herein for any purpose. It is provided "as is" * without express or implied warranty. * * The author may be contacted via http://dmalloc.com/ * * $Id: dmalloc.h.1,v 1.13 2000/03/21 18:19:10 gray Exp $ */#ifndef __DMALLOC_H__#define __DMALLOC_H__/* this is dmalloc.h.2 *//* produced by configure, inserted into dmalloc.h *//* const is available *//* strdup is not a macro */#undef DMALLOC_STRDUP_MACRO/* * the definition of DMALLOC_SIZE * * NOTE: some architectures have malloc, realloc, etc. * using unsigned instead of unsigned long. You may * have to edit this by hand to fix any compilation * warnings or errors. */#include <sys/types.h>#define DMALLOC_SIZE size_t/* * We use stdarg.h for the dmalloc_message and * dmalloc_vmessage functions. */#include <stdarg.h>#define DMALLOC_STDARG 1/* NOTE: start of $Id: dmalloc.h.3,v 1.50 2000/07/25 16:06:55 gray Exp $ *//* dmalloc version defines */#define DMALLOC_VERSION_MAJOR 4 /* X.0.0-b0 */#define DMALLOC_VERSION_MINOR 7 /* 0.X.0-b0 */#define DMALLOC_VERSION_PATCH 1 /* 0.0.X-b0 */#define DMALLOC_VERSION_BETA 0 /* 0.0.0-bX *//* this defines what type the standard void memory-pointer is */#if (defined(__STDC__) && __STDC__ == 1) || defined(__cplusplus)#define DMALLOC_PNT void *#define DMALLOC_FREE_RET void#else#define DMALLOC_PNT char *#define DMALLOC_FREE_RET int#endif/* * Malloc function return codes */#define CALLOC_ERROR 0L /* error from calloc */#define MALLOC_ERROR 0L /* error from malloc */#define REALLOC_ERROR 0L /* error from realloc *//* NOTE: this if for non- __STDC__ systems only */#define FREE_ERROR 0 /* error from free */#define FREE_NOERROR 1 /* no error from free */#define DMALLOC_ERROR 0 /* function failed */#define DMALLOC_NOERROR 1 /* function succeeded */#ifdef __cplusplusextern "C" {#endif/* logfile for dumping dmalloc info, DMALLOC_LOGFILE env var overrides this */extern char *dmalloc_logpath;/* internal dmalloc error number for reference purposes only */extern int dmalloc_errno;/* address to look for. when discovered call dmalloc_error() */extern DMALLOC_PNT dmalloc_address;/* * argument to dmalloc_address, if 0 then never call dmalloc_error() * else call it after seeing dmalloc_address for this many times. */extern int dmalloc_address_count;/* * shutdown memory-allocation module, provide statistics if necessary */extern void dmalloc_shutdown(void);/* * allocate and return a SIZE block of bytes. returns 0L on error. */extern DMALLOC_PNT malloc(DMALLOC_SIZE size);/* * allocate and return a block of _zeroed_ bytes able to hold * NUM_ELEMENTS, each element contains SIZE bytes. returns 0L on * error. */extern DMALLOC_PNT calloc(DMALLOC_SIZE num_elements, DMALLOC_SIZE size);/* * Resizes OLD_PNT to NEW_SIZE bytes and return the new space after * either copying all of OLD_PNT to the new area or truncating. If * OLD_PNT is 0L then it will do the equivalent of malloc(NEW_SIZE). * If NEW_SIZE is 0 and OLD_PNT is not 0L then it will do the * equivalent of free(OLD_PNT) and will return 0L. Returns 0L on * error. */extern DMALLOC_PNT realloc(DMALLOC_PNT old_pnt, DMALLOC_SIZE new_size);/* * Resizes OLD_PNT to NEW_SIZE bytes and return the new space after * either copying all of OLD_PNT to the new area or truncating. If * OLD_PNT is 0L then it will do the equivalent of malloc(NEW_SIZE). * If NEW_SIZE is 0 and OLD_PNT is not 0L then it will do the * equivalent of free(OLD_PNT) and will return 0L. Any extended * memory space will be zeroed like calloc. Returns 0L on error. */extern DMALLOC_PNT recalloc(DMALLOC_PNT old_pnt, DMALLOC_SIZE new_size);/* * Allocate and return a SIZE block of bytes that has been aligned to * ALIGNMENT bytes. ALIGNMENT must be a power of two and must be less * than or equal to the block-size. Returns 0L on error. */extern DMALLOC_PNT memalign(DMALLOC_SIZE alignment, DMALLOC_SIZE size);/* * Allocate and return a SIZE block of bytes that starts on a page * boundary. Returns 0L on error. */extern DMALLOC_PNT valloc(DMALLOC_SIZE size);#ifndef DMALLOC_STRDUP_MACRO/* * Allocate and return a block of bytes that contains the string STR * including the \0. Returns 0L on error. */extern char *strdup(const char *str);#endif/* * release PNT in the heap, returning FREE_ERROR, FREE_NOERROR or void * depending on whether STDC is defined by your compiler. */extern DMALLOC_FREE_RET free(DMALLOC_PNT pnt);/* * same as free(PNT) */extern DMALLOC_FREE_RET cfree(DMALLOC_PNT pnt);/* * log the heap structure plus information on the blocks if necessary. */extern void dmalloc_log_heap_map(void);/* * dump dmalloc statistics to logfile */extern void dmalloc_log_stats(void);/* * dump unfreed-memory info to logfile */extern void dmalloc_log_unfreed(void);/* * verify pointer PNT, if PNT is 0 then check the entire heap. * returns MALLOC_VERIFY_ERROR or MALLOC_VERIFY_NOERROR */extern int dmalloc_verify(const DMALLOC_PNT pnt);/* * same as dmalloc_verify */extern int malloc_verify(const DMALLOC_PNT pnt);/* * set the global debug functionality FLAGS to debug (0 to disable all * debugging). NOTE: after this module has started up, you cannot set * certain flags such as fence-post or free-space checking. */extern void dmalloc_debug(const int flags);/* * returns the current debug functionality flags. this allows you to * save a dmalloc library state to be restored later. */extern int dmalloc_debug_current(void);/* * Examine pointer PNT and returns SIZE, and FILE / LINE info on it, * or return-address RET_ADDR if any of the pointers are not 0L. if * FILE returns 0L then RET_ATTR may have a value and vice versa. * * Returns DMALLOC_NOERROR or DMALLOC_ERROR depending on whether PNT * is good or not */extern int dmalloc_examine(const DMALLOC_PNT pnt, DMALLOC_SIZE * size, char ** file, unsigned int * line, DMALLOC_PNT * ret_attr);#if DMALLOC_STDARG/* * Write a message into the dmalloc logfile using printf-like arguments. */extern void dmalloc_message(const char *format, ...);/* * Write a message into the dmalloc logfile using vprintf-like arguments. */extern void dmalloc_vmessage(const char *format, va_list args);#endif/* * Dmalloc function IDs for the dmalloc_track_t callback function. */#define DMALLOC_FUNC_MALLOC 10 /* malloc function called */#define DMALLOC_FUNC_CALLOC 11 /* calloc function called */#define DMALLOC_FUNC_REALLOC 12 /* realloc function called */#define DMALLOC_FUNC_RECALLOC 13 /* recalloc called */#define DMALLOC_FUNC_MEMALIGN 14 /* memalign function called */#define DMALLOC_FUNC_VALLOC 15 /* valloc function called */#define DMALLOC_FUNC_STRDUP 16 /* strdup function called */#define DMALLOC_FUNC_FREE 17 /* free function called *//* * Allocation tracking function called each time an allocation occurs. * FILE may be a return address if LINE is 0. FUNC_ID is one of the * above DMALLOC_FUNC_ defines. BYTE_SIZE is how many bytes were * requested with a possible ALIGNMENT. OLD_ADDR is for realloc and * free functions. NEW_ADDR is the pointer returned by the allocation * functions. */typedef void (*dmalloc_track_t)(const char *file, const unsigned int line, const int func_id, const DMALLOC_SIZE byte_size, const DMALLOC_SIZE alignment, const DMALLOC_PNT old_addr, const DMALLOC_PNT new_addr);/* * Register an allocation tracking function which will be called each * time an allocation occurs. Pass in NULL to disable. */extern void dmalloc_track(const dmalloc_track_t track_func);/* * Return to the caller the current ``mark'' which can be used later * to dmalloc_log_changed pointers since this point. Multiple marks * can be saved and used. */extern unsigned long dmalloc_mark(void);/* * Dump the pointers that have changed since the mark which was * returned by dmalloc_mark. If not_freed_b is set to non-0 then log * the new pointers that are non-freed. If free_b is set to non-0 * then log the new pointers that are freed. If details_b set to * non-0 then dump the individual pointers that have changed otherwise * just dump the summaries. */extern void dmalloc_log_changed(const unsigned long mark, const int not_freed_b, const int free_b, const int details_b);/* * Dmalloc version of strerror to return the string version of * ERROR_NUM. Returns an invaid errno string if ERROR_NUM is * out-of-range. */extern const char *dmalloc_strerror(const int error_num);#ifdef __cplusplus}#endif/* * alloc macros to provide for memory FILE/LINE debugging information. */#ifndef DMALLOC_DISABLE#undef malloc#define malloc(size) \ _malloc_leap(__FILE__, __LINE__, size)#undef calloc#define calloc(count, size) \ _calloc_leap(__FILE__, __LINE__, count, size)#undef realloc#define realloc(ptr, size) \ _realloc_leap(__FILE__, __LINE__, ptr, size)#undef recalloc#define recalloc(ptr, size) \ _recalloc_leap(__FILE__, __LINE__, ptr, size)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -