From caec161501b7157e102c7e6532084616e8dce176 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Tue, 28 Jun 2011 15:50:47 +0000 Subject: 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 --- sca-cpp/trunk/kernel/Makefile.am | 6 +++--- sca-cpp/trunk/kernel/gc.hpp | 40 ++++++++++++++++++++++++++++++++++++ sca-cpp/trunk/kernel/parallel.hpp | 2 +- sca-cpp/trunk/kernel/string-test.cpp | 4 ++-- sca-cpp/trunk/kernel/xml.hpp | 26 +++++++++++++++++++++-- 5 files changed, 70 insertions(+), 8 deletions(-) (limited to 'sca-cpp/trunk/kernel') 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 #include #include +#include #include #include #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(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(ptr) - 1); + size_t* gc_realloc_ptr = static_cast(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(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 pl = list() + "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 @@ -39,14 +39,25 @@ 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& ls) { * Read a list of values from a list of strings representing an XML document. */ const list readXML(const list& 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(); XMLReader reader(xml); @@ -365,6 +386,7 @@ template const failable writeXML(const lambda > writeXML(const list& l, const bool xmlTag) { + debug(l, "xml::writeXML"); const failable > ls = writeXML >(rcons, list(), l, xmlTag); if (!hasContent(ls)) return ls; -- cgit v1.2.3