Annotation of win32/gnome/gnome-xml/include/libxml/xmlmemory.h, revision 1.2

1.1       paf         1: /*
                      2:  * xmlmemory.h: interface for the memory allocation debug.
                      3:  *
                      4:  * daniel@veillard.com
                      5:  */
                      6: 
                      7: 
                      8: #ifndef _DEBUG_MEMORY_ALLOC_
                      9: #define _DEBUG_MEMORY_ALLOC_
                     10: 
                     11: #include <stdio.h>
                     12: #include <libxml/xmlversion.h>
                     13: 
                     14: /**
                     15:  * DEBUG_MEMORY:
                     16:  *
                     17:  * DEBUG_MEMORY replaces the allocator with a collect and debug
                     18:  * shell to the libc allocator.
                     19:  * DEBUG_MEMORY should only be activated when debugging 
                     20:  * libxml i.e. if libxml has been configured with --with-debug-mem too.
                     21:  */
                     22: /* #define DEBUG_MEMORY_FREED */
                     23: /* #define DEBUG_MEMORY_LOCATION */
                     24: 
                     25: #ifdef DEBUG
                     26: #ifndef DEBUG_MEMORY
                     27: #define DEBUG_MEMORY
                     28: #endif
                     29: #endif
                     30: 
                     31: /**
                     32:  * DEBUG_MEMORY_LOCATION:
                     33:  *
                     34:  * DEBUG_MEMORY_LOCATION should be activated only when debugging 
                     35:  * libxml i.e. if libxml has been configured with --with-debug-mem too.
                     36:  */
                     37: #ifdef DEBUG_MEMORY_LOCATION
                     38: #endif
                     39: 
                     40: #ifdef __cplusplus
                     41: extern "C" {
                     42: #endif
                     43: 
                     44: /*
                     45:  * The XML memory wrapper support 4 basic overloadable functions.
                     46:  */
                     47: /**
                     48:  * xmlFreeFunc:
                     49:  * @mem: an already allocated block of memory
                     50:  *
                     51:  * Signature for a free() implementation.
                     52:  */
                     53: typedef void (*xmlFreeFunc)(void *mem);
                     54: /**
                     55:  * xmlMallocFunc:
                     56:  * @size:  the size requested in bytes
                     57:  *
                     58:  * Signature for a malloc() implementation.
                     59:  *
                     60:  * Returns a pointer to the newly allocated block or NULL in case of error.
                     61:  */
                     62: typedef void *(*xmlMallocFunc)(size_t size);
                     63: 
                     64: /**
                     65:  * xmlReallocFunc:
                     66:  * @mem: an already allocated block of memory
                     67:  * @size:  the new size requested in bytes
                     68:  *
                     69:  * Signature for a realloc() implementation.
                     70:  *
                     71:  * Returns a pointer to the newly reallocated block or NULL in case of error.
                     72:  */
                     73: typedef void *(*xmlReallocFunc)(void *mem, size_t size);
                     74: 
                     75: /**
                     76:  * xmlStrdupFunc:
                     77:  * @str: a zero terminated string
                     78:  *
                     79:  * Signature for an strdup() implementation.
                     80:  *
                     81:  * Returns the copy of the string or NULL in case of error.
                     82:  */
                     83: typedef char *(*xmlStrdupFunc)(const char *str);
                     84: 
                     85: /*
                     86:  * The 4 interfaces used for all memory handling within libxml.
                     87: LIBXML_DLL_IMPORT extern xmlFreeFunc xmlFree;
                     88: LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMalloc;
1.2     ! paf        89: LIBXML_DLL_IMPORT extern xmlMallocFunc xmlMallocAtomic;
1.1       paf        90: LIBXML_DLL_IMPORT extern xmlReallocFunc xmlRealloc;
                     91: LIBXML_DLL_IMPORT extern xmlStrdupFunc xmlMemStrdup;
                     92:  */
                     93: 
                     94: /*
                     95:  * The way to overload the existing functions.
1.2     ! paf        96:  * The xmlGc function have an extra entry for atomic block
        !            97:  * allocations useful for garbage collected memory allocators
1.1       paf        98:  */
                     99: int     xmlMemSetup    (xmlFreeFunc freeFunc,
                    100:                         xmlMallocFunc mallocFunc,
                    101:                         xmlReallocFunc reallocFunc,
                    102:                         xmlStrdupFunc strdupFunc);
                    103: int     xmlMemGet      (xmlFreeFunc *freeFunc,
                    104:                         xmlMallocFunc *mallocFunc,
                    105:                         xmlReallocFunc *reallocFunc,
                    106:                         xmlStrdupFunc *strdupFunc);
1.2     ! paf       107: int     xmlGcMemSetup  (xmlFreeFunc freeFunc,
        !           108:                         xmlMallocFunc mallocFunc,
        !           109:                         xmlMallocFunc mallocAtomicFunc,
        !           110:                         xmlReallocFunc reallocFunc,
        !           111:                         xmlStrdupFunc strdupFunc);
        !           112: int     xmlGcMemGet    (xmlFreeFunc *freeFunc,
        !           113:                         xmlMallocFunc *mallocFunc,
        !           114:                         xmlMallocFunc *mallocAtomicFunc,
        !           115:                         xmlReallocFunc *reallocFunc,
        !           116:                         xmlStrdupFunc *strdupFunc);
1.1       paf       117: 
                    118: /*
                    119:  * Initialization of the memory layer.
                    120:  */
                    121: int    xmlInitMemory   (void);
                    122: 
                    123: /*
                    124:  * Those are specific to the XML debug memory wrapper.
                    125:  */
                    126: int    xmlMemUsed      (void);
                    127: void   xmlMemDisplay   (FILE *fp);
                    128: void   xmlMemShow      (FILE *fp, int nr);
                    129: void   xmlMemoryDump   (void);
                    130: void * xmlMemMalloc    (size_t size);
                    131: void * xmlMemRealloc   (void *ptr,size_t size);
                    132: void   xmlMemFree      (void *ptr);
                    133: char * xmlMemoryStrdup (const char *str);
                    134: 
                    135: #ifdef DEBUG_MEMORY_LOCATION
                    136: /**
                    137:  * xmlMalloc:
                    138:  * @size:  number of bytes to allocate
                    139:  *
                    140:  * Wrapper for the malloc() function used in the XML library.
                    141:  *
                    142:  * Returns the pointer to the allocated area or NULL in case of error.
                    143:  */
                    144: #define xmlMalloc(size) xmlMallocLoc((size), __FILE__, __LINE__)
1.2     ! paf       145: /**
        !           146:  * xmlMallocAtomic:
        !           147:  * @size:  number of bytes to allocate
        !           148:  *
        !           149:  * Wrapper for the malloc() function used in the XML library for allocation
        !           150:  * of block not containing pointers to other areas.
        !           151:  *
        !           152:  * Returns the pointer to the allocated area or NULL in case of error.
        !           153:  */
        !           154: #define xmlMallocAtomic(size) xmlMallocAtomicLoc((size), __FILE__, __LINE__)
1.1       paf       155: /**
                    156:  * xmlRealloc:
                    157:  * @ptr:  pointer to the existing allocated area
                    158:  * @size:  number of bytes to allocate
                    159:  *
                    160:  * Wrapper for the realloc() function used in the XML library.
                    161:  *
                    162:  * Returns the pointer to the allocated area or NULL in case of error.
                    163:  */
                    164: #define xmlRealloc(ptr, size) xmlReallocLoc((ptr), (size), __FILE__, __LINE__)
                    165: /**
                    166:  * xmlMemStrdup:
                    167:  * @str:  pointer to the existing string
                    168:  *
                    169:  * Wrapper for the strdup() function, xmlStrdup() is usually preferred.
                    170:  *
                    171:  * Returns the pointer to the allocated area or NULL in case of error.
                    172:  */
                    173: #define xmlMemStrdup(str) xmlMemStrdupLoc((str), __FILE__, __LINE__)
                    174: 
                    175: void * xmlMallocLoc(size_t size, const char *file, int line);
                    176: void * xmlReallocLoc(void *ptr,size_t size, const char *file, int line);
                    177: char * xmlMemStrdupLoc(const char *str, const char *file, int line);
                    178: #endif /* DEBUG_MEMORY_LOCATION */
                    179: 
                    180: #ifdef __cplusplus
                    181: }
                    182: #endif /* __cplusplus */
                    183: 
                    184: #ifndef __XML_GLOBALS_H
                    185: #ifndef __XML_THREADS_H__
                    186: #include <libxml/threads.h>
                    187: #include <libxml/globals.h>
                    188: #endif
                    189: #endif
                    190: 
                    191: #endif  /* _DEBUG_MEMORY_ALLOC_ */
                    192: 

E-mail: