Annotation of parser3/src/targets/cgi/pa_pool.C, revision 1.41.4.1

1.4       paf         1: /** @file
                      2:        Parser: CGI memory manager impl.
                      3: 
1.41      paf         4:        Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com)
1.36      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.39      paf         6: */
1.4       paf         7: 
1.41.4.1! paf         8: static const char* IDENT_POOL_C="$Date: 2003/01/21 15:51:16 $";
1.1       paf         9: 
                     10: #include "pa_pool.h"
                     11: 
1.41.4.1! paf        12: #ifdef XML
        !            13: #      include "libxml/xmlmemory.h"
        !            14: #endif
        !            15: 
        !            16: #ifdef _DEBUG
        !            17: #      define GC_DEBUG
        !            18: #endif
        !            19: #include "gc.h"
        !            20: 
1.37      paf        21: 
1.41.4.1! paf        22: // debug switches
        !            23: 
        !            24: #define DEBUG_TOTAL_ALLOC_SIZE
        !            25: #define DEBUG_DUMP
        !            26: 
        !            27: //
        !            28: 
        !            29: #ifdef DEBUG_TOTAL_ALLOC_SIZE
1.37      paf        30: unsigned long total_alloc_size=0;
                     31: #endif
                     32: 
1.41.4.1! paf        33: 
        !            34: #ifdef DEBUG_DUMP
        !            35: static void dump(const char *msg) {
        !            36:        fprintf(stderr, "%s: malloced=%lu, heap_used=%lu, heap_free=%lu, bytes_since_gc=%lu, total_bytes=%lu\n",
        !            37:                msg,
        !            38:                total_alloc_size,
        !            39:                GC_get_heap_size(),
        !            40:                GC_get_free_bytes(),
        !            41:                GC_get_bytes_since_gc(),
        !            42:                GC_get_total_bytes()
        !            43:                );
        !            44: }
        !            45: #endif
        !            46: void Pool::collect_garbage() {
        !            47: #ifdef DEBUG_DUMP
        !            48:        dump("before gc");
        !            49: #endif
        !            50: 
        !            51:        //GC_dont_gc=false;
        !            52:        //GC_collect_a_little();
        !            53:        GC_gcollect();
        !            54:        GC_gcollect();
        !            55: 
        !            56: #ifdef DEBUG_DUMP
        !            57:        dump("after gc");
        !            58: #endif
        !            59: }
        !            60: 
        !            61: #ifdef XML
        !            62: char *pa_GC_strdup(const char *s) {
        !            63:        if(!s)
        !            64:                return 0;
        !            65: 
        !            66:        size_t size=strlen(s)+1;
        !            67:        char *result=(char *)GC_MALLOC_ATOMIC(size);
        !            68:        memcpy(result, s, size);
        !            69:        return result;
        !            70: }
        !            71: 
        !            72: #endif
        !            73: 
        !            74: void Pool::real_init() {
        !            75: #ifdef DEBUG_DUMP
        !            76:        dump("init");
        !            77: #endif
        !            78:        //GC_dont_gc=true;
        !            79: #ifdef XML
        !            80:        static bool XML_memory_function_overloaded=false;
        !            81:        if(!XML_memory_function_overloaded) {
        !            82:                XML_memory_function_overloaded=true;
        !            83:                xmlMemSetup(/*xmlFreeFunc */GC_free,
        !            84:                         /*xmlMallocFunc */GC_malloc,
        !            85:                         /*xmlReallocFunc */GC_realloc,
        !            86:                         /*xmlStrdupFunc */pa_GC_strdup);
        !            87:        }
        !            88: #endif
        !            89: }
        !            90: void Pool::real_finit() {
        !            91:        //collect_garbage();
        !            92: }
        !            93: 
1.25      paf        94: void *Pool::real_malloc(size_t size, int place) {
1.41.4.1! paf        95: #ifdef DEBUG_TOTAL_ALLOC_SIZE
        !            96:        total_alloc_size+=size;
        !            97: #endif
        !            98:        //printf("%d,",size);
        !            99: 
        !           100:        return GC_MALLOC(size);//::calloc(size,1);//
        !           101: }
        !           102: 
        !           103: void *Pool::real_malloc_atomic(size_t size, int place) {
        !           104: #ifdef DEBUG_TOTAL_ALLOC_SIZE
1.37      paf       105:        total_alloc_size+=size;
                    106: #endif
                    107: 
1.41.4.1! paf       108:        return GC_MALLOC_ATOMIC(size);//::calloc(size,1);//
1.1       paf       109: }
                    110: 
                    111: void *Pool::real_calloc(size_t size) {
1.41.4.1! paf       112: #ifdef DEBUG_TOTAL_ALLOC_SIZE
1.37      paf       113:        total_alloc_size+=size;
                    114: #endif
                    115: 
1.41.4.1! paf       116:        return GC_MALLOC(size);//::calloc(size,1);//
1.1       paf       117: }
1.18      parser    118: 
1.41.4.1! paf       119: bool Pool::real_register_cleanup(void (*cleanup) (void *, void*), void *data) {
        !           120:        GC_REGISTER_FINALIZER(data, cleanup, 0, 0, 0);
        !           121:        return true;
1.34      paf       122: }

E-mail: