--- parser3/src/main/pa_pool.C 2001/10/18 13:09:37 1.32 +++ parser3/src/main/pa_pool.C 2001/11/16 11:03:02 1.41 @@ -2,21 +2,22 @@ Parser: pool class. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + Author: Alexander Petrosyan (http://paf.design.ru) - $Id: pa_pool.C,v 1.32 2001/10/18 13:09:37 parser Exp $ + $Id: pa_pool.C,v 1.41 2001/11/16 11:03:02 paf Exp $ */ #include "pa_pool.h" #include "pa_exception.h" #include "pa_common.h" +#include "pa_sapi.h" #ifdef XML #include #endif Pool::Pool(void *astorage) : - fstorage(astorage), fcontext(0), ftag(0), fexception(0) + fstorage(astorage), fcontext(0), ftag(0) #ifdef XML , transcoder(0) #endif @@ -35,15 +36,14 @@ Pool::~Pool() { } void Pool::fail_alloc(size_t size) const { - fexception->_throw(0, 0, - 0, - "failed to allocate %u bytes", size); + SAPI::die("failed to allocate %u bytes, " + "total allocated %u in %u times", + size, + ftotal_allocated, ftotal_times); } void Pool::fail_register_cleanup() const { - fexception->_throw(0, 0, - 0, - "failed to register cleanup"); + SAPI::die("failed to register cleanup"); } void Pool::set_charset(const String &new_charset) { @@ -63,7 +63,7 @@ void Pool::update_transcoder() { XMLTransService::Codes resValue; transcoder=XMLPlatformUtils::fgTransService->makeNewTranscoderFor(charset->cstr(), resValue, 60); if(!transcoder) - THROW(0, 0, + throw Exception(0, 0, charset, "unsupported encoding"); } @@ -87,7 +87,7 @@ const char *Pool::transcode_cstr(const X error=false; } } catch(XMLException& e) { - exception()._throw(*this, 0, e); + Exception::provide_source(*this, 0, e); } return (const char *)dest; } @@ -95,8 +95,7 @@ String& Pool::transcode(const XalanDOMSt return *new(*this) String(*this, transcode_cstr(s)); } -/// @test who would free up result? -XalanDOMString& Pool::transcode_buf(const char *buf, size_t buf_size) { +std::auto_ptr Pool::transcode_buf(const char *buf, size_t buf_size) { update_transcoder(); unsigned int dest_size=0; @@ -116,14 +115,14 @@ XalanDOMString& Pool::transcode_buf(cons result=new XalanDOMString(dest, dest_size); } } catch(XMLException& e) { - exception()._throw(*this, 0, e); + Exception::provide_source(*this, 0, e); + result=0; //calm, compiler } - free(charSizes); - return *result; + return std::auto_ptr(result); } -XalanDOMString& Pool::transcode(const String& s) { - const char *cstr=s.cstr(String::UL_XML); +std::auto_ptr Pool::transcode(const String& s) { + const char *cstr=s.cstr(String::UL_UNSPECIFIED); return transcode_buf(cstr, strlen(cstr)); }