Annotation of parser3/src/include/pa_memory.h, revision 1.1.2.9.2.3
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.3! paf 12: static const char* IDENT_MEMORY_H="$Date: 2003/03/19 13:16:56 $";
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:
1.1.2.9.2.3! paf 71: void *operator new(size_t size); // disabled, should cause link error!
! 72: void operator delete (void *ptr); // disabled, should cause link error!
! 73: void *operator new[] (size_t size); // disabled, should cause link error!
! 74:
! 75: #define UseGC ((int)1)
! 76: #define PointerFreeGC (true)
! 77:
! 78: inline void *operator new[] (size_t size, int) { // UseGC
! 79: return pa_malloc(size);
! 80: }
! 81: inline void *operator new[] (size_t size, bool) { // PointerFreeGC
1.1.2.9.2.1 paf 82: return pa_malloc_atomic(size);
1.1.2.1 paf 83: }
84: inline void operator delete[] (void *ptr) {
85: pa_free(ptr);
86: }
87:
1.1.2.9.2.1 paf 88: /// memory allocation/dallocation goes via pa_malloc/pa_free.
1.1.2.1 paf 89: class PA_Allocated {
90: public:
91: /// the sole: instances allocated using our functions
92: static void *operator new(size_t size) {
93: return pa_malloc(size);
94: }
95: static void operator delete(void *ptr) {
96: pa_free(ptr);
97: }
98: static void *malloc(size_t size) {
99: return pa_malloc(size);
100: }
1.1.2.9.2.1 paf 101: static void *malloc_atomic(size_t size) {
102: return pa_malloc_atomic(size);
1.1.2.1 paf 103: }
104: static void free(void *ptr) {
105: pa_free(ptr);
106: }
107: static void *realloc(void *ptr, size_t size) {
108: return pa_realloc(ptr, size);
109: }
1.1.2.9.2.2 paf 110:
111: private: // disabled from accidental use
112:
113: /// use malloc instead [GC clears malloc result]
114: static void *calloc(size_t size);
1.1.2.1 paf 115:
116: };
117:
1.1.2.9.2.1 paf 118: /// Base for all Parser classes
119: typedef PA_Allocated PA_Object;
1.1.2.1 paf 120:
121: // convinient types
122:
123: #endif
E-mail: