Changeset 2458 for trunk


Ignore:
Timestamp:
Sep 1, 2011, 10:29:57 PM (13 years ago)
Author:
gah
Message:

fix putfile to handle files > 232-1 bytes

Location:
trunk/src/core
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/RpBuffer.cc

    r2408 r2458  
    112112
    113113bool
    114 Buffer::load (Outcome &status, const char* filePath)
     114Buffer::load (Outcome &status, const char *path)
    115115{
    116116    status.addContext("Rappture::Buffer::load()");
    117117
    118118    FILE *f;
    119     f = fopen(filePath, "rb");
     119    f = fopen(path, "rb");
    120120    if (f == NULL) {
    121         status.addError("can't open \"%s\": %s", filePath, strerror(errno));
    122         return false;
    123     }
     121        status.addError("can't open \"%s\": %s", path, strerror(errno));
     122        return false;
     123    }
     124
    124125    struct stat stat;
    125126    if (fstat(fileno(f), &stat) < 0) {
    126         status.addError("can't stat \"%s\": %s", filePath, strerror(errno));
    127         return false;
    128     }
    129     off_t size;
    130     size = stat.st_size;
    131     char* memblock;
    132     memblock = new char [size];
    133     if (memblock == NULL) {
     127        status.addError("can't stat \"%s\": %s", path, strerror(errno));
     128        return false;
     129    }
     130
     131    size_t oldSize, numBytesRead;
     132
     133    // Save the # of elements in the current buffer.
     134    oldSize = count();
     135
     136    // Extend the buffer to accomodate the file contents.
     137    if (extend(stat.st_size) == 0) {
    134138        status.addError("can't allocate %d bytes for file \"%s\": %s",
    135                         size, filePath, strerror(errno));
     139                stat.st_size, path, strerror(errno));
    136140        fclose(f);
    137141        return false;
    138     }
    139 
    140     // FIXME: better yet, create an "extend" method in the buffer and returns
    141     //             the address of the char buffer so I can read the data directly
    142     //             into the buffer.  This eliminates memory new/copy/delete ops.
    143 
    144     size_t nRead;
    145     nRead = fread(memblock, sizeof(char), size, f);
    146     fclose(f);                        // Close the file.
    147 
    148     if (nRead != (size_t)size) {
    149         status.addError("can't read %d bytes from \"%s\": %s", size, filePath,
    150                         strerror(errno));
    151         return false;
    152     }
    153 
    154     int nBytes;
    155     nBytes = append(memblock, size);
    156     delete [] memblock;
    157 
    158     if (nBytes != size) {
    159         status.addError("can't append %d bytes from \"%s\" to buffer: %s",
    160                 size, filePath, strerror(errno));
    161         return false;
    162     }
    163     return true;
    164 }
    165 
    166 
    167 bool
    168 Buffer::dump (Outcome &status, const char* filePath)
     142    }   
     143    // Read the file contents directly onto the end of the old buffer.
     144    numBytesRead = fread((char *)bytes() + oldSize, sizeof(char),
     145        stat.st_size, f);
     146    fclose(f);
     147    if (numBytesRead != (size_t)stat.st_size) {
     148        status.addError("can't read %ld bytes from \"%s\": %s", stat.st_size,
     149                        path, strerror(errno));
     150        return false;
     151    }
     152    // Reset the # of elements in the buffer to the new count.
     153    count(stat.st_size + oldSize);
     154    return true;
     155}
     156
     157
     158bool
     159Buffer::dump (Outcome &status, const char* path)
    169160{
    170161    status.addContext("Rappture::Buffer::dump()");
    171162
    172163    FILE *f;
    173     f = fopen(filePath, "wb");
     164    f = fopen(path, "wb");
    174165    if (f == NULL) {
    175         status.addError("can't open \"%s\": %s\n", filePath, strerror(errno));
     166        status.addError("can't open \"%s\": %s\n", path, strerror(errno));
    176167        return false;
    177168    }
     
    182173    if (nWritten != (ssize_t)size()) {
    183174        status.addError("can't write %d bytes to \"%s\": %s\n", size(),
    184                         filePath, strerror(errno));
     175                        path, strerror(errno));
    185176        return false;
    186177    }
     
    288279{
    289280    int ret=0, flush=0;
    290     unsigned have=0;
    291281    z_stream strm;
    292282
    293283    char in[CHUNK];
    294284    char out[CHUNK];
    295 
    296     int bytesWritten = 0;
    297285
    298286    /* allocate deflate state */
     
    330318            ret = deflate(&strm, flush);    /* no bad return value */
    331319            assert(ret != Z_STREAM_ERROR);  /* state not clobbered */
     320
     321            int have;
    332322            have = CHUNK - strm.avail_out;
     323
    333324            /* write to file and check for error */
    334             bytesWritten = bout.append(out, have);
    335             if ( ( (unsigned) bytesWritten != have ) ) {
     325            if (bout.append(out, have)) {
    336326                (void)deflateEnd(&strm);
    337327                bout.clear();
  • trunk/src/core/RpSimpleBuffer.h

    r1850 r2458  
     1
    12/*
    23 * ======================================================================
     
    6970#include <cstdarg>
    7071
     72/*
     73 * Note: I think I would redo this class to deal only with unsigned byte
     74 *       arrays, instead of arrays of <T>.  I would create other classes
     75 *       that arrays of <T> that used the lower level byte array.
     76 *
     77 *       It would make it cleaner if the class only dealt with bytes
     78 *       instead of elements (of various sizes). 
     79 *
     80 *       Specific implementations of <T> could perform data alignment on
     81 *       word/double word/quad word boundaries.  This is an optimization
     82 *       that should could done for double arrays.
     83 *
     84 * Note: The signed int argument on append() should be replaced with a
     85 *       size_t.  This limits the length of strings to appended.  It
     86 *       silently truncates bigger sizes to the lower 32-bits. 
     87 */
    7188namespace Rappture {
    7289
     
    7491class SimpleBuffer {
    7592public:
    76     SimpleBuffer();
     93    /**
     94     * Construct an empty SimpleBuffer.
     95     */
     96    SimpleBuffer() {
     97        Initialize();
     98    }
     99    /**
     100     * Construct a SimpleBuffer loaded with initial data.
     101     *
     102     * @param bytes pointer to bytes being stored.
     103     * @param nbytes number of bytes being stored.
     104     */
     105    SimpleBuffer(const T* bytes, int numElems=-1) {
     106        Initialize();
     107        append(bytes, numElems);
     108    }
    77109    SimpleBuffer(size_t nmemb);
    78     SimpleBuffer(const T* bytes, int nmemb=-1);
     110   
     111    /**
     112     * Copy constructor
     113     * @param SimpleBuffer object to copy
     114     */
    79115    SimpleBuffer(const SimpleBuffer& b);
     116   
    80117    SimpleBuffer<T>& operator=(const SimpleBuffer<T>& b);
    81118    SimpleBuffer     operator+(const SimpleBuffer& b) const;
    82119    SimpleBuffer<T>& operator+=(const SimpleBuffer<T>& b);
    83120    T operator[](size_t offset);
    84     virtual ~SimpleBuffer();
    85 
    86     const T* bytes() const;
    87     size_t size() const;
    88     size_t nmemb() const;
    89 
    90     SimpleBuffer<T>& clear();
     121   
     122    /**
     123     * Destructor
     124     */
     125    virtual ~SimpleBuffer() {
     126        Release();
     127    }
     128   
     129    /**
     130     * Get the bytes currently stored in the buffer.  These bytes can
     131     * be stored, and used later to construct another Buffer to
     132     * decode the information.
     133     *
     134     * @return Pointer to the bytes in the buffer.
     135     */
     136    const T* bytes() const {
     137        return _buf;
     138    }
     139    /**
     140     * Get the number of bytes currently stored in the buffer.
     141     * @return Number of the bytes used in the buffer.
     142     */
     143    size_t size() const {
     144        return _numElemsUsed * sizeof(T);
     145    }
     146    /**
     147     * Get the number of members currently stored in the buffer.
     148     * @return Number of the members used in the buffer.
     149     */
     150    size_t nmemb() const {
     151        return _numElemsUsed;
     152    }
     153    /**
     154     * Get the number of members currently stored in the buffer.
     155     * @return Number of the members used in the buffer.
     156     */
     157    size_t count() const {
     158        return _numElemsUsed;
     159    }
     160    /**
     161     * Set the number of members currently stored in the buffer.
     162     * @return Number of the members used in the buffer.
     163     */
     164    size_t count(size_t newCount) {
     165        _numElemsUsed = newCount;
     166        return _numElemsUsed;
     167    }
     168    /**
     169     * Clear the buffer, making it empty.
     170     * @return Reference to this buffer.
     171     */
     172    SimpleBuffer<T>& clear() {
     173        Release();
     174        return *this;
     175    }
     176    size_t extend(size_t extraElems);
    91177    int append(const T* bytes, int nmemb=-1);
    92178    int appendf(const char *format, ...);
     
    98184    SimpleBuffer<T>& rewind();
    99185    SimpleBuffer<T>& show();
    100 
     186   
    101187    bool good() const;
    102188    bool bad() const;
    103189    bool eof() const;
    104 
     190   
    105191    SimpleBuffer<T>& move(SimpleBuffer<T>& b);
    106 
     192   
    107193protected:
    108 
    109     void bufferInit();
    110     void bufferFree();
    111 
     194   
     195    void Initialize();
     196    void Release();
     197   
    112198private:
    113 
     199   
    114200    /// Pointer to the memory that holds our buffer's data
    115201    T* _buf;
    116 
     202   
    117203    /// Position offset within the buffer's memory
    118204    size_t _pos;
    119 
     205   
    120206    /// Number of members stored in the buffer
    121     size_t _nMembStored;
    122 
     207    size_t _numElemsUsed;
     208   
    123209    /// Total number of members available in the buffer
    124     size_t _nMembAvl;
    125 
     210    size_t _numElemsAllocated;
     211   
    126212    /// State of the last file like operation.
    127213    bool _fileState;
    128 
     214   
    129215    /// Minimum number of members is set to the number you can fit in 256 bytes
    130     const static int _minMembCnt=(256/sizeof(T));
    131 
     216    const static int _minNumElems=(256/sizeof(T));
     217   
    132218    size_t __guesslen(const T* bytes);
    133 
     219   
    134220};
    135 
     221   
    136222typedef SimpleBuffer<char>   SimpleCharBuffer;
    137223typedef SimpleBuffer<float>  SimpleFloatBuffer;
     
    139225
    140226/**
    141  * Construct an empty SimpleBuffer.
    142  */
    143 template<class T>
    144 SimpleBuffer<T>::SimpleBuffer()
    145 {
    146     bufferInit();
    147 }
    148 
    149 
    150 /**
    151227 * Construct an empty SimpleBuffer of specified size.
    152228 */
    153229template<class T>
    154 SimpleBuffer<T>::SimpleBuffer(size_t nmemb)
    155 {
    156     bufferInit();
    157 
    158     if (nmemb == 0) {
     230SimpleBuffer<T>::SimpleBuffer(size_t numElems)
     231{
     232    Initialize();
     233
     234    if (numElems == 0) {
    159235        // ignore requests for sizes equal to zero
    160236        return;
     
    162238
    163239    // buffer sizes less than min_size are set to min_size
    164     if (nmemb < (size_t) _minMembCnt) {
    165         nmemb = _minMembCnt;
    166     }
    167 
    168     if (set(nmemb) != nmemb) {
     240    if (numElems < (size_t) _minNumElems) {
     241        numElems = _minNumElems;
     242    }
     243
     244    if (set(numElems) != numElems) {
    169245        return;
    170246    }
    171     _nMembStored = nmemb;
    172 }
    173 
    174 
    175 /**
    176  * Construct a SimpleBuffer loaded with initial data.
    177  *
    178  * @param bytes pointer to bytes being stored.
    179  * @param nbytes number of bytes being stored.
    180  */
    181 template<class T>
    182 SimpleBuffer<T>::SimpleBuffer(const T* bytes, int nmemb)
    183 {
    184     bufferInit();
    185     append(bytes,nmemb);
     247    _numElemsUsed = numElems;
    186248}
    187249
     
    194256SimpleBuffer<T>::SimpleBuffer(const SimpleBuffer<T>& b)
    195257{
    196     bufferInit();
    197     append(b.bytes(),b.nmemb());
     258    Initialize();
     259    append(b.bytes(), b.nmemb());
    198260}
    199261
     
    207269SimpleBuffer<T>::operator=(const SimpleBuffer<T>& b)
    208270{
    209     bufferFree();
    210     bufferInit();
     271    Release();
    211272    append(b.bytes(),b.nmemb());
    212273    return *this;
     
    247308template<class T>
    248309T
    249 SimpleBuffer<T>::operator[](size_t idx)
    250 {
    251     return (_buf+idx);
    252 }
    253 
    254 
    255 /**
    256  * Destructor
    257  */
    258 template<class T>
    259 SimpleBuffer<T>::~SimpleBuffer()
    260 {
    261     bufferFree();
    262 }
    263 
    264 
    265 /**
    266  * Get the bytes currently stored in the buffer.  These bytes can
    267  * be stored, and used later to construct another Buffer to
    268  * decode the information.
    269  *
    270  * @return Pointer to the bytes in the buffer.
    271  */
    272 template<class T>
    273 const T*
    274 SimpleBuffer<T>::bytes() const
    275 {
    276     return _buf;
    277 }
    278 
    279 
    280 /**
    281  * Get the number of bytes currently stored in the buffer.
    282  * @return Number of the bytes used in the buffer.
    283  */
    284 template<class T>
    285 size_t
    286 SimpleBuffer<T>::size() const
    287 {
    288     return _nMembStored*sizeof(T);
    289 }
    290 
    291 
    292 /**
    293  * Get the number of members currently stored in the buffer.
    294  * @return Number of the members used in the buffer.
    295  */
    296 template<class T>
    297 size_t
    298 SimpleBuffer<T>::nmemb() const
    299 {
    300     return _nMembStored;
    301 }
    302 
    303 
    304 /**
    305  * Clear the buffer, making it empty.
    306  * @return Reference to this buffer.
    307  */
    308 template<class T>
    309 SimpleBuffer<T>&
    310 SimpleBuffer<T>::clear()
    311 {
    312     bufferFree();
    313     bufferInit();
    314 
    315     return *this;
    316 }
     310SimpleBuffer<T>::operator[](size_t index)
     311{
     312    return (_buf + index);              // Rely on pointer arithmetic
     313}
     314
     315
    317316
    318317/**
     
    327326    return strlen(bytes);
    328327}
     328
     329/* FIXME:       Change the signed int to size_t.  Move the -1 copy string
     330 *              up to the SimpleCharBuffer class.   There needs to be both
     331 *              a heavy duty class that can take a string bigger than
     332 *              2^31-1 in length, and a convenient class that doesn't make
     333 *              you add call strlen(s).
     334 *             
     335 */
    329336
    330337/**
     
    351358{
    352359    size_t newMembCnt = 0;
    353     size_t nbytes = 0;
    354360
    355361    void* dest = NULL;
     
    361367        return 0;
    362368    }
     369
     370#ifdef notdef
     371
     372    /* This is dead code.  The test above catches the condition. */
    363373
    364374    // FIXME: i think this needs to be division,
     
    367377    // bytes in *bytes.
    368378
     379    size_t nbytes = 0;
    369380    if (nmemb == -1) {
    370381        // user signaled null terminated string
     
    379390        return nmemb;
    380391    }
    381 
    382     newMembCnt = (size_t)(_nMembStored + nmemb);
    383 
    384     if (newMembCnt > _nMembAvl) {
     392#endif
     393
     394    newMembCnt = (size_t)(_numElemsUsed + nmemb);
     395
     396    if (newMembCnt > _numElemsAllocated) {
    385397
    386398        // buffer sizes less than min_size are set to min_size
    387         if (newMembCnt < (size_t) _minMembCnt) {
    388             newMembCnt = (size_t) _minMembCnt;
     399        if (newMembCnt < (size_t) _minNumElems) {
     400            newMembCnt = (size_t) _minNumElems;
    389401        }
    390402
     
    395407         */
    396408        size_t membAvl;
    397         membAvl = (_nMembAvl > 0) ? _nMembAvl : _minMembCnt;
     409        membAvl = (_numElemsAllocated > 0) ? _numElemsAllocated : _minNumElems;
    398410        while (newMembCnt > membAvl) {
    399411            membAvl += membAvl;
     
    408420    }
    409421
    410     dest = (void*) (_buf + _nMembStored);
     422    dest = (void*) (_buf + _numElemsUsed);
    411423    src  = (void const*) bytes;
    412424    size = (size_t) (nmemb*sizeof(T));
    413425    memcpy(dest,src,size);
    414426
    415     _nMembStored += nmemb;
     427    _numElemsUsed += nmemb;
    416428
    417429    return nmemb;
     430}
     431
     432/**
     433 * Append bytes to the end of this buffer
     434 * @param pointer to bytes to be added
     435 * @param number of bytes to be added
     436 * @return number of bytes appended.
     437 */
     438template<class T>
     439size_t
     440SimpleBuffer<T>::extend(size_t numExtraElems)
     441{
     442    size_t newSize;
     443
     444    newSize = _numElemsUsed + numExtraElems;
     445    if (newSize > _numElemsAllocated) {
     446
     447        /* Enforce a minimum buffer size. */
     448        if (newSize < (size_t) _minNumElems) {
     449            newSize = (size_t) _minNumElems;
     450        }
     451
     452        size_t size;
     453        size = (_numElemsAllocated > 0) ? _numElemsAllocated : _minNumElems;
     454
     455        /* Keep doubling the size of the buffer until we have enough space to
     456         * hold the extra elements. */
     457        while (newSize > size) {
     458            size += size;
     459        }
     460        /* Reallocate to a larger buffer. */
     461        if (set(size) != size) {
     462            return 0;
     463        }
     464    }
     465    return _numElemsAllocated;
    418466}
    419467
     
    463511    }
    464512
    465     newMembCnt = (size_t)(_nMembStored + nmemb);
    466 
    467     if (newMembCnt > _nMembAvl) {
     513    newMembCnt = (size_t)(_numElemsUsed + nmemb);
     514
     515    if (newMembCnt > _numElemsAllocated) {
    468516
    469517        // buffer sizes less than min_size are set to min_size
    470         if (newMembCnt < (size_t) _minMembCnt) {
    471             newMembCnt = (size_t) _minMembCnt;
     518        if (newMembCnt < (size_t) _minNumElems) {
     519            newMembCnt = (size_t) _minNumElems;
    472520        }
    473521
     
    478526         */
    479527        size_t membAvl;
    480         membAvl = (_nMembAvl > 0) ? _nMembAvl : _minMembCnt;
     528        membAvl = (_numElemsAllocated > 0) ? _numElemsAllocated : _minNumElems;
    481529        while (newMembCnt > membAvl) {
    482530            membAvl += membAvl;
     
    491539    }
    492540
    493     dest = (char*) (_buf + _nMembStored);
    494     size = (_nMembAvl-_nMembStored)*sizeof(T);
     541    dest = (char*) (_buf + _numElemsUsed);
     542    size = (_numElemsAllocated-_numElemsUsed)*sizeof(T);
    495543
    496544    va_start(arg,format);
     
    511559
    512560        // FIXME: round the new size up to the nearest multiple of 256?
    513         set(_nMembStored+nmemb);
     561        set(_numElemsUsed+nmemb);
    514562
    515563        // reset dest because it may have moved during reallocation
    516         dest = (char*) (_buf + _nMembStored);
     564        dest = (char*) (_buf + _numElemsUsed);
    517565        size = bytesAdded;
    518566
     
    528576    }
    529577
    530     _nMembStored += nmemb;
     578    _numElemsUsed += nmemb;
    531579
    532580    // remove the null character added by vsnprintf()
     
    549597SimpleBuffer<T>::remove(int nmemb)
    550598{
    551     if ((_nMembStored - nmemb) < 0){
    552         _nMembStored = 0;
     599    if ((_numElemsUsed - nmemb) < 0){
     600        _numElemsUsed = 0;
    553601        _pos = 0;
    554602    } else {
    555         _nMembStored -= nmemb;
    556         if (_pos >= _nMembStored) {
     603        _numElemsUsed -= nmemb;
     604        if (_pos >= _numElemsUsed) {
    557605            // move _pos back to the new end of the buffer.
    558             _pos = _nMembStored-1;
     606            _pos = _numElemsUsed-1;
    559607        }
    560608    }
     
    563611    return nmemb;
    564612}
    565 
    566613
    567614template<class T>
     
    585632    }
    586633    _buf = buf;
    587     _nMembAvl = nmemb;
    588     return _nMembAvl;
    589 }
    590 
     634    _numElemsAllocated = nmemb;
     635    return _numElemsAllocated;
     636}
    591637
    592638template<> inline
     
    596642    size_t curMemb = 0;
    597643
    598     while (curMemb != _nMembStored) {
     644    while (curMemb != _numElemsUsed) {
    599645        fprintf(stdout,"_buf[%lu] = :%c:\n", (long unsigned int)curMemb,
    600646                _buf[curMemb]);
    601647        curMemb += 1;
    602648    }
    603     fprintf(stdout,"_nMembAvl = :%lu:\n", (long unsigned int)_nMembAvl);
     649    fprintf(stdout,"_numElemsAllocated = :%lu:\n",
     650            (long unsigned int)_numElemsAllocated);
    604651
    605652    return *this;
     
    613660    size_t curMemb = 0;
    614661
    615     while (curMemb != _nMembStored) {
     662    while (curMemb != _numElemsUsed) {
    616663        fprintf(stdout,"_buf[%lu] = :%#x:\n", (long unsigned int)curMemb,
    617664                (unsigned long)_buf[curMemb]);
    618665        curMemb += 1;
    619666    }
    620     fprintf(stdout,"_nMembAvl = :%lu:\n", (long unsigned int)_nMembAvl);
     667    fprintf(stdout,"_numElemsAllocated = :%lu:\n", (long unsigned int)_numElemsAllocated);
    621668
    622669    return *this;
     
    651698
    652699    // make sure we don't read off the end of our buffer
    653     if ( (_pos + nmemb) > _nMembStored ) {
    654         nMembRead = _nMembStored - _pos;
     700    if ( (_pos + nmemb) > _numElemsUsed ) {
     701        nMembRead = _numElemsUsed - _pos;
    655702    }
    656703    else {
     
    694741            _pos = 0;
    695742        }
    696         else if (offset >= (long)_nMembStored) {
     743        else if (offset >= (long)_numElemsUsed) {
    697744            /* dont go off the end of data */
    698             _pos = _nMembStored - 1;
     745            _pos = _numElemsUsed - 1;
    699746        }
    700747        else {
     
    707754            _pos = 0;
    708755        }
    709         else if ((_pos + offset) >= _nMembStored) {
     756        else if ((_pos + offset) >= _numElemsUsed) {
    710757            /* dont go off the end of data */
    711             _pos = _nMembStored - 1;
     758            _pos = _numElemsUsed - 1;
    712759        }
    713760        else {
     
    716763    }
    717764    else if (whence == SEEK_END) {
    718         if (offset <= (long)(-1*_nMembStored)) {
     765        if (offset <= (long)(-1*_numElemsUsed)) {
    719766            /* dont go off the beginning of data */
    720767            _pos = 0;
     
    722769        else if (offset >= 0) {
    723770            /* dont go off the end of data */
    724             _pos = _nMembStored - 1;
     771            _pos = _numElemsUsed - 1;
    725772        }
    726773        else {
    727             _pos = (size_t)((_nMembStored - 1) + offset);
     774            _pos = (size_t)((_numElemsUsed - 1) + offset);
    728775        }
    729776    }
     
    794841SimpleBuffer<T>::eof() const
    795842{
    796     return (_pos >= _nMembStored);
     843    return (_pos >= _numElemsUsed);
    797844}
    798845
     
    801848 * Move the data from this SimpleBuffer to the SimpleBuffer provided by
    802849 * the caller. All data except the _pos is moved and this SimpleBuffer is
    803  * re-initialized with bufferInit().
     850 * re-initialized with Initialize().
    804851 * @param SimpleBuffer to move the information to
    805852 * @return reference to this SimpleBuffer object.
     
    809856SimpleBuffer<T>::move(SimpleBuffer<T>& b)
    810857{
    811     bufferFree();
     858    Release();
    812859
    813860    _buf = b._buf;
    814861    _pos = b._pos;
    815862    _fileState = b._fileState;
    816     _nMembStored = b._nMembStored;
    817     _nMembAvl = b._nMembAvl;
    818 
    819     b.bufferInit();
     863    _numElemsUsed = b._numElemsUsed;
     864    _numElemsAllocated = b._numElemsAllocated;
     865
     866    b.Initialize();
    820867
    821868    return *this;
     
    825872 /**
    826873  *  Initializes a dynamic buffer, discarding any previous contents
    827   *  of the buffer. bufferFree() should have been called already
     874  *  of the buffer. Release() should have been called already
    828875  *  if the dynamic buffer was previously in use.
    829876  */
    830877template<class T>
    831878void
    832 SimpleBuffer<T>::bufferInit()
     879SimpleBuffer<T>::Initialize()
    833880{
    834881    _buf = NULL;
    835882    _pos = 0;
    836883    _fileState = true;
    837     _nMembStored = 0;
    838     _nMembAvl = 0;
     884    _numElemsUsed = 0;
     885    _numElemsAllocated = 0;
    839886}
    840887
     
    846893template<class T>
    847894void
    848 SimpleBuffer<T>::bufferFree()
     895SimpleBuffer<T>::Release()
    849896{
    850897    if (_buf != NULL) {
     
    852899        _buf = NULL;
    853900    }
    854     bufferInit();
     901    Initialize();
    855902}
    856903
  • trunk/src/core/scew/xhandler.c

    r1559 r2458  
    193193        }
    194194        if (bytes == NULL) {
    195             fprintf(stderr, "can't allocated %d bytes for character data\n",
     195            fprintf(stderr, "can't allocated %lu bytes for character data\n",
    196196                    size);
    197197            return;
Note: See TracChangeset for help on using the changeset viewer.