gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog server/parser/action_buffer.cpp...


From: Benjamin Wolsey
Subject: [Gnash-commit] gnash ChangeLog server/parser/action_buffer.cpp...
Date: Wed, 05 Mar 2008 11:54:34 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Benjamin Wolsey <bwy>   08/03/05 11:54:33

Modified files:
        .              : ChangeLog 
        server/parser  : action_buffer.cpp 
        server/vm      : ASHandlers.cpp 
        utilities      : dumpshm.cpp processor.cpp 
        libbase        : log.cpp log.h 
        libamf         : element.cpp sol.cpp 

Log message:
                * libbase/log.{h,cpp}: add templates to convert from vsnprintf 
format
                  logging calls to boost::format. These are generated with 
                  boost.preprocessor macros. The templates 'redirect' log_* 
calls
                  to logProcess_* functions. These can also be used directly.
                  Switching between the two is possible by changing the #define
                  USE_BOOST_FORMAT in log.h. It is enabled by default. Make 
static
                  members private, as they aren't needed elsewhere. Make 
hexify()
                  return a std::string and look much less scary.
                * libamf/element.cpp, libamf/sol.cpp: use std::string hexify.
                * server/parser/action_buffer.cpp: use std::string hexify.
                * server/vm/ASHandlers.cpp: use C++ standard header <locale>
                * utilities/dumpshm.cpp: use <locale>, change hexify.
                * utilities/processor.cpp: use <locale>.
        
        Logging when boost::format enabled is type-safe. Size_t is always fine 
and C++ strings are acceptable. Format 'mistakes' that would be rejected by 
printf are accepted. However, this will break the build for anyone using the 
old printf format or if it's decided to return to that style. There is no 
compiler warning when using the wrong number of arguments; extra ones will 
simply not be displayed.
        
        It is possible to use logProcess_* directly with boost::format style 
(see http://www.boost.org/libs/format/doc/format.html), 'feeding' it using the 
% operator.
        
        Please see http://wiki.gnashdev.org/wiki/index.php/Logging for more 
info.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5809&r2=1.5810
http://cvs.savannah.gnu.org/viewcvs/gnash/server/parser/action_buffer.cpp?cvsroot=gnash&r1=1.36&r2=1.37
http://cvs.savannah.gnu.org/viewcvs/gnash/server/vm/ASHandlers.cpp?cvsroot=gnash&r1=1.202&r2=1.203
http://cvs.savannah.gnu.org/viewcvs/gnash/utilities/dumpshm.cpp?cvsroot=gnash&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/gnash/utilities/processor.cpp?cvsroot=gnash&r1=1.86&r2=1.87
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/log.cpp?cvsroot=gnash&r1=1.65&r2=1.66
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/log.h?cvsroot=gnash&r1=1.68&r2=1.69
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/element.cpp?cvsroot=gnash&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/sol.cpp?cvsroot=gnash&r1=1.23&r2=1.24

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.5809
retrieving revision 1.5810
diff -u -b -r1.5809 -r1.5810
--- ChangeLog   5 Mar 2008 11:42:35 -0000       1.5809
+++ ChangeLog   5 Mar 2008 11:54:32 -0000       1.5810
@@ -1,3 +1,19 @@
+2008-03-04 Benjamin Wolsey <address@hidden>
+
+       * libbase/log.{h,cpp}: add templates to convert from vsnprintf format
+         logging calls to boost::format. These are generated with 
+         boost.preprocessor macros. The templates 'redirect' log_* calls
+         to logProcess_* functions. These can also be used directly.
+         Switching between the two is possible by changing the #define
+         USE_BOOST_FORMAT in log.h. It is enabled by default. Make static
+         members private, as they aren't needed elsewhere. Make hexify()
+         return a std::string and look much less scary.
+       * libamf/element.cpp, libamf/sol.cpp: use std::string hexify.
+       * server/parser/action_buffer.cpp: use std::string hexify.
+       * server/vm/ASHandlers.cpp: use C++ standard header <locale>
+       * utilities/dumpshm.cpp: use <locale>, change hexify.
+       * utilities/processor.cpp: use <locale>.
+
 2008-03-04 Sandro Santilli <address@hidden>
 
        * libbase/GC.{cpp,h}: add a countCollectables() method for stats.

Index: server/parser/action_buffer.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/parser/action_buffer.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -b -r1.36 -r1.37
--- server/parser/action_buffer.cpp     5 Mar 2008 03:56:02 -0000       1.36
+++ server/parser/action_buffer.cpp     5 Mar 2008 11:54:32 -0000       1.37
@@ -239,8 +239,8 @@
        if (fmt == ARG_HEX)
        {
            for (int i = 0; i < length; i++) {
-               hexify(num, (const unsigned char *)&instruction_data[3 + i], 1, 
false);
-               ss << "0x" << num << " ";
+
+               ss << "0x" << hexify((boost::uint8_t *)&instruction_data[3 + 
i], 1, false) << " ";
            }
        }
        else if (fmt == ARG_STR)

Index: server/vm/ASHandlers.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/vm/ASHandlers.cpp,v
retrieving revision 1.202
retrieving revision 1.203
diff -u -b -r1.202 -r1.203
--- server/vm/ASHandlers.cpp    5 Mar 2008 03:56:04 -0000       1.202
+++ server/vm/ASHandlers.cpp    5 Mar 2008 11:54:32 -0000       1.203
@@ -50,13 +50,13 @@
 #include "namedStrings.h"
 #include "utf8.h"
 
-#include <unistd.h>
+#include <unistd.h>  // For write() on BSD
 #include <string>
 #include <map>
 #include <set>
 #include <vector>
 #include <utility> // for std::pair
-#include <locale.h>
+#include <locale>
 #include <cerrno>
 #include <boost/scoped_array.hpp>
 #include <boost/random.hpp>

Index: utilities/dumpshm.cpp
===================================================================
RCS file: /sources/gnash/gnash/utilities/dumpshm.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- utilities/dumpshm.cpp       3 Mar 2008 16:52:29 -0000       1.27
+++ utilities/dumpshm.cpp       5 Mar 2008 11:54:33 -0000       1.28
@@ -60,7 +60,7 @@
 #include <cerrno>
 
 #ifdef ENABLE_NLS
-#include <locale.h>
+#include <locale>
 #endif
 
 #include "log.h"
@@ -250,10 +250,7 @@
        write(fd, shmaddr, size);
        if (out) {
 #if 0
-           boost::uint8_t *hexint;
-           hexint = new boost::uint8_t[(size + 3) *3];
-           hexify((boost::uint8_t *)hexint, (uint8_t *)shmaddr, size, false);
-           log_debug(_("The data is: 0x%s"), hexint);
+           log_debug(_("The data is: 0x%s"), hexify((uint8_t *)shmaddr, size, 
false));
 #endif
        }
        

Index: utilities/processor.cpp
===================================================================
RCS file: /sources/gnash/gnash/utilities/processor.cpp,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -b -r1.86 -r1.87
--- utilities/processor.cpp     5 Mar 2008 03:56:07 -0000       1.86
+++ utilities/processor.cpp     5 Mar 2008 11:54:33 -0000       1.87
@@ -27,7 +27,7 @@
 #include <time.h>
 
 #ifdef ENABLE_NLS
-#include <locale.h>
+#include <locale>
 #endif
 
 #include "gettext.h"

Index: libbase/log.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/log.cpp,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -b -r1.65 -r1.66
--- libbase/log.cpp     5 Mar 2008 03:55:53 -0000       1.65
+++ libbase/log.cpp     5 Mar 2008 11:54:33 -0000       1.66
@@ -17,18 +17,23 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-
 #ifdef HAVE_CONFIG_H
 #include "gnashconfig.h"
 #endif
 
-#include <cstdio>
-#include <cstdarg>
+#ifndef USE_BOOST_FORMAT_TEMPLATES
+# include <cstdio>  
+# include <cstdarg> // Both for vsnprintf
+#endif
+
+#include <ctime>
+
 #include <iostream>
+#include <sstream>
+#include <iomanip>
 #include <fstream>
 #include <string>
-#include <cstring>
-//#include <boost/format.hpp>
+#include <boost/format.hpp>
 
 #if defined(_WIN32) && defined(WIN32)
 // Required for SYSTEMTIME definitions
@@ -39,8 +44,6 @@
 # include <unistd.h>
 #endif
 
-#include <ctime>
-
 #include "log.h"
 
 using std::cout;
@@ -48,85 +51,45 @@
 
 namespace gnash {
 
-// static data to be shared amongst all classes.
-//ofstream LogFile::_console;
-int LogFile::_verbose = 0;
-bool LogFile::_actiondump = false;
-bool LogFile::_parserdump = false;
-
 // Workspace for vsnprintf formatting.
 static const int BUFFER_SIZE = 2048;
 
-// Convert each byte into it's hex represntation
-static const char hexchars[]="0123456789abcdef";
-unsigned char *
-hexify(unsigned char *p, const unsigned char *s, int length, bool ascii) {
-
-    unsigned char *p1 = p;
-
-    // convert some characters so it'll look right in the log
-    for (int i=0 ; i<length; i++) {
-        // use the hex value
+// Convert each byte into its hex representation
+std::string hexify (const unsigned char *p, size_t length, bool ascii)
+{
+
+       assert (length <= sizeof(p));
+
+       const std::vector<unsigned char> bytes (p, p + length);
 
+       std::ostringstream ss;
+       
+       // For hex output, fill single-digit numbers with a leading 0.
+       if (!ascii) ss << std::hex << std::setfill('0');
+       
+       for (std::vector<unsigned char>::const_iterator i = bytes.begin(), e = 
bytes.end();
+                               i != e; ++i)
+       {
        if (ascii) {
-           if (isprint(s[i])) {
-               *p++ = s[i];
-               continue;
-           } else {
-               if ((s[i] == 0xd) || (s[i] == 0xa)) {
-                   *p++ = s[i];
-                   continue;
-               }
-               *p++ = '^';
-           }
-       } else {                // if not ascii outout requested
-           *p++ = hexchars[s[i] >> 4];
-           *p++ = hexchars[s[i] & 0xf];
-           *p++ = ' ';         // add a space between bytes
-       }
-           
-//     if (isascii(s[i]) && ascii) {
-//         *p++ = hexchars[s[i] >> 4];
-//         *p++ = hexchars[s[i] & 0xf];
-// //              *p++ = ' ';
-//         *p++ = '%';
-//         continue;
-//     }
-//     *p++ = s[i];
-// //      if (!isprint(s[i+1])) {
-// //          *p++ = hexchars[s[i] >> 4];
-// //          *p++ = hexchars[s[i] & 0xf];
-// // //               *p++ = ' ';
-// //          *p++ = '$';
-// //      }
-
-//     } else {
-//         if (ascii) {
-//             if (s[i] == 0xd) {
-// //              *p++ = '\r';
-//                 *p++ = '@';
-//                 continue;
-//             }
-//             if (s[i] == 0xa) {              
-// //              *p++ = '\n';
-//                 *p++ = '#';
-//                 continue;
-//             }
-//         } else {
-//             *p++ = hexchars[s[i] >> 4];
-//             *p++ = hexchars[s[i] & 0xf];
-//         }
-//     }
+                       if (isprint(*i) || *i == 0xd || *i == 0xa) {
+                               ss << *i;
+                       }
+                       else ss << "^";
+               }
+               else  {
+                       // Not ascii
+                       ss << std::setw(2) << static_cast<int>(*i) << " ";      
+               }
     }
 
-    *p = '\0';
+       return ss.str();
 
-    return p1;
 }
 
 // FIXME: localize these, so they print local regional timestamps.
 std::ostream&
-timestamp(std::ostream& x) {
+timestamp(std::ostream& x)
+{
     time_t t;
     char buf[10];
 
@@ -181,6 +144,8 @@
     LogFile& dbglogfile = LogFile::getDefaultInstance();
 }
 
+#ifndef USE_BOOST_FORMAT_TEMPLATES
+
 void
 log_trace(const char* fmt, ...)
 {
@@ -197,12 +162,6 @@
     va_end (ap);
 }
 
-//void
-//logTrace(const boost::format& fmt)
-//{
-//    dbglogfile.log(N_("TRACE"), fmt.str());
-//}
-
 void
 log_debug(const char* fmt, ...)
 {
@@ -226,13 +185,6 @@
     va_end (ap);
 }
 
-//void
-//logDebug(const boost::format& fmt)
-//{
-//    if (dbglogfile.getVerbosity() < DEBUGLEVEL) return;
-//    dbglogfile.log(N_("DEBUG"), fmt.str());
-//}
-
 void
 log_action(const char* fmt, ...)
 {
@@ -249,15 +201,6 @@
     dbglogfile.setStamp(stamp);
 }
 
-//void
-//logAction(const boost::format& fmt)
-//{
-//    bool stamp = dbglogfile.getStamp();
-//    dbglogfile.setStamp(false);
-//    dbglogfile.log(fmt.str());
-//    dbglogfile.setStamp(stamp);
-//}
-
 void
 log_parse(const char* fmt, ...)
 {
@@ -274,12 +217,6 @@
     va_end (ap);
 }
 
-//void
-//logParse(const boost::format& fmt)
-//{
-//    dbglogfile.log(fmt.str());
-//}
-
 // Printf-style error log.
 void
 log_error(const char* fmt, ...)
@@ -296,12 +233,6 @@
     va_end (ap);
 }
 
-//void
-//logError(const boost::format& fmt)
-//{
-//    dbglogfile.log(N_("ERROR"), fmt.str());
-//}
-
 void
 log_unimpl(const char* fmt, ...)
 {
@@ -317,12 +248,6 @@
     va_end (ap);
 }
 
-//void
-//logUnimpl(const boost::format& fmt)
-//{
-//    dbglogfile.log(N_("UNIMPLEMENTED"), fmt.str());
-//}
-
 void
 log_security(const char* fmt, ...)
 {
@@ -338,12 +263,6 @@
     va_end (ap);
 }
 
-//void
-//logSecurity(const boost::format& fmt)
-//{
-//    dbglogfile.log(N_("SECURITY"), fmt.str());
-//}
-
 void
 log_swferror(const char* fmt, ...)
 {
@@ -359,12 +278,6 @@
     va_end (ap);
 }
 
-//void
-//logSWFError(const boost::format& fmt)
-//{
-//    dbglogfile.log(N_("MALFORMED SWF"), fmt.str());
-//}
-
 void
 log_aserror(const char* fmt, ...)
 {
@@ -380,11 +293,69 @@
     va_end (ap);
 }
 
-//void
-//logASError(const boost::format& fmt)
-//{
-//    dbglogfile.log(N_("ACTIONSCRIPT ERROR"), fmt.str());
-//}
+#else
+// boost format functions to process the objects
+// created by our hundreds of templates 
+
+void
+processLog_trace(const boost::format& fmt)
+{
+       dbglogfile.log(N_("TRACE"), fmt.str());
+}
+
+void
+processLog_debug(const boost::format& fmt)
+{
+       if (dbglogfile.getVerbosity() < DEBUGLEVEL) return;
+       dbglogfile.log(N_("DEBUG"), fmt.str());
+}
+
+void
+processLog_parse(const boost::format& fmt)
+{
+       dbglogfile.log(fmt.str());
+}
+
+void
+processLog_error(const boost::format& fmt)
+{
+       dbglogfile.log(N_("ERROR"), fmt.str());
+}
+
+void
+processLog_unimpl(const boost::format& fmt)
+{
+       dbglogfile.log(N_("UNIMPLEMENTED"), fmt.str());
+}
+
+void
+processLog_security(const boost::format& fmt)
+{
+       dbglogfile.log(N_("SECURITY"), fmt.str());
+}
+
+void
+processLog_swferror(const boost::format& fmt)
+{
+       dbglogfile.log(N_("MALFORMED SWF"), fmt.str());
+}
+
+void
+processLog_aserror(const boost::format& fmt)
+{
+       dbglogfile.log(N_("ACTIONSCRIPT ERROR"), fmt.str());
+}
+
+void
+processLog_action(const boost::format& fmt)
+{
+       bool stamp = dbglogfile.getStamp();
+       dbglogfile.setStamp(false);
+       dbglogfile.log(fmt.str());
+       dbglogfile.setStamp(stamp);
+}
+
+#endif
 
 void
 LogFile::log(const std::string& msg)
@@ -392,7 +363,6 @@
     boost::mutex::scoped_lock lock(_ioMutex);
 
     dbglogfile << msg << endl;
-
 }
 
 void
@@ -407,13 +377,15 @@
 // Default constructor
 LogFile::LogFile ()
        :
+       _verbose(0),
+       _actiondump(false),
+       _parserdump(false),
        _state(CLOSED),
        _stamp(true),
        _write(false)
 {
     RcInitFile& rcfile = RcInitFile::getDefaultInstance();
     _write = rcfile.useWriteLog();
-
 }
 
 LogFile::~LogFile()
@@ -440,6 +412,7 @@
 bool
 LogFile::openLog (const std::string& filespec)
 {
+
     // NOTE:
     // don't need to lock the mutex here, as this method
     // is intended to be called only by openLogIfNeeded,
@@ -495,10 +468,7 @@
     return true;
 }
 
-/// \brief print a string
-///
-
-
+/// log a string
 LogFile&
 LogFile::operator << (const std::string &s)
 {
@@ -522,7 +492,6 @@
                _outstream << s;   
        }
     }
-
     return *this;
 }
 
