1 /* 2 A* ------------------------------------------------------------------- 3 B* This file contains source code for the PyMOL computer program 4 C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific. 5 D* ------------------------------------------------------------------- 6 E* It is unlawful to modify or remove this copyright notice. 7 F* ------------------------------------------------------------------- 8 G* Please see the accompanying LICENSE file for further information. 9 H* ------------------------------------------------------------------- 10 I* Additional authors of this source file include: 11 -* 12 -* 13 -* 14 Z* ------------------------------------------------------------------- 15 */ 16 #ifndef _H_os_memory 17 #define _H_os_memory 18 19 /* This file can be included by C programs for debugging of malloc, realloc, free in C 20 21 In order to use the debugging system, you must do the following... 22 23 *use os_malloc for malloc 24 *use os_realloc for realloc 25 *use os_calloc for calloc 26 *use os_free for free 27 28 */ 29 #include<stdlib.h> 30 #include<stdbool.h> 31 32 /* ==================== Master Switch ============================= 33 * Define _os_memory_debug_on to enable the debugging system... 34 * Note: the debugging system is not thread-safe, so turn this 35 * flag off when you are using threads 36 */ 37 38 #define _os_memory_debug_on 39 40 /* ================================================================ 41 * Don't touch below unless you know what you are doing */ 42 43 44 #ifndef _os_memory_debug_on 45 46 #define os_malloc malloc 47 #define os_realloc realloc 48 #define os_calloc calloc 49 #define os_free free 50 51 #define os_memory_dump() 52 53 #else 54 55 #define _OSMemoryPointer 1 56 #define _OSMemoryVLA 2 57 58 void *OSMemoryMalloc(unsigned int size,const char *file,int line,int type); 59 void *OSMemoryCalloc(unsigned int count,unsigned int size,const char *file,int line,int type); 60 void *OSMemoryRealloc(void *ptr,unsigned int size,const char *file,int line,int type); 61 void OSMemoryFree(void *ptr,const char *file,int line,int type); 62 void OSMemoryDump(void); 63 64 #define os_malloc(x) OSMemoryMalloc(x,__FILE__,__LINE__,_OSMemoryPointer) 65 #define os_calloc(n,x) OSMemoryCalloc(n,x,__FILE__,__LINE__,_OSMemoryPointer) 66 #define os_realloc(x,y) OSMemoryRealloc(x,y,__FILE__,__LINE__,_OSMemoryPointer) 67 #define os_free(x) OSMemoryFree(x,__FILE__,__LINE__,_OSMemoryPointer) 68 #define os_memory_dump() OSMemoryDump() 69 70 71 #endif 72 73 void OSMemoryZero(char *p,char *q); 74 75 #define os_zero(p,q) OSMemoryZero(p,q) 76 77 #endif 78 79 80 81 82 83 84 85