diff options
Diffstat (limited to '')
-rw-r--r-- | sca-cpp/trunk/kernel/Makefile.am | 6 | ||||
-rw-r--r-- | sca-cpp/trunk/kernel/gc.hpp | 40 | ||||
-rw-r--r-- | sca-cpp/trunk/kernel/parallel.hpp | 2 | ||||
-rw-r--r-- | sca-cpp/trunk/kernel/string-test.cpp | 4 | ||||
-rw-r--r-- | sca-cpp/trunk/kernel/xml.hpp | 26 |
5 files changed, 70 insertions, 8 deletions
diff --git a/sca-cpp/trunk/kernel/Makefile.am b/sca-cpp/trunk/kernel/Makefile.am index a112ab5d0d..e6a7fdb2b3 100644 --- a/sca-cpp/trunk/kernel/Makefile.am +++ b/sca-cpp/trunk/kernel/Makefile.am @@ -25,9 +25,9 @@ string_test_SOURCES = string-test.cpp noinst_test_LTLIBRARIES = libdynlib-test.la noinst_testdir = `pwd`/tmp libdynlib_test_la_SOURCES = dynlib-test.cpp -noinst_DATA = libdynlib-test.so -libdynlib-test.so: - ln -s .libs/libdynlib-test.so +noinst_DATA = libdynlib-test${libsuffix} +libdynlib-test${libsuffix}: + ln -s .libs/libdynlib-test${libsuffix} kernel_test_SOURCES = kernel-test.cpp 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 */ diff --git a/sca-cpp/trunk/kernel/parallel.hpp b/sca-cpp/trunk/kernel/parallel.hpp index 09829f0758..9c75b8fb91 100644 --- a/sca-cpp/trunk/kernel/parallel.hpp +++ b/sca-cpp/trunk/kernel/parallel.hpp @@ -43,7 +43,7 @@ namespace tuscany { * Returns the current thread id. */ long int threadId() { - return syscall(__NR_gettid); + return syscall(SYS_gettid); } /** diff --git a/sca-cpp/trunk/kernel/string-test.cpp b/sca-cpp/trunk/kernel/string-test.cpp index 23fa2b9457..5919eed3de 100644 --- a/sca-cpp/trunk/kernel/string-test.cpp +++ b/sca-cpp/trunk/kernel/string-test.cpp @@ -40,7 +40,7 @@ bool testCopies() { string y = string("abcd"); assert(checkStringCopyCounters(1)); resetStringCopyCounters(); - string z = y; + unused string z = y; assert(checkStringCopyCounters(0)); resetStringCopyCounters(); const list<string> pl = list<string>() + "abcd" + "efgh"; @@ -119,7 +119,7 @@ string add(string& x, string& y) { return x + y; } -char charBuffer[16384]; +char charBuffer[16385]; struct addStrings{ const size_t size; diff --git a/sca-cpp/trunk/kernel/xml.hpp b/sca-cpp/trunk/kernel/xml.hpp index 97c9effcc2..fb7c0a6cf6 100644 --- a/sca-cpp/trunk/kernel/xml.hpp +++ b/sca-cpp/trunk/kernel/xml.hpp @@ -40,13 +40,24 @@ namespace tuscany { /** + * APR-based memory management functions. + */ + + +/** * Initializes the libxml2 library. */ class XMLParser { public: XMLParser() { + debug("xml::XMLParser"); + xmlMemSetup(gc_free, gc_malloc, gc_realloc, gc_strdup); xmlInitParser(); } + + ~XMLParser() { + debug("xml::~XMLParser"); + } } xmlParser; /** @@ -58,12 +69,20 @@ public: None = 0, Element = 1, Attribute = 2, Text = 3, EndElement = 15, Identifier = 100, End = 101 }; - XMLReader(xmlTextReaderPtr xml) : xml(xml), tokenType(None), isEmptyElement(false), hasValue(false), hasAttributes(false) { + XMLReader(xmlTextReaderPtr xml) : xml(xml), owner(true), tokenType(None), isEmptyElement(false), hasValue(false), hasAttributes(false) { + debug("xml::XMLReader::xml"); xmlTextReaderSetParserProp(xml, XML_PARSER_DEFAULTATTRS, 1); xmlTextReaderSetParserProp(xml, XML_PARSER_SUBST_ENTITIES, 1); } + XMLReader(const XMLReader& r) : xml(r.xml), owner(false), tokenType(r.tokenType), isEmptyElement(r.isEmptyElement), hasValue(r.hasValue), hasAttributes(r.hasAttributes) { + debug("xml::XMLReader::copy"); + } + ~XMLReader() { + debug("xml::~XMLReader"); + if (!owner) + return; xmlTextReaderClose(xml); xmlFreeTextReader(xml); } @@ -96,6 +115,7 @@ public: private: const xmlTextReaderPtr xml; + const bool owner; int tokenType; bool isEmptyElement; bool hasValue; @@ -212,8 +232,9 @@ const bool isXML(const list<string>& ls) { * Read a list of values from a list of strings representing an XML document. */ const list<value> readXML(const list<string>& ilist) { + debug(ilist, "xml::readXML"); XMLReadContext cx(ilist); - xmlTextReaderPtr xml = xmlReaderForIO(readCallback, NULL, &cx, NULL, NULL, XML_PARSE_NONET); + xmlTextReaderPtr xml = xmlReaderForIO(readCallback, NULL, &cx, NULL, NULL, XML_PARSE_NONET | XML_PARSE_NODICT); if (xml == NULL) return list<value>(); XMLReader reader(xml); @@ -365,6 +386,7 @@ template<typename R> const failable<R> writeXML(const lambda<R(const string&, co * Convert a list of values to a list of strings representing an XML document. */ const failable<list<string> > writeXML(const list<value>& l, const bool xmlTag) { + debug(l, "xml::writeXML"); const failable<list<string> > ls = writeXML<list<string> >(rcons<string>, list<string>(), l, xmlTag); if (!hasContent(ls)) return ls; |