@@ -544,6 +513,28 @@
     return *this;
 }
 
+boost::format
+logFormat (const std::string &str)
+{
+
+       using namespace boost::io;
+
+       boost::format fmt(str);
+       
+       // Don't throw exception if the wrong number of 
+       // arguments is passed or the format string is 
+       // bad. This might lead to strings being mangled,
+       // but the alternative is that a careless format
+       // string would cause Gnash to abort; and some
+       // strings don't appear very often. The same holds
+       // for translations.
+       fmt.exceptions(all_error_bits ^ (
+                                                       too_many_args_bit |
+                                                       too_few_args_bit |
+                                                       bad_format_string_bit));
+       return fmt;
+}
+
 } // end of gnash namespace
 
 

Index: libbase/log.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/log.h,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -b -r1.68 -r1.69
--- libbase/log.h       22 Feb 2008 11:24:37 -0000      1.68
+++ libbase/log.h       5 Mar 2008 11:54:33 -0000       1.69
@@ -26,24 +26,43 @@
 # include <io.h>
 #endif
 
-// Support compilation with (or without) native language support
-#include "gettext.h"   // for internationalization (GNU gettext)
-#define        _(String) gettext (String)
-#define N_(String) gettext_noop (String)
-
 #include "rc.h" // for IF_VERBOSE_* implementation
 
 #include <fstream>
 #include <sstream>
 #include <boost/thread/thread.hpp>
 #include <boost/thread/mutex.hpp>
