Annotation of parser3/src/main/pa_memory.C, revision 1.1.2.2

1.1.2.1   paf         1: /** @file
                      2:        Parser: memory reference counting classes.
                      3: 
                      4:        Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
                      5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
                      6: */
                      7: 
1.1.2.2 ! paf         8: static const char* IDENT_MEMORY_C="$Date: 2003/02/21 10:55:34 $";
1.1.2.1   paf         9: 
                     10: #include "pa_pool.h"
                     11: #include "pa_exception.h"
                     12: #include "pa_common.h"
                     13: #include "pa_sapi.h"
                     14: 
1.1.2.2 ! paf        15: void *pa_fail_alloc(char *what, size_t size) {
1.1.2.1   paf        16:        SAPI::die("out of memory: failed to %s %u bytes",
                     17:                what, size);
                     18: 
                     19:        // never reached
                     20:        return 0;
                     21: }
                     22: 
                     23: /*
                     24: Pool::Pool(void *astorage) : 
                     25:        fstorage(astorage), fcontext(0), 
                     26:        ftotal_allocated(0), ftotal_times(0),
                     27:        source_charset(0), client_charset(0)
                     28:        {
                     29: }
                     30: 
                     31: void *Pool::copy(const void *buf, const size_t size) {
                     32:        if(!buf || !size)
                     33:                return 0;
                     34: 
                     35:        void *result=malloc(size);
                     36:        memcpy(result, buf, size);
                     37:        return result;
                     38: }
                     39: 
                     40: char *Pool::copy(const char* cstr) {
                     41:        if(cstr) {
                     42:                size_t size=strlen(cstr)+1;
                     43:                return (char *)copy(cstr, size);
                     44:        }
                     45:        return 0;
                     46: }
                     47: 
                     48: 
                     49: void Pool::fail_alloc(size_t size) const {
                     50:        SAPI::die("out of pool memory: failed to allocate %u bytes; "
                     51:                "already allocated on pool: %u bytes in %u times", 
                     52:                size, 
                     53:                ftotal_allocated, ftotal_times);
                     54: }
                     55: 
                     56: void Pool::fail_register_cleanup() const {
                     57:        SAPI::die("failed to register cleanup");
                     58: }
                     59: 
                     60: void Pool::set_source_charset(Charset& acharset) { 
                     61:        source_charset=&acharset; 
                     62: }
                     63: Charset& Pool::get_source_charset() { 
                     64:        if(!source_charset)
                     65:                throw Exception(0,
                     66:                        0,
                     67:                        "no source charset defined yet");
                     68:        return *source_charset; 
                     69: }
                     70: 
                     71: void Pool::set_client_charset(Charset& acharset) { 
                     72:        client_charset=&acharset; 
                     73: }
                     74: Charset& Pool::get_client_charset() { 
                     75:        if(!client_charset)
                     76:                throw Exception(0,
                     77:                        0,
                     78:                        "no client charset defined yet");
                     79:        return *client_charset; 
                     80: }
                     81: 
                     82: #ifdef XML
                     83: 
                     84: const char* Pool::transcode_cstr(xmlChar *s) {
                     85:        return get_source_charset().transcode_cstr(s); 
                     86: }
                     87: 
                     88: String& Pool::transcode(xmlChar *s
                     89: #ifndef NO_STRING_ORIGIN
                     90:                , const String *origin
                     91: #endif
                     92:                                                ) {
                     93:        return get_source_charset().transcode(s, origin); 
                     94: }
                     95: 
                     96: const char* Pool::transcode_cstr(GdomeDOMString *s) { 
                     97:        return get_source_charset().transcode_cstr(s); 
                     98: }
                     99: 
                    100: String& Pool::transcode(GdomeDOMString *s
                    101: #ifndef NO_STRING_ORIGIN
                    102:                , const String *origin
                    103: #endif
                    104:        ) { 
                    105:        return get_source_charset().transcode(s, origin);
                    106: }
                    107: 
                    108: xmlChar *Pool::transcode_buf2xchar(const char* buf, size_t buf_size) {
                    109:        return get_source_charset().transcode_buf2xchar(buf, buf_size); 
                    110: }
                    111: 
                    112: GdomeDOMString_auto_ptr Pool::transcode(const String& s) {
                    113:        return get_source_charset().transcode(s); 
                    114: }
                    115: 
                    116: #endif
                    117: */

E-mail: