diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-06-28 15:50:47 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-06-28 15:50:47 +0000 |
commit | caec161501b7157e102c7e6532084616e8dce176 (patch) | |
tree | 309db281ba8898f82b385aff3c36369bc34a9031 /sca-cpp/trunk/kernel/gc.hpp | |
parent | 1e9176c21306dd9af9671f3599c377811f73bebc (diff) |
Port to Mac OS X 10.6.7.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1140690 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | sca-cpp/trunk/kernel/gc.hpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/sca-cpp/trunk/kernel/gc.hpp b/sca-cpp/trunk/kernel/gc.hpp index d843b50ca0..2a8303f638 100644 --- a/sca-cpp/trunk/kernel/gc.hpp +++ b/sca-cpp/trunk/kernel/gc.hpp @@ -29,6 +29,7 @@ #include <stdlib.h> #include <apr_general.h> #include <apr_pools.h> +#include <apr_strings.h> #include <assert.h> #include <new> #include "config.hpp" @@ -298,6 +299,45 @@ char* gc_cnew(size_t n) { return gc_cnew(gc_current_pool(), n); } +/** + * Pool based equivalent of the standard malloc function. + */ +void* gc_malloc(size_t n) { + size_t* gc_malloc_ptr = static_cast<size_t*>(apr_palloc(gc_current_pool(), sizeof(size_t) + n)); + assertOrFail(gc_malloc_ptr != NULL); + *gc_malloc_ptr = n; + return gc_malloc_ptr + 1; +} + +/** + * Pool based equivalent of the standard realloc function. + */ +void* gc_realloc(void* ptr, size_t n) { + size_t size = *(static_cast<size_t*>(ptr) - 1); + size_t* gc_realloc_ptr = static_cast<size_t*>(apr_palloc(gc_current_pool(), sizeof(size_t) + n)); + assertOrFail(gc_realloc_ptr != NULL); + *gc_realloc_ptr = n; + memcpy(gc_realloc_ptr + 1, ptr, size < n? size : n); + return gc_realloc_ptr + 1; +} + +/** + * Pool based equivalent of the standard free function. + */ +void gc_free(unused void* ptr) { + // Memory allocated from a pool is freed when the pool is freed +} + +/** + * Pool based equivalent of the standard strdup function. + */ +char* gc_strdup(const char* str) { + char* gc_strdup_ptr = static_cast<char*>(gc_malloc(strlen(str) + 1)); + assertOrFail(gc_strdup_ptr != NULL); + strcpy(gc_strdup_ptr, str); + return gc_strdup_ptr; +} + } #endif /* tuscany_gc_hpp */ |