-//#include <boost/format.hpp>
+#include <boost/format.hpp>
 
 // the default name for the debug log
 #define DEFAULT_LOGFILE "gnash-dbg.log"
 #define TIMESTAMP_LENGTH 24             // timestamp length
 #define TIMESTAMP_FORMAT "%Y-%m-%d %H:%M:%S     " // timestamp format
 
+// Support compilation with (or without) native language support
+#include "gettext.h"
+#define        _(String) gettext (String)
+#define N_(String) gettext_noop (String)
+
+// This macro should be used to add both boost formatting and
+// internationalization to log messages. The po directory
+// Makefile must also look for the BF macro for gettext
+// processing, otherwise they will not appear in the
+// translation (.po) files.
+//#define BF(x) logFormat(_(x))
+
+// Define to switch between printf-style log formatting
+// and boost::format
+#define USE_BOOST_FORMAT_TEMPLATES 1
+
+#ifdef USE_BOOST_FORMAT_TEMPLATES
+# include <boost/preprocessor/arithmetic/inc.hpp>
+# include <boost/preprocessor/repetition/enum_params.hpp>
+# include <boost/preprocessor/repetition/repeat.hpp>
+# include <boost/preprocessor/repetition/repeat_from_to.hpp>
+# include <boost/preprocessor/seq/for_each.hpp>
+#endif
+
 namespace gnash {
 
 extern std::ostream& stampon(std::ostream& x);
@@ -60,7 +79,7 @@
 
     ~LogFile();
 
-    enum fileState {
+    enum FileState {
         CLOSED,
         OPEN,
         INPROGRESS,
@@ -173,16 +192,16 @@
     std::ofstream       _outstream;
 
     /// How much output is required: 2 or more gives debug output.
-    static int          _verbose;
+    int                 _verbose;
 
     /// Whether to dump all SWF actions
-    static bool                 _actiondump;
+    bool                _actiondump;
 
     /// Whether to dump parser output
-    static bool                 _parserdump;
+    bool                _parserdump;
 
     /// The state of the log file.
-    fileState _state;
+    FileState _state;
 
     bool                _stamp;
 
@@ -214,7 +233,87 @@
 };
 
 
-DSOEXPORT unsigned char *hexify(unsigned char *p, const unsigned char *s, int 
length, bool ascii);
+#ifdef USE_BOOST_FORMAT_TEMPLATES
+/// This heap of steaming preprocessor code magically converts
+/// printf-style statements into boost::format messages using templates.
+//
+/// Macro to feed boost::format strings to the boost::format object,
+/// producing code like this: "% t1 % t2 % t3 ..."
+#define TOKENIZE_FORMAT(z, n, t) % t##n
+
+/// Macro to add a number of arguments to the templated function
+/// corresponding to the number of template arguments. Produces code
+/// like this: "const T0& t0, const T1& t1, const T2& t2 ..."
+#define TOKENIZE_ARGS(z, n, t) BOOST_PP_COMMA_IF(n) const T##n& t##n
+
+/// This is a sequence of different log message types to be used in
+/// the code. Append the name to log_ to call the function, e.g. 
+/// log_error, log_unimpl.
+#define LOG_TYPES (error) (debug) (unimpl) (aserror) (swferror) (security) 
(action) (parse) (trace)
+
+/// This actually creates the template functions using the TOKENIZE
+/// functions above. The templates look like this:
+//
+/// template< typename T0 , typename T1 , typename T2 , typename T3 > 
+/// void
+/// log_security (const T0& t0, const T1& t1, const T2& t2, const T3& t3)
+/// {
+///     if (_verbosity == 0) return;
+///     processLog_security(myFormat(t0) % t1 % t2 % t3);
+/// }
+//
+/// Only not as nicely indented.
+///
+/// Use "g++ -E log.h" or "gcc log.h" to check.
+#define LOG_TEMPLATES(z, n, data)\
+    template< \
+         BOOST_PP_ENUM_PARAMS(\
+         BOOST_PP_INC(n), typename T)\
+     >\
+    DSOEXPORT void log_##data (\
+        BOOST_PP_REPEAT(\
+        BOOST_PP_INC(n), \
+        TOKENIZE_ARGS, t)\
+    ) { \
+    if (LogFile::getDefaultInstance().getVerbosity() == 0) return; \
+    processLog_##data(logFormat(t0) \
+    BOOST_PP_REPEAT_FROM_TO(1, \
+        BOOST_PP_INC(n), \
+        TOKENIZE_FORMAT, t));\
+    }\
+
+/// Defines the maximum number of template arguments
+//
+/// The preprocessor generates templates with 1..ARG_NUMBER
+/// arguments.
+#define ARG_NUMBER 16
+
+/// Calls the macro LOG_TEMPLATES an ARG_NUMBER number
+/// of times, each time adding an extra typename argument to the
+/// template.
+#define GENERATE_LOG_TYPES(r, _, t) \
+    BOOST_PP_REPEAT(ARG_NUMBER, LOG_TEMPLATES, t)
+
+/// Calls the template generator for each log type in the
+/// sequence LOG_TYPES.
+BOOST_PP_SEQ_FOR_EACH(GENERATE_LOG_TYPES, _, LOG_TYPES)
+
+#undef TOKENIZE_FORMAT
+#undef GENERATE_LOG_TYPES
+#undef LOG_TEMPLATES
+#undef ARG_NUMBER
+
+DSOEXPORT void processLog_error(const boost::format& fmt);
+DSOEXPORT void processLog_unimpl(const boost::format& fmt);
+DSOEXPORT void processLog_trace(const boost::format& fmt);
+DSOEXPORT void processLog_debug(const boost::format& fmt);
+DSOEXPORT void processLog_action(const boost::format& fmt);
+DSOEXPORT void processLog_parse(const boost::format& fmt);
+DSOEXPORT void processLog_security(const boost::format& fmt);
+DSOEXPORT void processLog_swferror(const boost::format& fmt);
+DSOEXPORT void processLog_aserror(const boost::format& fmt);
+
+#else
 
 #ifdef __GNUC__
 #define GNUC_LOG_ATTRS __attribute__((format (printf, 1, 2)))
