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. release_0_8_9_final-


From: Bastiaan Jacques
Subject: [Gnash-commit] [SCM] Gnash branch, master, updated. release_0_8_9_final-1745-gad7e4bc
Date: Tue, 13 Aug 2013 15:37:45 +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  ad7e4bc5a031ec4784155ded68922c5e6321e58f (commit)
       via  b1e8ac117af00d44b92b8b3605066b266ef649f1 (commit)
       via  2183dbdcbb818ea6362edba16613a7c4b60f89c4 (commit)
       via  35c3fe2f54eda1d151d89d1c57910821692d7f9d (commit)
      from  e062b91a698ddce715a7c4d98724037d78ed622f (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=ad7e4bc5a031ec4784155ded68922c5e6321e58f


commit ad7e4bc5a031ec4784155ded68922c5e6321e58f
Author: Bastiaan Jacques <address@hidden>
Date:   Tue Aug 13 17:36:24 2013 +0200

    Check the return value.

diff --git a/libbase/Socket.cpp b/libbase/Socket.cpp
index 647ac1c..b23240a 100644
--- a/libbase/Socket.cpp
+++ b/libbase/Socket.cpp
@@ -165,6 +165,9 @@ Socket::connect(const std::string& hostname, 
boost::uint16_t port)
 
     // This is used for ::connect()
     ScopedPtr<addrinfo> ans(getAddrInfo(hostname, port), freeaddrinfo);
+    if (!ans.get()) {
+        return false;
+    }
 
     // display all the IP numbers
     if (LogFile::getDefaultInstance().getVerbosity() != 0) {

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


commit b1e8ac117af00d44b92b8b3605066b266ef649f1
Author: Bastiaan Jacques <address@hidden>
Date:   Tue Aug 13 17:34:05 2013 +0200

    Manage addrinfo in a ScopedPtr.

diff --git a/libbase/Socket.cpp b/libbase/Socket.cpp
index 402467e..647ac1c 100644
--- a/libbase/Socket.cpp
+++ b/libbase/Socket.cpp
@@ -35,6 +35,7 @@
 #include "utility.h"
 #include "GnashAlgorithm.h"
 #include "GnashSystemNetHeaders.h"
+#include "GnashScopedPtr.h"
 
 namespace gnash {
 
@@ -122,6 +123,28 @@ Socket::close()
     _error = false;
 }
 
+namespace {
+
+addrinfo* getAddrInfo(const std::string& hostname, boost::uint16_t port)
+{
+    addrinfo req = addrinfo(), *ans = 0;
+    
+    req.ai_family = AF_UNSPEC;  // Allow IPv4 or IPv6
+    req.ai_socktype = SOCK_STREAM;
+
+    std::string portNo = boost::lexical_cast<std::string>(port);
+    int code = getaddrinfo(hostname.c_str(), portNo.c_str(), &req, &ans);
+    if (code != 0) {
+        log_error(_("getaddrinfo() failed with code: #%d - %s"),
+                 code, gai_strerror(code));
+        return 0;
+    }
+
+    return ans;
+}
+  
+}
+
 bool
 Socket::connect(const std::string& hostname, boost::uint16_t port)
 {
@@ -141,26 +164,14 @@ Socket::connect(const std::string& hostname, 
boost::uint16_t port)
     }
 
     // This is used for ::connect()
-
-    addrinfo req = addrinfo(), *ans = 0;
-    
-    req.ai_family = AF_UNSPEC;  // Allow IPv4 or IPv6
-    req.ai_socktype = SOCK_STREAM;
-
-    std::string portNo = boost::lexical_cast<std::string>(port);
-    int code = getaddrinfo(hostname.c_str(), portNo.c_str(), &req, &ans);
-    if (code != 0) {
-        log_error(_("getaddrinfo() failed with code: #%d - %s"),
-                 code, gai_strerror(code));
-        return false;
-    }
+    ScopedPtr<addrinfo> ans(getAddrInfo(hostname, port), freeaddrinfo);
 
     // display all the IP numbers
     if (LogFile::getDefaultInstance().getVerbosity() != 0) {
-        for(struct addrinfo* ot = ans; ot; ot = ot->ai_next) {
+        for(const addrinfo* ot = ans.get(); ot; ot = ot->ai_next) {
 
             char clienthost [INET6_ADDRSTRLEN] = {};
-            code = getnameinfo(ot->ai_addr, ot->ai_addrlen,
+            int code = getnameinfo(ot->ai_addr, ot->ai_addrlen,
                                clienthost, sizeof(clienthost),
                                NULL, 0, NI_NUMERICHOST);
 
@@ -174,7 +185,7 @@ Socket::connect(const std::string& hostname, 
boost::uint16_t port)
 
     // Multiple IPV$ and IPV6 numbers may be returned, so we try them all if
     // required
-    struct addrinfo *it = ans;
+    const addrinfo *it = ans.get();
     while (it) {
         _socket = ::socket(it->ai_family, it->ai_socktype, it->ai_protocol);
         if (_socket < 0) {
@@ -190,7 +201,6 @@ Socket::connect(const std::string& hostname, 
boost::uint16_t port)
 
     if (!it) {
         log_error(_("Socket creation attempt(s) failed: giving up."));
-        freeaddrinfo(ans);
         return false;
     }
 
@@ -202,7 +212,6 @@ Socket::connect(const std::string& hostname, 
boost::uint16_t port)
 
     // Attempt connection
     int ret = ::connect(_socket, it->ai_addr, it->ai_addrlen);
-    freeaddrinfo(ans);          // free the response data
     if (ret < 0) {
         const int err = errno;
 #ifndef _WIN32

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


commit 2183dbdcbb818ea6362edba16613a7c4b60f89c4
Author: Bastiaan Jacques <address@hidden>
Date:   Tue Aug 13 17:33:33 2013 +0200

    A little RAII class for managing C API pointers.

diff --git a/libbase/GnashScopedPtr.h b/libbase/GnashScopedPtr.h
new file mode 100644
index 0000000..86603d6
--- /dev/null
+++ b/libbase/GnashScopedPtr.h
@@ -0,0 +1,85 @@
+// GnashSmartPtr.h: scoped pointer supporting deleters.
+//
+//   Copyright (C) 2013
+//   Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+#ifndef GNASH_SCOPED_PTR_H
+#define GNASH_SCOPED_PTR_H
+
+#include <boost/utility.hpp> // noncopyable
+#include <boost/function.hpp>
+
+namespace gnash {
+
+/// ScopedPtr is very similar to scoped_ptr, but includes the Deleter
+/// functionality from shared_ptr. ScopedPtr can be used to implement the RAII
+/// pattern for C APIs, which frequently have their own deallocation strategy,
+/// when shared_ptr semantics are not desirable.
+//
+/// ScopedPtr is similar to C++11's unique_ptr, but the deleter is not part of
+/// the type.
+template <typename T>
+class ScopedPtr : public boost::noncopyable
+{
+private:
+    typedef boost::function<void(T* x)> DeleterT;
+public:
+
+    /// Construct a ScopedPtr and provide a deleter.
+    ///
+    /// @ptr the pointer to exclusively manage.
+    /// @deleter the deleter to call when this object goes out of scope.
+    /// The expression d(ptr) must be well-formed.
+    explicit ScopedPtr(T* ptr, DeleterT d)
+    : _ptr(ptr),
+      _deleter(d)
+    {}
+
+    /// Dereferences the managed pointer and returns a reference.
+    T& operator*() const 
+    {
+        return *_ptr;
+    }
+
+    /// Dereference the contained pointer.
+    T* operator->() const
+    {
+        return _ptr;
+    }
+
+    /// Obtain the contained pointer.
+    T* get() const
+    {
+        return _ptr;
+    }
+
+    ~ScopedPtr()
+    {
+        if (_ptr) {
+            _deleter(_ptr);
+        }
+    }
+private:
+
+    T* _ptr;
+    DeleterT _deleter;
+};
+
+} // namespace gnash
+
+#endif

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


commit 35c3fe2f54eda1d151d89d1c57910821692d7f9d
Author: Bastiaan Jacques <address@hidden>
Date:   Tue Aug 13 16:05:57 2013 +0200

    Fix warning, and also tidy up and refactor.

diff --git a/cygnal/libamf/sol.cpp b/cygnal/libamf/sol.cpp
index 43a9b4c..0963dcd 100644
--- a/cygnal/libamf/sol.cpp
+++ b/cygnal/libamf/sol.cpp
@@ -51,10 +51,10 @@ using gnash::log_error;
 // Object Name  - variable (the name of the object as an AMF encoded string)
 // Padding      - 4 bytes
 // After this is a series of AMF objects
-const short SOL_MAGIC = 0x00bf;        // is in big-endian format, this is the 
first
+const boost::uint16_t SOL_MAGIC = 0x00bf;      // is in big-endian format, 
this is the first
                                // two bytes. of the .sol file.
 //char *SOL_FILETYPE = "TCSO";
-const short SOL_BLOCK_MARK = 0x0004;
+const boost::uint16_t SOL_BLOCK_MARK = 0x0004;
 
 /// \define ENSUREBYTES
 ///
@@ -149,6 +149,15 @@ SOL::formatHeader(const std::string &name)
     return formatHeader(name, _filesize);
 }
 
+template <typename T>
+void
+appendSwapped(std::vector<boost::uint8_t>& container, T val)
+{
+    boost::uint8_t *ptr = 
+        static_cast<boost::uint8_t*>(swapBytes(&val, sizeof(val)));
+    container.insert(container.end(), ptr, ptr+sizeof(val));
+}
+
 /// \brief Create the file header.
 ///
 /// @param name The name of the SharedObject for this file.
@@ -160,67 +169,40 @@ bool
 SOL::formatHeader(const std::string &name, int filesize)
 {
 //    GNASH_REPORT_FUNCTION;
-    boost::uint32_t i;
 
     // First we add the magic number. All SOL data is in big-endian format,
     // so we swap it first.
-    boost::uint16_t swapped = SOL_MAGIC;
-    swapped = htons(swapped);
-    boost::uint8_t *ptr = reinterpret_cast<boost::uint8_t *>(&swapped);
-    for (i=0; i<sizeof(boost::uint16_t); i++) {
-        _header.push_back(ptr[i]);
-    }
+    appendSwapped(_header, SOL_MAGIC);
 
     // Next is the file size to be created. We adjust it as the filesize
     // includes the padding in the header, the mystery bytes, and the
     // padding, plus the length of the name itself.
     filesize += name.size() + 16;
     boost::uint32_t len = filesize;
-    len = htonl(len);
-    ptr = reinterpret_cast<boost::uint8_t *>(&len);
-    for (i=0; i<sizeof(boost::uint32_t); i++) {
-        _header.push_back(ptr[i]);
-    }
+    appendSwapped(_header, len);
 
     // Then the mystery block, but as the value never seems to every change,
     // we just built it the same way it always is.
     // first is the TCSO, we have no idea what this stands for.
-//    ptr = reinterpret_cast<uint8_t *>(const_cast<uint8_t *>("TCSO");
-       ptr = (boost::uint8_t *)"TCSO";
-    for (i=0; i<sizeof(boost::uint32_t); i++) {
-        _header.push_back(ptr[i]);
-    }
+    const char magic[] = "TCSO";
+    _header.insert(_header.end(), boost::begin(magic), boost::end(magic));
+
     // then the 0x0004 bytes, also a mystery
-    swapped = SOL_BLOCK_MARK;
-    swapped = htons(swapped);
-    ptr = reinterpret_cast<boost::uint8_t *>(&swapped);
-    for (i=0; i<sizeof(boost::uint16_t); i++) {
-        _header.push_back(ptr[i]);
-    }
+    appendSwapped(_header, SOL_BLOCK_MARK);
     // finally a bunch of zeros to pad things for this field
-    for (i=0; i<sizeof(boost::uint32_t); i++) {
-        _header.push_back('\0');
-    }
+    _header.insert(_header.end(), '\0', sizeof(boost::uint32_t));
 
     // Encode the name. This is not a string object, which has a type field
     // one byte field precedding the length as a file type of AMF::STRING.
     //  First the length in two bytes
-    swapped = name.size();
-    swapped = htons(swapped);
-    ptr = reinterpret_cast<boost::uint8_t *>(&swapped);
-    for (i=0; i<sizeof(boost::uint16_t); i++) {
-        _header.push_back(ptr[i]);
-    }
+    boost::uint16_t size = name.size();
+    appendSwapped(_header, size);
+
     // then the string itself
-    ptr = (boost::uint8_t *)name.c_str();
-    for (i=0; i<name.size(); i++) {
-        _header.push_back(ptr[i]);
-    }
+    _header.insert(_header.end(), name.begin(), name.end());
     
     // finally a bunch of zeros to pad things at the end of the header
-    for (i=0; i<sizeof(boost::uint32_t); i++) {
-        _header.push_back('\0');
-    }
+    _header.insert(_header.end(), '\0', sizeof(boost::uint32_t));
 
 #if 0
     unsigned char *hexint;

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

Summary of changes:
 cygnal/libamf/sol.cpp    |   64 ++++++++++++----------------------
 libbase/GnashScopedPtr.h |   85 ++++++++++++++++++++++++++++++++++++++++++++++
 libbase/Socket.cpp       |   44 +++++++++++++++---------
 3 files changed, 136 insertions(+), 57 deletions(-)
 create mode 100644 libbase/GnashScopedPtr.h


hooks/post-receive
-- 
Gnash



reply via email to

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