--- parser3/src/include/pa_memory.h 2003/03/19 16:28:08 1.1.2.9.2.3 +++ parser3/src/include/pa_memory.h 2003/03/24 10:21:28 1.1.2.9.2.10 @@ -9,7 +9,7 @@ #ifndef PA_MEMORY_H #define PA_MEMORY_H -static const char* IDENT_MEMORY_H="$Date: 2003/03/19 16:28:08 $"; +static const char* IDENT_MEMORY_H="$Date: 2003/03/24 10:21:28 $"; #define PA_DEBUG_REFERENCES @@ -27,7 +27,7 @@ static const char* IDENT_MEMORY_H="$Date // forwards -void *pa_fail_alloc(const char *what, size_t size); +void *pa_fail_alloc(const char* what, size_t size); // inlines @@ -44,6 +44,24 @@ inline void *pa_malloc_atomic(size_t siz return pa_fail_alloc("allocate clean", size); } +/// @a length may be null, which mean "autocalc it" +inline char *pa_strdup(const char* auto_variable_never_null, size_t length=0) { + if(!length) + length=strlen(auto_variable_never_null); + if(!length) + abort(); + + size_t size=length+1; + if(char *result=static_cast(GC_MALLOC_ATOMIC(size))) { + memcpy(result, auto_variable_never_null, length); + result[length]=0; + return result; + } + + return static_cast(pa_fail_alloc("allocate clean", size)); +} +char* pa_format_integer(int value); + inline void pa_free(void *ptr) { GC_FREE(ptr); } @@ -55,22 +73,11 @@ inline void *pa_realloc(void *ptr, size_ return pa_fail_alloc("reallocate to", size); } -#define DECLARE_OBJECT_PTR(name) \ - typedef name* name##Ptr - -#define DECLARE_SMART_PTR(name) \ - typedef name* name##Ptr - -// defines - -#define override -#define rethrow throw - -// memory - -void *operator new(size_t size); // disabled, should cause link error! -void operator delete (void *ptr); // disabled, should cause link error! -void *operator new[] (size_t size); // disabled, should cause link error! +//{@ these operators are disabled, one should explicitely specify either new(UseGC) or new(PointerFreeGC) +inline void *operator new(size_t size) { abort(); } // disabled +inline void operator delete (void *ptr) { abort(); } // disabled +inline void *operator new[] (size_t size) { abort(); } // disabled +//}@ #define UseGC ((int)1) #define PointerFreeGC (true) @@ -101,6 +108,9 @@ public: static void *malloc_atomic(size_t size) { return pa_malloc_atomic(size); } + static char *strdup(const char* auto_variable_never_null, size_t length=0) { + return pa_strdup(auto_variable_never_null, length); + } static void free(void *ptr) { pa_free(ptr); } @@ -110,7 +120,7 @@ public: private: // disabled from accidental use - /// use malloc instead [GC clears malloc result] + /// use malloc/malloc_atomic instead [GC clears result of those] static void *calloc(size_t size); }; @@ -118,6 +128,10 @@ private: // disabled from accidental use /// Base for all Parser classes typedef PA_Allocated PA_Object; -// convinient types +// defines + +#define override +#define rethrow throw + #endif