@@ -230,7 +329,6 @@
 /// or log_swferror for that.
 ///
 DSOEXPORT void log_error(const char* fmt, ...) GNUC_LOG_ATTRS;
-//DSOEXPORT void logError(const boost::format& fmt);
 
 /// Log a message about unimplemented features.
 //
@@ -239,7 +337,6 @@
 /// implement those features of Flash.
 ///
 DSOEXPORT void log_unimpl(const char* fmt, ...) GNUC_LOG_ATTRS;
-//DSOEXPORT void logUnimpl(const boost::format& fmt);
 
 /// Use only for explicit user traces
 //
@@ -247,14 +344,12 @@
 /// ASHandlers.cpp for ActionTrace
 ///
 DSOEXPORT void log_trace(const char* fmt, ...) GNUC_LOG_ATTRS;
-//DSOEXPORT void logTrace(const boost::format& fmt);
 
 /// Log debug info
 //
 /// Used for function entry/exit tracing.
 ///
 DSOEXPORT void log_debug(const char* fmt, ...) GNUC_LOG_ATTRS;
-//DSOEXPORT void logDebug(const boost::format& fmt);
 
 /// Log action execution info
 //
@@ -264,7 +359,6 @@
 /// at runtime.
 ///
 DSOEXPORT void log_action(const char* fmt, ...) GNUC_LOG_ATTRS;
