Diff for /parser3/src/targets/cgi/Attic/pa_pool.C between versions 1.36 and 1.41.4.2

version 1.36, 2002/02/08 08:30:17 version 1.41.4.2, 2003/03/18 09:53:02
Line 1 Line 1
 /** @file  /** @file
         Parser: CGI memory manager impl.          Parser: CGI memory manager impl.
   
         Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
   
         $Id$  
 */  */
   
   static const char* IDENT_POOL_C="$Date$";
   
 #include "pa_pool.h"  #include "pa_pool.h"
 #include "pool_storage.h"  
   #ifdef XML
   #       include "libxml/xmlmemory.h"
   #endif
   
   #ifdef _DEBUG
   #       define GC_DEBUG
   #endif
   #include "gc.h"
   
   
   // debug switches
   
   #define DEBUG_TOTAL_ALLOC_SIZE
   #define DEBUG_DUMP
   
   //
   
   #ifdef DEBUG_TOTAL_ALLOC_SIZE
   unsigned long total_alloc_size=0;
   #endif
   
   void Pool::log_high_watermark(const char *msg) {
           fprintf(stderr, "%s: malloced=%lu, heap_used=%lu, heap_free=%lu, bytes_since_gc=%lu, total_bytes=%lu\n",
                   msg,
                   total_alloc_size,
                   GC_get_heap_size(),
                   GC_get_free_bytes(),
                   GC_get_bytes_since_gc(),
                   GC_get_total_bytes()
                   );
   }
   
   void Pool::collect_garbage() {
   #ifdef DEBUG_DUMP
           log_high_watermark("before gc");
   #endif
   
           //GC_dont_gc=false;
           //GC_collect_a_little();
           GC_gcollect();
           GC_gcollect();
   
   #ifdef DEBUG_DUMP
           log_high_watermark("after gc");
   #endif
   }
   
   #ifdef XML
   char *pa_GC_strdup(const char *s) {
           if(!s)
                   return 0;
   
           size_t size=strlen(s)+1;
           char *result=(char *)GC_MALLOC_ATOMIC(size);
           memcpy(result, s, size);
           return result;
   }
   
   #endif
   
   void Pool::real_init() {
   #ifdef DEBUG_DUMP
           log_high_watermark("init");
   #endif
           //GC_dont_gc=true;
   #ifdef XML
           static bool XML_memory_function_overloaded=false;
           if(!XML_memory_function_overloaded) {
                   XML_memory_function_overloaded=true;
                   xmlMemSetup(/*xmlFreeFunc */GC_free,
                            /*xmlMallocFunc */GC_malloc,
                            /*xmlReallocFunc */GC_realloc,
                            /*xmlStrdupFunc */pa_GC_strdup);
           }
   #endif
   }
   void Pool::real_finit() {
           //collect_garbage();
   }
   
 void *Pool::real_malloc(size_t size, int place) {  void *Pool::real_malloc(size_t size, int place) {
         return fstorage?  #ifdef DEBUG_TOTAL_ALLOC_SIZE
                 static_cast<Pool_storage *>(fstorage)->malloc(size): ::malloc(size);          total_alloc_size+=size;
   #endif
           //printf("%d,",size);
   
           return GC_MALLOC(size);//::calloc(size,1);//
   }
   
   void *Pool::real_malloc_atomic(size_t size, int place) {
   #ifdef DEBUG_TOTAL_ALLOC_SIZE
           total_alloc_size+=size;
   #endif
   
           return GC_MALLOC_ATOMIC(size);//::calloc(size,1);//
 }  }
   
 void *Pool::real_calloc(size_t size) {  void *Pool::real_calloc(size_t size) {
         return fstorage?  #ifdef DEBUG_TOTAL_ALLOC_SIZE
                 static_cast<Pool_storage *>(fstorage)->calloc(size): ::calloc(size, 1);          total_alloc_size+=size;
   #endif
   
           return GC_MALLOC(size);//::calloc(size,1);//
 }  }
   
 bool Pool::real_register_cleanup(void (*cleanup) (void *), void *data) {  bool Pool::real_register_cleanup(void (*cleanup) (void *, void*), void *data) {
         return fstorage!=0 && static_cast<Pool_storage *>(fstorage)->register_cleanup(cleanup, data);          GC_REGISTER_FINALIZER(data, cleanup, 0, 0, 0);
           return true;
 }  }

Removed from v.1.36  
changed lines
  Added in v.1.41.4.2


E-mail: