gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] [SCM] Gnash branch, master, updated. e189a1ba2a4fc3b06a7a


From: Benjamin Wolsey
Subject: [Gnash-commit] [SCM] Gnash branch, master, updated. e189a1ba2a4fc3b06a7aa9602b8e25b209d98da2
Date: Fri, 22 Oct 2010 09:58:55 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Gnash".

The branch, master has been updated
       via  e189a1ba2a4fc3b06a7aa9602b8e25b209d98da2 (commit)
       via  cfdf736fbfe6ca8c34ce23043da0bc4a707c6489 (commit)
      from  a0146c39c456fc46d4ecba6e52ff7fceed4df844 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit//commit/?id=e189a1ba2a4fc3b06a7aa9602b8e25b209d98da2


commit e189a1ba2a4fc3b06a7aa9602b8e25b209d98da2
Author: Benjamin Wolsey <address@hidden>
Date:   Fri Oct 22 11:49:52 2010 +0200

    Cleanups of zlib adapter.

diff --git a/libbase/zlib_adapter.cpp b/libbase/zlib_adapter.cpp
index 8fb3b53..acde573 100644
--- a/libbase/zlib_adapter.cpp
+++ b/libbase/zlib_adapter.cpp
@@ -8,16 +8,16 @@
 
 
 #include "zlib_adapter.h"
-#include "IOChannel.h" // for inheritance
-#include "log.h"
-#include "GnashException.h"
-#include <algorithm> // std::min
 
+#include <algorithm>
 #include <sstream>
 #include <memory>
 
-namespace gnash {
+#include "IOChannel.h" // for inheritance
+#include "log.h"
+#include "GnashException.h"
 
+namespace gnash {
 
 #ifndef HAVE_ZLIB_H
 
@@ -25,28 +25,22 @@ namespace gnash {
 // Stubs, in case client doesn't want to link to zlib.
 namespace zlib_adapter
 {
-    std::auto_ptr<IOChannel> make_inflater(std::auto_ptr<IOChannel> /*in*/)
-    {
-        abort(); // callers should check this themselves
-        return std::auto_ptr<IOChannel>(NULL);
+    std::auto_ptr<IOChannel> make_inflater(std::auto_ptr<IOChannel> /*in*/) {
+        std::abort(); 
     }
 
-    IOChannel* make_deflater(IOChannel* /*out*/)
-    {
-        abort(); // callers should check this themselves
-        return NULL;
+    IOChannel* make_deflater(IOChannel* /*out*/) {
+        std::abort(); 
     }
 }
 
-
 #else // HAVE_ZLIB_H
 
 extern "C" {
-#include <zlib.h>
+# include <zlib.h>
 }
 
-namespace zlib_adapter
-{
+namespace zlib_adapter {
 
 class InflaterIOChannel : public IOChannel 
 {
@@ -64,8 +58,7 @@ public:
     virtual bool seek(std::streampos pos);
 
     // See dox in IOChannel
-    virtual std::streamsize read(void* dst, std::streamsize bytes)
-    {
+    virtual std::streamsize read(void* dst, std::streamsize bytes) {
         if (m_error) return 0;
         return inflate_from_stream(dst, bytes);
     }
@@ -74,20 +67,17 @@ public:
     virtual void go_to_end();
 
     // See dox in IOChannel
-    virtual std::streampos tell() const
-    {
+    virtual std::streampos tell() const {
         return m_logical_stream_pos;
     }
 
     // See dox in IOChannel
-    virtual bool eof() const
-    {
+    virtual bool eof() const {
         return m_at_eof;
     }
 
     // See dox in IOChannel
-    virtual bool bad() const
-    {
+    virtual bool bad() const {
         return m_error;
     }
 
@@ -133,10 +123,9 @@ const int InflaterIOChannel::ZBUF_SIZE;
 void
 InflaterIOChannel::rewind_unused_bytes()
 {
-    if (m_zstream.avail_in > 0)
-    {
-        int    pos = m_in->tell();
-        int    rewound_pos = pos - m_zstream.avail_in;
+    if (m_zstream.avail_in > 0) {
+        const int pos = m_in->tell();
+        const int rewound_pos = pos - m_zstream.avail_in;
         assert(pos >= 0);
         assert(pos >= m_initial_stream_pos);
         assert(rewound_pos >= 0);
@@ -151,7 +140,7 @@ InflaterIOChannel::reset()
 {
     m_error = 0;
     m_at_eof = 0;
-    int    err = inflateReset(&m_zstream);
+    const int err = inflateReset(&m_zstream);
     if (err != Z_OK) {
         log_error("inflater_impl::reset() inflateReset() returned %d", err);
         m_error = 1;
@@ -187,73 +176,59 @@ InflaterIOChannel::inflate_from_stream(void* dst, 
std::streamsize bytes)
     m_zstream.next_out = static_cast<unsigned char*>(dst);
     m_zstream.avail_out = bytes;
 
-    for (;;)
-    {
-        if (m_zstream.avail_in == 0)
-        {
+    for (;;) {
+        if (m_zstream.avail_in == 0) {
             // Get more raw data.
-            int    new_bytes = m_in->read(m_rawdata, ZBUF_SIZE);
-            if (new_bytes == 0)
-            {
+            const int new_bytes = m_in->read(m_rawdata, ZBUF_SIZE);
+            if (new_bytes == 0) {
                 // The cupboard is bare!  We have nothing to feed to inflate().
                 break;
             }
-            else
-            {
+            else {
                 m_zstream.next_in = m_rawdata;
                 m_zstream.avail_in = new_bytes;
             }
         }
 
-        int    err = inflate(&m_zstream, Z_SYNC_FLUSH);
-        if (err == Z_STREAM_END)
-        {
+        const int err = inflate(&m_zstream, Z_SYNC_FLUSH);
+        if (err == Z_STREAM_END) {
             m_at_eof = true;
             break;
         }
-        if (err == Z_BUF_ERROR)
-        {
+        if (err == Z_BUF_ERROR) {
             std::ostringstream ss;
             ss << __FILE__ << ":" << __LINE__ << ": " << m_zstream.msg;
             log_error("%s", ss.str());
             break;
         }
-        if (err == Z_DATA_ERROR)
-        {
+        if (err == Z_DATA_ERROR) {
             std::ostringstream ss;
             ss << __FILE__ << ":" << __LINE__ << ": " << m_zstream.msg;
             throw ParserException(ss.str());
             break;
         }
-        if (err == Z_MEM_ERROR)
-        {
+        if (err == Z_MEM_ERROR) {
             std::ostringstream ss;
             ss << __FILE__ << ":" << __LINE__ << ": " << m_zstream.msg;
             throw ParserException(ss.str());
             break;
         }
-        if (err != Z_OK)
-        {
+        if (err != Z_OK) {
             // something's wrong.
             std::ostringstream ss;
             ss << __FILE__ << ":" << __LINE__ << ": " << m_zstream.msg;
             throw ParserException(ss.str());
-            //m_error = 1;
             break;
         }
 
-        if (m_zstream.avail_out == 0)
-        {
+        if (m_zstream.avail_out == 0) {
             break;
         }
     }
 
-    if (m_error)
-    {
-        return 0;
-    }
+    if (m_error) return 0;
 
-    int    bytes_read = bytes - m_zstream.avail_out;
+    const int bytes_read = bytes - m_zstream.avail_out;
     m_logical_stream_pos += bytes_read;
 
     return bytes_read;
@@ -262,21 +237,19 @@ InflaterIOChannel::inflate_from_stream(void* dst, 
std::streamsize bytes)
 void
 InflaterIOChannel::go_to_end()
 {
-    if (m_error)
-    {
-        throw IOException("InflaterIOChannel is in error condition, can't seek 
to end");
+    if (m_error) {
+        throw IOException("InflaterIOChannel is in error condition, "
+                "can't seek to end");
     }
 
     // Keep reading until we can't read any more.
 
-    unsigned char    temp[ZBUF_SIZE];
+    unsigned char temp[ZBUF_SIZE];
 
     // Seek forwards.
-    for (;;)
-    {
-        std::streamsize bytes_read = inflate_from_stream(temp, ZBUF_SIZE);
-        if (bytes_read == 0)
-        {
+    for (;;) {
+        const std::streamsize bytes_read = inflate_from_stream(temp, 
ZBUF_SIZE);
+        if (!bytes_read) {
             // We've seeked as far as we can.
             break;
         }
@@ -286,15 +259,13 @@ InflaterIOChannel::go_to_end()
 bool
 InflaterIOChannel::seek(std::streampos pos)
 {
-    if (m_error)
-    {
+    if (m_error) {
         log_debug("Inflater is in error condition");
         return false;
     }
 
     // If we're seeking backwards, then restart from the beginning.
-    if (pos < m_logical_stream_pos)
-    {
+    if (pos < m_logical_stream_pos) {
         log_debug("inflater reset due to seek back from %d to %d",
                 m_logical_stream_pos, pos );
         reset();
@@ -303,8 +274,7 @@ InflaterIOChannel::seek(std::streampos pos)
     unsigned char temp[ZBUF_SIZE];
 
     // Now seek forwards, by just reading data in blocks.
-    while (m_logical_stream_pos < pos)
-    {
+    while (m_logical_stream_pos < pos) {
         std::streamsize to_read = pos - m_logical_stream_pos;
         assert(to_read > 0);
 
@@ -313,12 +283,9 @@ InflaterIOChannel::seek(std::streampos pos)
 
         std::streamsize bytes_read = inflate_from_stream(temp, readNow);
         assert(bytes_read <= readNow);
-        if (bytes_read == 0)
-        {
-            // Trouble; can't seek any further.
+        if (bytes_read == 0) {
             log_debug("Trouble: can't seek any further.. ");
             return false;
-            break;
         }
     }
 
@@ -331,44 +298,27 @@ 
InflaterIOChannel::InflaterIOChannel(std::auto_ptr<IOChannel> in)
     :
     m_in(in),
     m_initial_stream_pos(m_in->tell()),
+    m_zstream(),
     m_logical_stream_pos(m_initial_stream_pos),
     m_at_eof(false),
     m_error(0)
 {
     assert(m_in.get());
 
-    m_zstream.zalloc = (alloc_func)0;
-    m_zstream.zfree = (free_func)0;
-    m_zstream.opaque = (voidpf)0;
-
-    m_zstream.next_in  = 0;
-    m_zstream.avail_in = 0;
-
-    m_zstream.next_out = 0;
-    m_zstream.avail_out = 0;
-
-    int    err = inflateInit(&m_zstream);
+    const int err = inflateInit(&m_zstream);
     if (err != Z_OK) {
-        log_error("inflater_impl::ctor() inflateInit() returned %d", err);
+        log_error("inflateInit() returned %d", err);
         m_error = 1;
         return;
     }
-
-    // Ready to go!
 }
 
-
-
 std::auto_ptr<IOChannel> make_inflater(std::auto_ptr<IOChannel> in)
 {
     assert(in.get());
     return std::auto_ptr<IOChannel> (new InflaterIOChannel(in));
 }
 
-
-// @@ TODO
-// IOChannel*    make_deflater(IOChannel* out) { ... }
-
 }
 
 #endif // HAVE_ZLIB_H

http://git.savannah.gnu.org/cgit//commit/?id=cfdf736fbfe6ca8c34ce23043da0bc4a707c6489


commit cfdf736fbfe6ca8c34ce23043da0bc4a707c6489
Author: Benjamin Wolsey <address@hidden>
Date:   Fri Oct 22 11:36:05 2010 +0200

    Don't cast unnecessarily and fix some documentation.

diff --git a/libbase/tu_file.cpp b/libbase/tu_file.cpp
index 3474f08..c28b2fd 100644
--- a/libbase/tu_file.cpp
+++ b/libbase/tu_file.cpp
@@ -6,56 +6,61 @@
 // A file class that can be customized with callbacks.
 
 #include "tu_file.h"
-#include "log.h"
 
 #include <boost/format.hpp>
 #include <cerrno>
 #include <cstdio>
-#include "GnashFileUtilities.h"
 
-//
-// tu_file functions using FILE
-//
+#include "GnashFileUtilities.h"
+#include "log.h"
 
 namespace gnash {
 
+//// Create a file from a standard file pointer.
+tu_file::tu_file(FILE* fp, bool autoclose = false)
+    :
+    _data(fp),
+    _autoclose(autoclose)
+{
+}
+
+tu_file::~tu_file()
+{
+    // Close this file when destroyed unless not requested.
+    if (_autoclose) close();
+}
+
 
-std::streamsize
-tu_file::read(void* dst, std::streamsize bytes) 
 // Return the number of bytes actually read.  EOF or an error would
 // cause that to not be equal to "bytes".
+std::streamsize
+tu_file::read(void* dst, std::streamsize bytes) 
 {
-//    GNASH_REPORT_FUNCTION;
-    
     assert(dst);
-    return fread( dst, 1, bytes, static_cast<FILE*>(m_data) );
+    return std::fread(dst, 1, bytes, _data);
 }
 
+// Return the number of bytes actually written.
 std::streamsize
 tu_file::write(const void* src, std::streamsize bytes)
-// Return the number of bytes actually written.
 {
     assert(src);
-    return std::fwrite(src, 1, bytes, static_cast<FILE*>(m_data));
+    return std::fwrite(src, 1, bytes, _data);
 }
 
 bool
 tu_file::seek(std::streampos pos)
 {
-
     // TODO: optimize this by caching total stream size ?
     if (static_cast<size_t>(pos) > size()) return false;
 
-    FILE* file = static_cast<FILE*>(m_data);
-
-    std::clearerr(file); // make sure EOF flag is cleared.
-    int        result = std::fseek(file, pos, SEEK_SET);
+    std::clearerr(_data); // make sure EOF flag is cleared.
+    const int result = std::fseek(_data, pos, SEEK_SET);
     if (result == EOF) {
-        // @@ TODO should set m_error to something relevant based on errno.
         return false;
     }
 
-    assert (std::ftell(file) == pos);
+    assert (std::ftell(_data) == pos);
 
     return true;
 }
@@ -63,11 +68,10 @@ tu_file::seek(std::streampos pos)
 void
 tu_file::go_to_end()
 {
-    int err = std::fseek(static_cast<FILE*>(m_data), 0, SEEK_END);
-    if (-1 == err ) {
+    const int err = std::fseek(_data, 0, SEEK_END);
+    if (err == -1) {
         boost::format fmt = boost::format(
-                    _("Error while seeking to end: %1%")
-                ) % strerror(errno);
+                _("Error while seeking to end: %1%")) % strerror(errno);
         throw IOException(fmt.str());
     }
 }
@@ -75,9 +79,7 @@ tu_file::go_to_end()
 std::streampos
 tu_file::tell() const
 {
-    FILE* f = static_cast<FILE*>(m_data);
-
-    std::streampos ret = std::ftell(f);
+    std::streampos ret = std::ftell(_data);
     if (ret < 0) throw IOException("Error getting stream position");
 
     assert(static_cast<size_t>(ret) <= size());
@@ -87,25 +89,23 @@ tu_file::tell() const
 bool
 tu_file::eof() const
 {
-    return std::feof(static_cast<FILE*>(m_data));
+    return std::feof(_data);
 }
 
 bool
 tu_file::bad() const
 {
-    if (!m_data) return true;
-    return std::ferror(static_cast<FILE*>(m_data));
+    if (!_data) return true;
+    return std::ferror(_data);
 }
 
 size_t
 tu_file::size() const
 {
-    assert(m_data);
-
-    FILE* f = static_cast<FILE*>(m_data);
+    assert(_data);
 
     struct stat statbuf;
-    if (fstat(fileno(f), &statbuf) < 0)
+    if (fstat(fileno(_data), &statbuf) < 0)
     {
            log_error("Could not fstat file");
            return static_cast<size_t>(-1);
@@ -116,32 +116,11 @@ tu_file::size() const
 
 void
 tu_file::close()
-// Return 0 on success, or TU_FILE_CLOSE_ERROR on failure.
 {
-    assert(m_data);
-    int        result = std::fclose(static_cast<FILE*>(m_data));
-    if (result == EOF) {
-           // @@ TODO should set m_error to something relevant based on errno.
-    }
+    assert(_data);
+    std::fclose(_data);
 }
 
-
-//// Create a file from a standard file pointer.
-tu_file::tu_file(FILE* fp, bool autoclose=false) :
-    m_data(fp),
-    _autoclose(autoclose)
-{
-    //GNASH_REPORT_FUNCTION;
-}
-
-
-tu_file::~tu_file()
-// Close this file when destroyed.
-{
-    if (_autoclose) close();
-}
-
-
 } // end namespace gnash
 
 // Local Variables:
diff --git a/libbase/tu_file.h b/libbase/tu_file.h
index fab8afe..5412218 100644
--- a/libbase/tu_file.h
+++ b/libbase/tu_file.h
@@ -9,6 +9,8 @@
 #ifndef TU_FILE_H
 #define TU_FILE_H
 
+#include <cstdio>
+
 #include "dsodefs.h" // DSOEXPORT
 #include "utility.h"
 #include "IOChannel.h" // for inheritance
@@ -16,10 +18,7 @@
 
 namespace gnash {
 
-// a file abstraction that can be customized with callbacks.
-// Designed to be easy to hook up to FILE*, SDL_RWops*, or
-// whatever stream type(s) you might use in your game or
-// libraries.
+/// An IOChannel that works on a C stdio file.
 class DSOEXPORT tu_file : public gnash::IOChannel
 {
 public:
@@ -129,7 +128,7 @@ private:
     
     void close();
     
-    void *     m_data;
+    FILE* _data;
 
     bool _autoclose;
 

-----------------------------------------------------------------------

Summary of changes:
 libbase/tu_file.cpp      |   91 +++++++++++------------------
 libbase/tu_file.h        |    9 +--
 libbase/zlib_adapter.cpp |  144 +++++++++++++++-------------------------------
 3 files changed, 86 insertions(+), 158 deletions(-)


hooks/post-receive
-- 
Gnash



reply via email to

[Prev in Thread] Current Thread [Next in Thread]