-//DSOEXPORT void logAction(const boost::format& fmt);
 
 /// Log parsing information
 //
@@ -274,11 +368,9 @@
 /// at runtime.
 ///
 DSOEXPORT void log_parse(const char* fmt, ...) GNUC_LOG_ATTRS;
-//DSOEXPORT void logParse(const boost::format& fmt);
 
 /// Log security information
 DSOEXPORT void log_security(const char* fmt, ...) GNUC_LOG_ATTRS;
-//DSOEXPORT void logSecurity(const boost::format& fmt);
 
 /// Log a malformed SWF error
 //
@@ -291,7 +383,6 @@
 /// at runtime.
 ///
 DSOEXPORT void log_swferror(const char* fmt, ...) GNUC_LOG_ATTRS;
-//DSOEXPORT void logSWFError(const boost::format& fmt);
 
 /// Log an ActionScript error
 //
@@ -304,9 +395,26 @@
 /// at runtime.
 ///
 DSOEXPORT void log_aserror(const char* fmt, ...) GNUC_LOG_ATTRS;
-//DSOEXPORT void logASError(const boost::format& fmt);
 
 
+#endif // USE_BOOST_FORMAT_TEMPLATES
+
+/// A fault-tolerant boost::format object for logging
+//
+/// Generally to be used in the LogFile macro BF(), which will also
+/// be recognized by gettext for internationalization and is less
+/// effort to type.
+DSOEXPORT boost::format logFormat(const std::string &str);
+
+/// Convert a sequence of bytes to hex or ascii format.
+//
+/// @param bytes    the array of bytes to process
+/// @param length   the number of bytes to read. Callers are responsible
+///                 for checking that length does not exceed the array size.
+/// @param ascii    whether to return in ascii or space-separated hex format.
+/// @return         a string representation of the byte sequence.
+DSOEXPORT std::string hexify(const unsigned char *bytes, size_t length, bool 
ascii);
+
 // Define to 0 to completely remove parse debugging at compile-time
 #ifndef VERBOSE_PARSE
 #define VERBOSE_PARSE 1
