Changeset 52


Ignore:
Timestamp:
Feb 20, 2008, 11:05:02 AM (12 years ago)
Author:
cameron
Message:

Destructors

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile

    r50 r52  
    99markup_stats:   markup_stats.cxx src/xmlbuffer.h src/ilax.h src/multiliteral.h src/engine.h\
    1010                src/transpose.h src/bitlex.h src/xmlbuffer.c src/bitlex.c src/engine.c\
    11                 lib/sse_simd.h\
     11                lib/lib_simd.h lib/sse_simd.h\
    1212                src/bytelex.h src/charsets/ASCII_EBCDIC.h
    1313        $(CC) -o markup_stats markup_stats.cxx -march=pentium4
  • trunk/lib/lib_simd.h

    r43 r52  
    9595}
    9696
     97static inline void simd_delete(SIMD_type * blk_ptr) {
     98#ifdef __APPLE__
     99  delete [] blk_ptr;
     100#endif
     101#ifndef __APPLE__
     102  free((void *) blk_ptr);
     103#endif
     104}
    97105
    98106#endif
  • trunk/markup_stats.cxx

    r49 r52  
    236236        }
    237237        char * filename = argv[1];
    238        
     238
     239        for (int run = 0; run <100; run++) {
    239240       
    240241        parser = Parser_Interface::ParserFactory(filename);
     
    257258       
    258259        parser->ParseContent();
     260        parser->~Parser_Interface();
     261        printf("Run %i complete.\n", run);
     262        }
    259263       
    260264        print_stats("comment", comment_count, comment_length);
  • trunk/src/bitlex.c

    r45 r52  
    1616        x8basis = (BitBlockBasis *) simd_new(BUFFER_SIZE/PACKSIZE);
    1717};
     18
     19
     20Lexer_Interface::~Lexer_Interface() {
     21        simd_delete((SIMD_type *) x8basis);
     22};
     23
     24
    1825
    1926void NoEncodingError(char * msg) {
     
    827834#endif
    828835        if (buffer_units < BUFFER_SIZE) {
     836                printf("SENTINELS at %i of length %i\n", lexer_base_pos + buffer_units,
     837                                                buffer_units % BLOCKSIZE);
    829838                int lastblk = buffer_units/BLOCKSIZE;
    830839                for (int j = minLexicalItem; j < LexicalItemCount; j++) {
  • trunk/src/bitlex.h

    r40 r52  
    6161public:
    6262        Lexer_Interface(XML_Buffer_Interface *b, LexicalStreamSet *l);
     63        ~Lexer_Interface();
    6364        void AdvanceBuffer(int& base_pos, int& rel_pos, int& limit_pos);
    6465
  • trunk/src/engine.c

    r49 r52  
    3636}
    3737
     38Parser_Interface::~Parser_Interface() {
     39  xml_buf->~XML_Buffer_Interface();
     40}
     41
     42
    3843bool Parser_Interface::has_ByteOrderMark() {
    3944        return xml_buf->BOM_units > 0;
     
    104109
    105110
     111template <CodeUnit_Base C>
     112ParsingEngine<C>::~ParsingEngine() {
     113  simd_delete((SIMD_type *) buf);
     114  lexer->~Lexer_Interface();
     115}
    106116
    107117template <CodeUnit_Base C>
  • trunk/src/engine.h

    r49 r52  
    1919class Parser_Interface {
    2020public:
     21    ~Parser_Interface();
    2122        static Parser_Interface * ParserFactory(char * filename);
    2223        virtual void ParseContent() = 0;
     
    4546public:
    4647        ParsingEngine(XML_Buffer_Interface * b);
     48        ~ParsingEngine();
    4749        void ParseContent();
    4850protected:
  • trunk/src/xmlbuffer.c

    r46 r52  
    5656}
    5757
     58U16_Buffer::~U16_Buffer() {
     59  simd_delete((SIMD_type *) x16hi);
     60  simd_delete((SIMD_type *) x16lo);
     61  simd_delete((SIMD_type *) x8data);
     62}
     63
    5864U16LE_Buffer::U16LE_Buffer(BytePack * src, int lgth, int BOM)
    5965        : U16_Buffer(src, lgth, BOM) {
     
    7884        x32lh = simd_new(8*total_blocks+LOOKAHEAD_PACKS);
    7985        x32ll = simd_new(8*total_blocks+LOOKAHEAD_PACKS);
     86}
     87
     88U32_Buffer::~U32_Buffer() {
     89  simd_delete((SIMD_type *) x32hh);
     90  simd_delete((SIMD_type *) x32hl);
     91  simd_delete((SIMD_type *) x32lh);
     92  simd_delete((SIMD_type *) x32ll);
     93  simd_delete((SIMD_type *) x8data);
    8094}
    8195
     
    259273XML_Buffer_Interface * XML_Buffer_Interface::BufferFactory(char* filename) {
    260274        int chars_read;
     275        struct stat fileinfo;
     276        stat(filename, &fileinfo);
     277        int buffer_packs = (fileinfo.st_size + BUFFER_PADDING + PACKSIZE - 1)/PACKSIZE;
     278        BytePack * src_data = simd_new(buffer_packs);
     279        unsigned char * bytedata = (unsigned char *) src_data;
    261280        FILE *infile;
    262281        infile = fopen(filename, "rb");
     
    265284                exit(-1);
    266285        }
    267        
    268         struct stat fileinfo;
    269         if(fstat(fileno(infile), &fileinfo)!=0) {
    270                 fprintf(stderr, "Error: cannot fstat %s for file size.\n", filename);
    271                 exit(-1);
    272         }
    273        
    274         int buffer_packs = (fileinfo.st_size + BUFFER_PADDING + PACKSIZE - 1)/PACKSIZE;
    275         BytePack * src_data = simd_new(buffer_packs);
    276         unsigned char * bytedata = (unsigned char *) src_data; 
    277        
    278         chars_read = fread(bytedata, 1, fileinfo.st_size, infile);
     286        chars_read = fread(bytedata, 1, fileinfo.st_size, infile);
    279287        if (chars_read != fileinfo.st_size) {
    280288                fprintf(stderr, "Error: fread returned %i characters, expecting %i.\n",
     
    282290                exit(-1);
    283291        }
    284        
    285292        // Install null sentinels.
    286293        memset(&bytedata[chars_read], 0, BUFFER_PADDING);
     
    323330}
    324331
     332
     333XML_Buffer_Interface::~XML_Buffer_Interface() {
     334  simd_delete(ByteBuffer);
     335}
     336
    325337int XML_Buffer_Interface::AvailableUnits(int pos) {
    326338        return (buffer_bytes/(int) code_unit_size) - pos;
  • trunk/src/xmlbuffer.h

    r47 r52  
    2323
    2424/* Define the size of buffer used for lexical analysis/parsing. */
    25 const int BUFFER_BLOCKS = 1024;
     25const int BUFFER_BLOCKS = 16;
    2626const int BUFFER_SIZE = BUFFER_BLOCKS * BLOCKSIZE;
    2727
     
    3737public:
    3838        XML_Buffer_Interface ();
     39        ~XML_Buffer_Interface ();
    3940        /* Create and initialize an XML Buffer object for parsing a file,
    4041           based on autodetection of the character encoding family
     
    6566
    6667        BytePack * ByteBuffer;
     68
    6769protected:
    6870
     
    128130public:
    129131        U16_Buffer(BytePack * src, int lgth, int BOM);
     132        ~U16_Buffer();
    130133        virtual void DoByteplex() = 0;
    131134        void PreparePseudoASCII_Stream();
     
    156159public:
    157160        U32_Buffer(BytePack * src, int lgth, int BOM);
     161    ~U32_Buffer();
    158162        virtual void DoByteplex() = 0;
    159163        void PreparePseudoASCII_Stream();
Note: See TracChangeset for help on using the changeset viewer.