]> git.cworth.org Git - apitrace/commitdiff
Merge remote-tracking branch 'origin/master' into on-demand-loading
authorZack Rusin <zack@kde.org>
Fri, 2 Sep 2011 20:02:59 +0000 (16:02 -0400)
committerZack Rusin <zack@kde.org>
Fri, 2 Sep 2011 20:02:59 +0000 (16:02 -0400)
glapi.py
glparams.py
glretrace.py
glstate.cpp
glstate.py
gui/apisurface.cpp
gui/loaderthread.cpp
trace_file.cpp
trace_file.hpp
trace_snappyfile.cpp
trace_snappyfile.hpp

index cb903fad6af17e3261a27c48cb32d6d2e66c005c..62e4638e8635a273953523b645c743acf590f5a8 100644 (file)
--- a/glapi.py
+++ b/glapi.py
@@ -2297,7 +2297,7 @@ glapi.add_functions([
     GlFunction(Void, "glClearColorIuiEXT", [(GLuint, "red"), (GLuint, "green"), (GLuint, "blue"), (GLuint, "alpha")]),
 
     # GL_GREMEDY_frame_terminator
-    GlFunction(Void, "glFrameTerminatorGREMEDY", [], sideeffects=False),
+    GlFunction(Void, "glFrameTerminatorGREMEDY", []),
 
     # GL_NV_conditional_render
     GlFunction(Void, "glBeginConditionalRenderNV", [(GLuint, "id"), (GLenum, "mode")]),
index 9337a398b5e257b30bdf5bc86d38b7e1753e2b32..fd8c002dd9c24d4c206de19f6d33035715a7441a 100644 (file)
@@ -331,8 +331,8 @@ parameters = [
     ("glGet",  I,      1,      "GL_MAP1_GRID_SEGMENTS"),       # 0x0DD1
     ("glGet",  F,      4,      "GL_MAP2_GRID_DOMAIN"), # 0x0DD2
     ("glGet",  I,      2,      "GL_MAP2_GRID_SEGMENTS"),       # 0x0DD3
-    ("glGet",  B,      1,      "GL_TEXTURE_1D"),       # 0x0DE0
-    ("glGet",  B,      1,      "GL_TEXTURE_2D"),       # 0x0DE1
+    ("_glGet", B,      1,      "GL_TEXTURE_1D"),       # 0x0DE0
+    ("_glGet", B,      1,      "GL_TEXTURE_2D"),       # 0x0DE1
     ("glGet",  P,      1,      "GL_FEEDBACK_BUFFER_POINTER"),  # 0x0DF0
     ("glGet",  I,      1,      "GL_FEEDBACK_BUFFER_SIZE"),     # 0x0DF1
     ("glGet",  E,      1,      "GL_FEEDBACK_BUFFER_TYPE"),     # 0x0DF2
@@ -617,9 +617,9 @@ parameters = [
     ("",       X,      1,      "GL_TEXTURE_TOO_LARGE_EXT"),    # 0x8065
     ("glGetTexParameter",      F,      1,      "GL_TEXTURE_PRIORITY"), # 0x8066
     ("glGetTexParameter",      B,      1,      "GL_TEXTURE_RESIDENT"), # 0x8067
-    ("glGet",  I,      1,      "GL_TEXTURE_BINDING_1D"),       # 0x8068
-    ("glGet",  I,      1,      "GL_TEXTURE_BINDING_2D"),       # 0x8069
-    ("glGet",  I,      1,      "GL_TEXTURE_BINDING_3D"),       # 0x806A
+    ("_glGet", I,      1,      "GL_TEXTURE_BINDING_1D"),       # 0x8068
+    ("_glGet", I,      1,      "GL_TEXTURE_BINDING_2D"),       # 0x8069
+    ("_glGet", I,      1,      "GL_TEXTURE_BINDING_3D"),       # 0x806A
     ("glGet",  I,      1,      "GL_PACK_SKIP_IMAGES"), # 0x806B
     ("glGet",  F,      1,      "GL_PACK_IMAGE_HEIGHT"),        # 0x806C
     ("glGet",  I,      1,      "GL_UNPACK_SKIP_IMAGES"),       # 0x806D
@@ -1182,8 +1182,8 @@ parameters = [
     ("",       X,      1,      "GL_ALL_COMPLETED_NV"), # 0x84F2
     ("",       X,      1,      "GL_FENCE_STATUS_NV"),  # 0x84F3
     ("",       X,      1,      "GL_FENCE_CONDITION_NV"),       # 0x84F4
-    ("glGet",  B,      1,      "GL_TEXTURE_RECTANGLE"),        # 0x84F5
-    ("glGet",  I,      1,      "GL_TEXTURE_BINDING_RECTANGLE"),        # 0x84F6
+    ("_glGet", B,      1,      "GL_TEXTURE_RECTANGLE"),        # 0x84F5
+    ("_glGet", I,      1,      "GL_TEXTURE_BINDING_RECTANGLE"),        # 0x84F6
     ("",       X,      1,      "GL_PROXY_TEXTURE_RECTANGLE"),  # 0x84F7
     ("glGet",  I,      1,      "GL_MAX_RECTANGLE_TEXTURE_SIZE"),       # 0x84F8
     ("",       X,      1,      "GL_DEPTH_STENCIL"),    # 0x84F9
@@ -1210,8 +1210,8 @@ parameters = [
     ("",       X,      1,      "GL_VERTEX_WEIGHT_ARRAY_POINTER_EXT"),  # 0x8510
     ("",       X,      1,      "GL_NORMAL_MAP"),       # 0x8511
     ("",       X,      1,      "GL_REFLECTION_MAP"),   # 0x8512
-    ("glGet",  B,      1,      "GL_TEXTURE_CUBE_MAP"), # 0x8513
-    ("glGet",  I,      1,      "GL_TEXTURE_BINDING_CUBE_MAP"), # 0x8514
+    ("_glGet", B,      1,      "GL_TEXTURE_CUBE_MAP"), # 0x8513
+    ("_glGet", I,      1,      "GL_TEXTURE_BINDING_CUBE_MAP"), # 0x8514
     ("",       X,      1,      "GL_TEXTURE_CUBE_MAP_POSITIVE_X"),      # 0x8515
     ("",       X,      1,      "GL_TEXTURE_CUBE_MAP_NEGATIVE_X"),      # 0x8516
     ("",       X,      1,      "GL_TEXTURE_CUBE_MAP_POSITIVE_Y"),      # 0x8517
@@ -2253,8 +2253,8 @@ parameters = [
     ("",       X,      1,      "GL_PROXY_TEXTURE_1D_ARRAY"),   # 0x8C19
     ("",       X,      1,      "GL_TEXTURE_2D_ARRAY"), # 0x8C1A
     ("",       X,      1,      "GL_PROXY_TEXTURE_2D_ARRAY"),   # 0x8C1B
-    ("glGet",  I,      1,      "GL_TEXTURE_BINDING_1D_ARRAY"), # 0x8C1C
-    ("glGet",  I,      1,      "GL_TEXTURE_BINDING_2D_ARRAY"), # 0x8C1D
+    ("_glGet", I,      1,      "GL_TEXTURE_BINDING_1D_ARRAY"), # 0x8C1C
+    ("_glGet", I,      1,      "GL_TEXTURE_BINDING_2D_ARRAY"), # 0x8C1D
     ("",       X,      1,      "GL_GEOMETRY_PROGRAM_NV"),      # 0x8C26
     ("",       X,      1,      "GL_MAX_PROGRAM_OUTPUT_VERTICES_NV"),   # 0x8C27
     ("",       X,      1,      "GL_MAX_PROGRAM_TOTAL_OUTPUT_COMPONENTS_NV"),   # 0x8C28
@@ -2697,7 +2697,7 @@ parameters = [
     ("",       X,      1,      "GL_DISCRETE_AMD"),     # 0x9006
     ("",       X,      1,      "GL_CONTINUOUS_AMD"),   # 0x9007
     ("",       X,      1,      "GL_TEXTURE_CUBE_MAP_ARRAY"),   # 0x9009
-    ("glGet",  I,      1,      "GL_TEXTURE_BINDING_CUBE_MAP_ARRAY"),   # 0x900A
+    ("_glGet", I,      1,      "GL_TEXTURE_BINDING_CUBE_MAP_ARRAY"),   # 0x900A
     ("",       X,      1,      "GL_PROXY_TEXTURE_CUBE_MAP_ARRAY"),     # 0x900B
     ("",       X,      1,      "GL_SAMPLER_CUBE_MAP_ARRAY"),   # 0x900C
     ("",       X,      1,      "GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW"),    # 0x900D
index 6a5103e0db2523894d8ff60f7632191af4cc3f19..b6dac924ef5b4e350f2ee0321c81fae96696eb15 100644 (file)
@@ -170,6 +170,12 @@ class GlRetracer(Retracer):
             print '    GLint __pack_buffer = 0;'
             print '    glGetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &__pack_buffer);'
             print '    if (!__pack_buffer) {'
+            if function.name == 'glReadPixels':
+                print '    glFinish();'
+                print '    if (glretrace::snapshot_frequency == glretrace::FREQUENCY_FRAME ||'
+                print '        glretrace::snapshot_frequency == glretrace::FREQUENCY_FRAMEBUFFER) {'
+                print '        glretrace::snapshot(call.no);'
+                print '    }'
             print '        return;'
             print '    }'
 
@@ -178,6 +184,9 @@ class GlRetracer(Retracer):
             print '    if (glretrace::snapshot_frequency == glretrace::FREQUENCY_FRAMEBUFFER) {'
             print '        glretrace::snapshot(call.no - 1);'
             print '    }'
+        if function.name == 'glFrameTerminatorGREMEDY':
+            print '    glretrace::frame_complete(call.no);'
+            return
 
         Retracer.retrace_function_body(self, function)
 
@@ -186,12 +195,6 @@ class GlRetracer(Retracer):
             print '    if (!glretrace::double_buffer) {'
             print '        glretrace::frame_complete(call.no);'
             print '    }'
-        if function.name == 'glReadPixels':
-            print '    glFinish();'
-            print '    if (glretrace::snapshot_frequency == glretrace::FREQUENCY_FRAME ||'
-            print '        glretrace::snapshot_frequency == glretrace::FREQUENCY_FRAMEBUFFER) {'
-            print '        glretrace::snapshot(call.no);'
-            print '    }'
         if is_draw_array or is_draw_elements or is_misc_draw:
             print '    if (glretrace::snapshot_frequency == glretrace::FREQUENCY_DRAW) {'
             print '        glretrace::snapshot(call.no);'
index aaf4d4bd6b6b5b15c4a67c9c3f51947b1a5b0d91..ac63a78b84bbc8629acf12490db4b83956634d75 100644 (file)
@@ -591,7 +591,7 @@ dumpTextureImage(JSONWriter &json, GLenum target, GLint level)
         json.beginMember("__data__");
         char *pngBuffer;
         int pngBufferSize;
-        Image::writePixelsToBuffer(pixels, width, height, 4, false, &pngBuffer, &pngBufferSize);
+        Image::writePixelsToBuffer(pixels, width, height, 4, true, &pngBuffer, &pngBufferSize);
         json.writeBase64(pngBuffer, pngBufferSize);
         free(pngBuffer);
         json.endMember(); // __data__
@@ -949,7 +949,7 @@ dumpReadBufferImage(JSONWriter &json, GLint width, GLint height, GLenum format)
     json.beginMember("__data__");
     char *pngBuffer;
     int pngBufferSize;
-    Image::writePixelsToBuffer(pixels, width, height, channels, false, &pngBuffer, &pngBufferSize);
+    Image::writePixelsToBuffer(pixels, width, height, channels, true, &pngBuffer, &pngBufferSize);
     //std::cerr <<" Before = "<<(width * height * channels * sizeof *pixels)
     //          <<", after = "<<pngBufferSize << ", ratio = " << double(width * height * channels * sizeof *pixels)/pngBufferSize;
     json.writeBase64(pngBuffer, pngBufferSize);
index fb3e090bff8d094f66ce0ee4ea78ecfc9918d014..c348d2b99b69dd2273ca30067f6a5c1fe237f7c6 100644 (file)
@@ -380,13 +380,18 @@ class StateDumper:
         print '            json.beginMember(name);'
         print '            glActiveTexture(GL_TEXTURE0 + unit);'
         print '            json.beginObject();'
-        print '            GLint texture;'
+        print '            GLboolean enabled;'
+        print '            GLint binding;'
         print
         for target, binding in texture_targets:
             print '            // %s' % target
-            print '            texture = 0;'
-            print '            glGetIntegerv(%s, &texture);' % binding
-            print '            if (glIsEnabled(%s) || texture) {' % target
+            print '            enabled = GL_FALSE;'
+            print '            glGetBooleanv(%s, &enabled);' % target
+            print '            json.writeBoolMember("%s", enabled);' % target
+            print '            binding = 0;'
+            print '            glGetIntegerv(%s, &binding);' % binding
+            print '            json.writeNumberMember("%s", binding);' % binding
+            print '            if (enabled || binding) {'
             print '                json.beginMember("%s");' % target
             print '                json.beginObject();'
             self.dump_atoms(glGetTexParameter, target)
index 64aa1532bc7083a89de2ea130489c3f7b146d8bb..050c081756bf4ef7e1f9079802c0790b7589fe35 100644 (file)
@@ -31,7 +31,6 @@ void ApiSurface::contentsFromBase64(const QByteArray &base64)
 {
     QByteArray dataArray = QByteArray::fromBase64(base64);
     m_image.loadFromData(dataArray, "png");
-    m_image = m_image.mirrored();
     m_thumb = m_image.scaled(64, 64, Qt::KeepAspectRatio);
 }
 
index f311fe0d3e33f52e19bfcc1c471d8666a809d953..03f0ccd0f68569983d7bc9b0ca362bae23ab8f70 100644 (file)
@@ -95,6 +95,10 @@ void LoaderThread::run()
     //  it's just a bunch of Delete calls for every object
     //  after the last SwapBuffers
     if (currentFrame) {
+        if (!frames.count()) {
+            calls.squeeze();
+            currentFrame->setCalls(calls, binaryDataSize);
+        }
         frames.append(currentFrame);
         currentFrame = 0;
     }
index 652cd0f3f70bb0b14216aa2a48919b11b74c4767..2d002868920feda1d7c2d48438bd8af5e88b8351 100644 (file)
@@ -116,12 +116,12 @@ bool ZLibFile::rawOpen(const std::string &filename, File::Mode mode)
     return m_gzFile != NULL;
 }
 
-bool ZLibFile::rawWrite(const void *buffer, int length)
+bool ZLibFile::rawWrite(const void *buffer, size_t length)
 {
     return gzwrite(m_gzFile, buffer, length) != -1;
 }
 
-bool ZLibFile::rawRead(void *buffer, int length)
+bool ZLibFile::rawRead(void *buffer, size_t length)
 {
     return gzread(m_gzFile, buffer, length) != -1;
 }
index 13b392cdaa8876729791fb641a2e1f747f2dca8b..487121187fdd9dad368fe631445b3ffea218a80e 100644 (file)
@@ -62,8 +62,8 @@ public:
     std::string filename() const;
 
     bool open(const std::string &filename, File::Mode mode);
-    bool write(const void *buffer, int length);
-    bool read(void *buffer, int length);
+    bool write(const void *buffer, size_t length);
+    bool read(void *buffer, size_t length);
     void close();
     void flush(void);
     int getc();
@@ -74,8 +74,8 @@ public:
     virtual void setCurrentOffset(const File::Offset &offset);
 protected:
     virtual bool rawOpen(const std::string &filename, File::Mode mode) = 0;
-    virtual bool rawWrite(const void *buffer, int length) = 0;
-    virtual bool rawRead(void *buffer, int length) = 0;
+    virtual bool rawWrite(const void *buffer, size_t length) = 0;
+    virtual bool rawRead(void *buffer, size_t length) = 0;
     virtual int rawGetc() = 0;
     virtual void rawClose() = 0;
     virtual void rawFlush() = 0;
@@ -113,7 +113,7 @@ inline bool File::open(const std::string &filename, File::Mode mode)
     return m_isOpened;
 }
 
-inline bool File::write(const void *buffer, int length)
+inline bool File::write(const void *buffer, size_t length)
 {
     if (!m_isOpened || m_mode != File::Write) {
         return false;
@@ -121,7 +121,7 @@ inline bool File::write(const void *buffer, int length)
     return rawWrite(buffer, length);
 }
 
-inline bool File::read(void *buffer, int length)
+inline bool File::read(void *buffer, size_t length)
 {
     if (!m_isOpened || m_mode != File::Read) {
         return false;
@@ -168,8 +168,8 @@ public:
     virtual bool supportsOffsets() const;
 protected:
     virtual bool rawOpen(const std::string &filename, File::Mode mode);
-    virtual bool rawWrite(const void *buffer, int length);
-    virtual bool rawRead(void *buffer, int length);
+    virtual bool rawWrite(const void *buffer, size_t length);
+    virtual bool rawRead(void *buffer, size_t length);
     virtual int rawGetc();
     virtual void rawClose();
     virtual void rawFlush();
index 443ebe7c5040c131bf7eef72daeb84ace273b98b..c350013d7f1acc7e7ff1546fa860019f94d47762 100644 (file)
@@ -46,7 +46,7 @@ using namespace Trace;
  * The file is composed of a number of chunks, they are:
  * chunk {
  *     uint32 - specifying the length of the compressed data
- *     compressed data
+ *     compressed data, in little endian
  * }
  * File can contain any number of such chunks.
  * The default size of an uncompressed chunk is specified in
@@ -76,6 +76,7 @@ SnappyFile::SnappyFile(const std::string &filename,
 SnappyFile::~SnappyFile()
 {
     delete [] m_compressedCache;
+    delete [] m_cache;
 }
 
 bool SnappyFile::rawOpen(const std::string &filename, File::Mode mode)
@@ -107,7 +108,7 @@ bool SnappyFile::rawOpen(const std::string &filename, File::Mode mode)
     return m_stream.is_open();
 }
 
-bool SnappyFile::rawWrite(const void *buffer, int length)
+bool SnappyFile::rawWrite(const void *buffer, size_t length)
 {
     if (freeCacheSize() > length) {
         memcpy(m_cachePtr, buffer, length);
@@ -122,14 +123,14 @@ bool SnappyFile::rawWrite(const void *buffer, int length)
         while (sizeToWrite >= freeCacheSize()) {
             int endSize = freeCacheSize();
             int offset = length - sizeToWrite;
-            memcpy(m_cachePtr, (char*)buffer + offset, endSize);
+            memcpy(m_cachePtr, (const char*)buffer + offset, endSize);
             sizeToWrite -= endSize;
             m_cachePtr += endSize;
             flushCache();
         }
         if (sizeToWrite) {
             int offset = length - sizeToWrite;
-            memcpy(m_cachePtr, (char*)buffer + offset, sizeToWrite);
+            memcpy(m_cachePtr, (const char*)buffer + offset, sizeToWrite);
             m_cachePtr += sizeToWrite;
         }
     }
@@ -137,7 +138,7 @@ bool SnappyFile::rawWrite(const void *buffer, int length)
     return true;
 }
 
-bool SnappyFile::rawRead(void *buffer, int length)
+bool SnappyFile::rawRead(void *buffer, size_t length)
 {
     if (endOfData()) {
         return false;
@@ -147,10 +148,10 @@ bool SnappyFile::rawRead(void *buffer, int length)
         memcpy(buffer, m_cachePtr, length);
         m_cachePtr += length;
     } else {
-        int sizeToRead = length;
-        int offset = 0;
+        size_t sizeToRead = length;
+        size_t offset = 0;
         while (sizeToRead) {
-            int chunkSize = std::min(freeCacheSize(), sizeToRead);
+            size_t chunkSize = std::min(freeCacheSize(), sizeToRead);
             offset = length - sizeToRead;
             memcpy((char*)buffer + offset, m_cachePtr, chunkSize);
             m_cachePtr += chunkSize;
@@ -191,57 +192,81 @@ void SnappyFile::rawFlush()
 void SnappyFile::flushCache()
 {
     if (m_mode == File::Write) {
-        size_t compressedLength;
+        size_t inputLength = usedCacheSize();
 
-        ::snappy::RawCompress(m_cache, SNAPPY_CHUNK_SIZE - freeCacheSize(),
-                              m_compressedCache, &compressedLength);
+        if (inputLength) {
+            size_t compressedLength;
 
-        writeCompressedLength(compressedLength);
-        m_stream.write(m_compressedCache, compressedLength);
-        m_cachePtr = m_cache;
+            ::snappy::RawCompress(m_cache, inputLength,
+                                  m_compressedCache, &compressedLength);
+
+            writeCompressedLength(compressedLength);
+            m_stream.write(m_compressedCache, compressedLength);
+            m_cachePtr = m_cache;
+        }
+        assert(m_cachePtr == m_cache);
     } else if (m_mode == File::Read) {
-        if (m_stream.eof())
-            return;
         //assert(m_cachePtr == m_cache + m_cacheSize);
         m_currentOffset.chunk = m_stream.tellg();
         size_t compressedLength;
         compressedLength = readCompressedLength();
-        m_stream.read((char*)m_compressedCache, compressedLength);
-        /*
-         * The reason we peek here is because the last read will
-         * read all the way until the last character, but that will not
-         * trigger m_stream.eof() to be set, so by calling peek
-         * we assure that if we in fact have read the entire stream
-         * then the m_stream.eof() is always set.
-         */
-        m_stream.peek();
-        ::snappy::GetUncompressedLength(m_compressedCache, compressedLength,
-                                        &m_cacheSize);
-        if (m_cache)
-            delete [] m_cache;
-        createCache(m_cacheSize);
-        ::snappy::RawUncompress(m_compressedCache, compressedLength,
-                                m_cache);
+
+        if (compressedLength) {
+            m_stream.read((char*)m_compressedCache, compressedLength);
+            ::snappy::GetUncompressedLength(m_compressedCache, compressedLength,
+                                            &m_cacheSize);
+            createCache(m_cacheSize);
+            ::snappy::RawUncompress(m_compressedCache, compressedLength,
+                                    m_cache);
+        } else {
+            createCache(0);
+        }
     }
 }
 
 void SnappyFile::createCache(size_t size)
 {
-    m_cache = new char[size];
+    // TODO: only re-allocate if the current buffer is not big enough
+
+    if (m_cache) {
+        delete [] m_cache;
+    }
+
+    if (size) {
+        m_cache = new char[size];
+    } else {
+        m_cache = NULL;
+    }
+
     m_cachePtr = m_cache;
     m_cacheSize = size;
 }
 
-void SnappyFile::writeCompressedLength(uint32_t value)
+void SnappyFile::writeCompressedLength(size_t length)
 {
-    m_stream.write((const char*)&value, sizeof value);
+    unsigned char buf[4];
+    buf[0] = length & 0xff; length >>= 8;
+    buf[1] = length & 0xff; length >>= 8;
+    buf[2] = length & 0xff; length >>= 8;
+    buf[3] = length & 0xff; length >>= 8;
+    assert(length == 0);
+    m_stream.write((const char *)buf, sizeof buf);
 }
 
-uint32_t SnappyFile::readCompressedLength()
+size_t SnappyFile::readCompressedLength()
 {
-    uint32_t len;
-    m_stream.read((char*)&len, sizeof len);
-    return len;
+    unsigned char buf[4];
+    size_t length;
+    m_stream.read((char *)buf, sizeof buf);
+    if (m_stream.fail()) {
+        length = 0;
+    } else {
+        length  =  (size_t)buf[0];
+        length |= ((size_t)buf[1] <<  8);
+        length |= ((size_t)buf[2] << 16);
+        length |= ((size_t)buf[3] << 24);
+    }
+    return length;
 }
 
 bool SnappyFile::supportsOffsets() const
index ecf39dedbe649a470f531aaba1bf56918812e797..398ff7900c335a4c7f3b55d8afe0e643c5651e49 100644 (file)
 #ifndef TRACE_SNAPPYFILE_HPP
 #define TRACE_SNAPPYFILE_HPP
 
+#include <assert.h>
+
 #include "trace_file.hpp"
 
 #include <string>
 #include <fstream>
 
-#include <stdint.h>
-
 namespace snappy {
     class File;
 }
@@ -57,20 +57,27 @@ public:
     virtual void setCurrentOffset(const File::Offset &offset);
 protected:
     virtual bool rawOpen(const std::string &filename, File::Mode mode);
-    virtual bool rawWrite(const void *buffer, int length);
-    virtual bool rawRead(void *buffer, int length);
+    virtual bool rawWrite(const void *buffer, size_t length);
+    virtual bool rawRead(void *buffer, size_t length);
     virtual int rawGetc();
     virtual void rawClose();
     virtual void rawFlush();
     virtual bool rawSkip(unsigned length);
 
 private:
-    inline int freeCacheSize() const
+    inline size_t usedCacheSize() const
+    {
+        assert(m_cachePtr >= m_cache);
+        return m_cachePtr - m_cache;
+    }
+    inline size_t freeCacheSize() const
     {
-        if (m_cacheSize > 0)
-            return m_cacheSize - (m_cachePtr - m_cache);
-        else
+        assert(m_cacheSize >= usedCacheSize());
+        if (m_cacheSize > 0) {
+            return m_cacheSize - usedCacheSize();
+        } else {
             return 0;
+        }
     }
     inline bool endOfData() const
     {
@@ -78,8 +85,8 @@ private:
     }
     void flushCache();
     void createCache(size_t size);
-    void writeCompressedLength(uint32_t  num);
-    uint32_t readCompressedLength();
+    void writeCompressedLength(size_t length);
+    size_t readCompressedLength();
 private:
     std::fstream m_stream;
     char *m_cache;