@@ -375,7 +483,7 @@
     }
 
     ~__Host_Function_Report__(void) {
-       if (LogFile::getDefaultInstance().getVerbosity() >= DEBUGLEVEL+1) {
+       if (LogFile::getDefaultInstance().getVerbosity() >= DEBUGLEVEL + 1) {
            log_debug("returning");
        }
     }

Index: libamf/element.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/element.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- libamf/element.cpp  1 Feb 2008 01:42:41 -0000       1.9
+++ libamf/element.cpp  5 Mar 2008 11:54:33 -0000       1.10
@@ -590,10 +590,7 @@
       case Element::RECORD_SET:
       case Element::XML_OBJECT:
       case Element::TYPED_OBJECT:
-         boost::uint8_t *hexint;
-         hexint = new boost::uint8_t[(_length + 3) * 3];
-         hexify((boost::uint8_t *)hexint, _data, _length, false);
-         cerr << "AMF data is: 0x%s" << hexint << endl;
+         cerr << "AMF data is: 0x%s" << hexify(_data, _length, false) << endl;
          break;
       case Element::VARIABLE:
       case Element::FUNCTION:

Index: libamf/sol.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/sol.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- libamf/sol.cpp      19 Feb 2008 19:20:50 -0000      1.23
+++ libamf/sol.cpp      5 Mar 2008 11:54:33 -0000       1.24
@@ -408,9 +408,8 @@
         if (el->getType() == Element::NUMBER) {
             double ddd = *((double *)el->getData());
              cerr << ddd << " ";
-            hexint = new uint8_t[(sizeof(double) *3) + 3];
-            hexify(hexint, el->getData(), 8, false);
-            cerr << "( " << hexint << ")";
+
+            cerr << "( " << hexify(el->getData(), 8, false) << ")";
         }
         if ((*(it))->getType() == Element::BOOLEAN) {
             if (el[0] == true) {




reply via email to

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