Diff for /XML/xmlmemory.c between versions 1.6 and 1.7

version 1.6, 1999/10/08 09:35:42 version 1.7, 1999/10/14 08:26:49
Line 23 Line 23
 #ifdef HAVE_MALLOC_H  #ifdef HAVE_MALLOC_H
 #include <malloc.h>  #include <malloc.h>
 #endif  #endif
   #ifdef HAVE_STDLIB_H
   #include <stdlib.h>
   #endif
   
   
 #include "xmlmemory.h"  #include "xmlmemory.h"
   
Line 78  typedef struct memnod { Line 82  typedef struct memnod {
   
   
 static unsigned long  debugMemSize = 0;  static unsigned long  debugMemSize = 0;
   static unsigned long  debugMaxMemSize = 0;
 static int block=0;  static int block=0;
   int xmlMemStopAtBlock = 0;
   int xmlMemInitialized = 0;
 #ifdef MEM_LIST  #ifdef MEM_LIST
 static MEMHDR *memlist = NULL;  static MEMHDR *memlist = NULL;
 #endif  #endif
Line 95  void debugmem_list_delete(MEMHDR *); Line 102  void debugmem_list_delete(MEMHDR *);
 #endif  #endif
   
 /**  /**
    * xmlMallocBreakpoint:
    *
    * Breakpoint to use in conjunction with xmlMemStopAtBlock. When the block
    * number reaches the specified value this function is called. One need to add a breakpoint
    * to it to get the context in which the given block is allocated.
    */
   
   void
   xmlMallocBreakpoint(void) {
       fprintf(stderr, "xmlMallocBreakpoint reached on block %d\n", xmlMemStopAtBlock);
   }
   
   /**
  * xmlMallocLoc:   * xmlMallocLoc:
  * @size:  an int specifying the size in byte to allocate.   * @size:  an int specifying the size in byte to allocate.
  * @file:  the file name or NULL   * @file:  the file name or NULL
  * @file:  the line number    @file:  the line number
  *   *
  * a malloc() equivalent, with logging of the allocation info.   * a malloc() equivalent, with logging of the allocation info.
  *   *
Line 110  xmlMallocLoc(int size, const char * file Line 130  xmlMallocLoc(int size, const char * file
 {  {
     MEMHDR *p;      MEMHDR *p;
           
       if (!xmlMemInitialized) xmlInitMemory();
 #ifdef DEBUG_MEMORY  #ifdef DEBUG_MEMORY
     fprintf(stderr, "Malloc(%d)\n",size);      fprintf(stderr, "Malloc(%d)\n",size);
 #endif  #endif
Line 129  xmlMallocLoc(int size, const char * file Line 150  xmlMallocLoc(int size, const char * file
     p->mh_file = file;      p->mh_file = file;
     p->mh_line = line;      p->mh_line = line;
     debugMemSize += size;      debugMemSize += size;
       if (debugMemSize > debugMaxMemSize) debugMaxMemSize = debugMemSize;
 #ifdef MEM_LIST  #ifdef MEM_LIST
     debugmem_list_add(p);      debugmem_list_add(p);
 #endif  #endif
Line 137  xmlMallocLoc(int size, const char * file Line 159  xmlMallocLoc(int size, const char * file
     fprintf(stderr, "Malloc(%d) Ok\n",size);      fprintf(stderr, "Malloc(%d) Ok\n",size);
 #endif  #endif
           
       if (xmlMemStopAtBlock == block) xmlMallocBreakpoint();
   
     TEST_POINT      TEST_POINT
   
Line 176  xmlReallocLoc(void *ptr,int size, const Line 199  xmlReallocLoc(void *ptr,int size, const
     MEMHDR *p;      MEMHDR *p;
     unsigned long number;      unsigned long number;
   
       if (!xmlMemInitialized) xmlInitMemory();
     TEST_POINT      TEST_POINT
   
     p = CLIENT_2_HDR(ptr);      p = CLIENT_2_HDR(ptr);
Line 201  xmlReallocLoc(void *ptr,int size, const Line 225  xmlReallocLoc(void *ptr,int size, const
     p->mh_file = file;      p->mh_file = file;
     p->mh_line = line;      p->mh_line = line;
     debugMemSize += size;      debugMemSize += size;
       if (debugMemSize > debugMaxMemSize) debugMaxMemSize = debugMemSize;
 #ifdef MEM_LIST  #ifdef MEM_LIST
     debugmem_list_add(p);      debugmem_list_add(p);
 #endif  #endif
Line 281  xmlMemStrdupLoc(const char *str, const c Line 306  xmlMemStrdupLoc(const char *str, const c
     size_t size = strlen(str) + 1;      size_t size = strlen(str) + 1;
     MEMHDR *p;      MEMHDR *p;
   
       if (!xmlMemInitialized) xmlInitMemory();
     TEST_POINT      TEST_POINT
   
     p = (MEMHDR *) malloc(RESERVE_SIZE+size);      p = (MEMHDR *) malloc(RESERVE_SIZE+size);
Line 294  xmlMemStrdupLoc(const char *str, const c Line 320  xmlMemStrdupLoc(const char *str, const c
     p->mh_file = file;      p->mh_file = file;
     p->mh_line = line;      p->mh_line = line;
     debugMemSize += size;      debugMemSize += size;
       if (debugMemSize > debugMaxMemSize) debugMaxMemSize = debugMemSize;
 #ifdef MEM_LIST  #ifdef MEM_LIST
     debugmem_list_add(p);      debugmem_list_add(p);
 #endif  #endif
     s = HDR_2_CLIENT(p);      s = HDR_2_CLIENT(p);
           
       if (xmlMemStopAtBlock == block) xmlMallocBreakpoint();
   
     if (s != NULL)      if (s != NULL)
       strcpy(s,str);        strcpy(s,str);
     else      else
Line 365  xmlMemDisplay(FILE *fp) Line 394  xmlMemDisplay(FILE *fp)
 #endif  #endif
   
           
     fprintf(fp,"      MEMORY ALLOCATED : %lu\n",debugMemSize);      fprintf(fp,"      MEMORY ALLOCATED : %lu, MAX was %lu\n",
               debugMemSize, debugMaxMemSize);
     fprintf(fp,"BLOCK  NUMBER   SIZE  TYPE\n");      fprintf(fp,"BLOCK  NUMBER   SIZE  TYPE\n");
     idx = 0;      idx = 0;
     p = memlist;      p = memlist;
Line 473  int Line 503  int
 xmlInitMemory(void)  xmlInitMemory(void)
 {  {
      int ret;       int ret;
        
   #ifdef HAVE_STDLIB_H
        char *breakpoint;
   
        breakpoint = getenv("XML_MEM_BREAKPOINT");
        if (breakpoint != NULL) {
            sscanf(breakpoint, "%d", &xmlMemStopAtBlock);
        }
   #endif     
           
 #ifdef DEBUG_MEMORY  #ifdef DEBUG_MEMORY
      fprintf(stderr, "xmlInitMemory() Ok\n");       fprintf(stderr, "xmlInitMemory() Ok\n");

Removed from v.1.6  
changed lines
  Added in v.1.7


Webmaster