Annotation of parser3/src/include/pa_memory.h, revision 1.1.2.9.2.2

1.1.2.1   paf         1: /** @file
                      2:        Parser: memory reference counting classes decls.
                      3: 
                      4:        Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
                      5: 
                      6:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
                      7: */
                      8: 
                      9: #ifndef PA_MEMORY_H
                     10: #define PA_MEMORY_H
                     11: 
1.1.2.9.2.2! paf        12: static const char* IDENT_MEMORY_H="$Date: 2003/03/18 15:14:16 $";
1.1.2.9   paf        13: 
                     14: #define PA_DEBUG_REFERENCES
1.1.2.1   paf        15: 
                     16: // include
                     17: 
                     18: #include "pa_config_includes.h"
1.1.2.9.2.1  paf        19: #include "gc.h"
                     20: 
1.1.2.1   paf        21: 
                     22: #ifdef XML
                     23: #      include "gdome.h"
                     24: // for xmlChar
                     25: #      include "libxml/tree.h"
                     26: #endif
                     27: 
                     28: // forwards
                     29: 
1.1.2.9.2.1  paf        30: void *pa_fail_alloc(const char *what, size_t size);
1.1.2.2   paf        31: 
                     32: // inlines
                     33: 
                     34: inline void *pa_malloc(size_t size) {
1.1.2.9.2.1  paf        35:        if(void *result=GC_MALLOC(size))
1.1.2.2   paf        36:                return result;
                     37: 
                     38:        return pa_fail_alloc("allocate", size);
                     39: }
                     40: 
1.1.2.9.2.1  paf        41: inline void *pa_malloc_atomic(size_t size) {
                     42:        if(void *result=GC_MALLOC_ATOMIC(size))
1.1.2.2   paf        43:                return result;
                     44: 
                     45:        return pa_fail_alloc("allocate clean", size);
                     46: }
                     47: inline void pa_free(void *ptr) {
1.1.2.9.2.1  paf        48:        GC_FREE(ptr);
1.1.2.2   paf        49: }
                     50: 
                     51: inline void *pa_realloc(void *ptr, size_t size) {
1.1.2.9.2.1  paf        52:        if(void *result=GC_REALLOC(ptr, size))
1.1.2.2   paf        53:                return result;
                     54: 
                     55:        return pa_fail_alloc("reallocate to", size);
                     56: }
1.1.2.1   paf        57: 
                     58: #define DECLARE_OBJECT_PTR(name) \
1.1.2.9.2.1  paf        59:        typedef name* name##Ptr
1.1.2.6   paf        60: 
                     61: #define DECLARE_SMART_PTR(name) \
1.1.2.9.2.1  paf        62:        typedef name* name##Ptr
1.1.2.1   paf        63: 
                     64: // defines
                     65: 
                     66: #define override
                     67: #define rethrow throw
                     68: 
                     69: // memory
                     70: 
                     71: inline void *operator new[] (size_t size) {
1.1.2.9.2.1  paf        72:        return pa_malloc_atomic(size);
1.1.2.1   paf        73: }
                     74: inline void operator delete[] (void *ptr) {
                     75:        pa_free(ptr);
                     76: }
                     77: inline void operator delete (void *ptr) {
1.1.2.9.2.1  paf        78:        abort();
1.1.2.1   paf        79: }
                     80: 
1.1.2.9.2.1  paf        81: /// memory allocation/dallocation goes via pa_malloc/pa_free.
1.1.2.1   paf        82: class PA_Allocated {
                     83: public:
                     84:        /// the sole: instances allocated using our functions
                     85:        static void *operator new(size_t size) { 
                     86:                return pa_malloc(size);
                     87:        }
                     88:        static void operator delete(void *ptr) {
                     89:                pa_free(ptr);
                     90:        }
                     91:        static void *malloc(size_t size) {
                     92:                return pa_malloc(size);
                     93:        }
1.1.2.9.2.1  paf        94:        static void *malloc_atomic(size_t size) {
                     95:                return pa_malloc_atomic(size);
1.1.2.1   paf        96:        }
                     97:        static void free(void *ptr) {
                     98:                pa_free(ptr);
                     99:        }
                    100:        static void *realloc(void *ptr, size_t size) {
                    101:                return pa_realloc(ptr, size);
                    102:        }
1.1.2.9.2.2! paf       103: 
        !           104: private: // disabled from accidental use
        !           105: 
        !           106:        /// use malloc instead [GC clears malloc result]
        !           107:        static void *calloc(size_t size);
1.1.2.1   paf       108: 
                    109: };
                    110: 
1.1.2.9.2.1  paf       111: /// Base for all Parser classes
                    112: typedef PA_Allocated PA_Object;
1.1.2.1   paf       113: 
                    114: // convinient types
                    115: 
                    116: #endif

E-mail: