[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r9628: Minor cleanups only.
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r9628: Minor cleanups only. |
Date: |
Wed, 20 Aug 2008 15:56:50 +0200 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 9628
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Wed 2008-08-20 15:56:50 +0200
message:
Minor cleanups only.
modified:
libbase/GnashImagePng.cpp
libcore/LoadVariablesThread.cpp
libcore/asobj/SharedObject.cpp
libcore/fill_style.cpp
------------------------------------------------------------
revno: 9624.1.3
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Tue 2008-08-19 16:38:42 +0200
message:
Fix g++4.3 warnings (again).
modified:
libbase/GnashImagePng.cpp
------------------------------------------------------------
revno: 9624.1.4
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Tue 2008-08-19 16:39:16 +0200
message:
Use LOG_ONCE.
modified:
libcore/fill_style.cpp
------------------------------------------------------------
revno: 9624.1.5
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Tue 2008-08-19 16:39:32 +0200
message:
Use scoped_array for exception safety.
modified:
libcore/LoadVariablesThread.cpp
------------------------------------------------------------
revno: 9624.1.6
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Tue 2008-08-19 17:42:34 +0200
message:
Use a switch statement rather than if / else for SharedObject. Use the
std::string(const char*, length) constructor for added safety.
Add comments for future implementation.
modified:
libcore/asobj/SharedObject.cpp
=== modified file 'libbase/GnashImagePng.cpp'
--- a/libbase/GnashImagePng.cpp 2008-08-19 08:53:47 +0000
+++ b/libbase/GnashImagePng.cpp 2008-08-19 14:38:42 +0000
@@ -208,8 +208,8 @@
const size_t components = getComponents();
// We must have 3 or 4-channel data by this point.
- assert(_type == GNASH_IMAGE_RGB && components == 3 ||
- _type == GNASH_IMAGE_RGBA && components == 4);
+ assert((_type == GNASH_IMAGE_RGB && components == 3) ||
+ (_type == GNASH_IMAGE_RGBA && components == 4));
// Allocate space for the data
_pixelData.reset(new png_byte[width * height * components]);
=== modified file 'libcore/LoadVariablesThread.cpp'
--- a/libcore/LoadVariablesThread.cpp 2008-06-09 18:08:25 +0000
+++ b/libcore/LoadVariablesThread.cpp 2008-08-19 14:39:32 +0000
@@ -27,6 +27,7 @@
#include "utf8.h"
#include <string>
+#include <boost/scoped_array.hpp>
//#define DEBUG_LOAD_VARIABLES 1
@@ -39,7 +40,6 @@
log_debug("completeLoad called");
#endif
- using std::string;
// TODO: how to set _bytesTotal ?
@@ -48,57 +48,62 @@
_bytesLoaded = 0;
_bytesTotal = _stream->size();
- string toparse;
+ std::string toparse;
- size_t CHUNK_SIZE = 1024;
- char* buf = new char[CHUNK_SIZE];
+ const size_t chunkSize = 1024;
+ boost::scoped_array<char> buf(new char[chunkSize]);
unsigned int parsedLines = 0;
// TODO: use read_string ?
- while ( size_t read = _stream->read(buf, CHUNK_SIZE) )
+ while ( size_t bytesRead = _stream->read(buf.get(), chunkSize) )
{
#ifdef DEBUG_LOAD_VARIABLES
- log_debug("Read %u bytes", read);
+ log_debug("Read %u bytes", bytesRead);
#endif
if ( _bytesLoaded )
{
- string chunk(buf, read);
+ std::string chunk(buf.get(), bytesRead);
toparse += chunk;
}
else
{
- size_t dataSize = read;
+ size_t dataSize = bytesRead;
utf8::TextEncoding encoding;
- char* ptr = utf8::stripBOM(buf, dataSize, encoding);
- if ( encoding != utf8::encUTF8 && encoding !=
utf8::encUNSPECIFIED )
+ char* ptr = utf8::stripBOM(buf.get(), dataSize,
+ encoding);
+ if ( encoding != utf8::encUTF8 &&
+ encoding != utf8::encUNSPECIFIED )
{
- log_unimpl("%s to utf8 conversion in
MovieClip.loadVariables input parsing", utf8::textEncodingName(encoding));
+ log_unimpl("%s to utf8 conversion in "
+ "MovieClip.loadVariables "
+ "input parsing",
+ utf8::textEncodingName(encoding));
}
- string chunk(ptr, dataSize);
+ std::string chunk(ptr, dataSize);
toparse += chunk;
}
#ifdef DEBUG_LOAD_VARIABLES
- log_debug("toparse: %s", toparse.c_str());
+ log_debug("toparse: %s", toparse);
#endif
// parse remainder
size_t lastamp = toparse.rfind('&');
- if ( lastamp != string::npos )
+ if ( lastamp != std::string::npos )
{
- string parseable = toparse.substr(0, lastamp);
+ std::string parseable = toparse.substr(0, lastamp);
#ifdef DEBUG_LOAD_VARIABLES
- log_debug("parseable: %s", parseable.c_str());
+ log_debug("parseable: %s", parseable);
#endif
parse(parseable);
toparse = toparse.substr(lastamp+1);
#ifdef DEBUG_LOAD_VARIABLES
- log_debug("toparse nextline: %s", toparse.c_str());
+ log_debug("toparse nextline: %s", toparse);
#endif
++parsedLines;
}
- _bytesLoaded += read;
+ _bytesLoaded += bytesRead;
//dispatchDataEvent();
// eof, get out !
@@ -127,7 +132,6 @@
}
//dispatchLoadEvent();
- delete[] buf;
setCompleted();
}
=== modified file 'libcore/asobj/SharedObject.cpp'
--- a/libcore/asobj/SharedObject.cpp 2008-06-17 12:49:48 +0000
+++ b/libcore/asobj/SharedObject.cpp 2008-08-19 15:42:34 +0000
@@ -45,8 +45,6 @@
#include "URL.h"
#include "rc.h" // for use of rcfile
-using std::string;
-
namespace {
gnash::LogFile& dbglogfile = gnash::LogFile::getDefaultInstance();
gnash::RcInitFile& rcfile = gnash::RcInitFile::getDefaultInstance();
@@ -84,12 +82,12 @@
AMF amf;
Element *el = 0;
- const string& name = _st.string_table::value(key);
+ const std::string& name = _st.string_table::value(key);
// cerr << "FIXME: yes!!!!! " << name << ": "<< val << std::endl;
if (val.is_string()) {
- string str;
+ std::string str;
if (!val.is_undefined()) {
str = val.to_string();
}
@@ -221,7 +219,7 @@
PropsSerializer props(sol, vm);
ptr->visitPropertyValues(props);
// We only want to access files in this directory
- string newspec;
+ std::string newspec;
newspec += obj->getFilespec();
bool ret = sol.writeFile(newspec, obj->getObjectName().c_str());
if ( ! ret )
@@ -260,26 +258,26 @@
obj->getVM().addStatic(obj.get());
}
- string::size_type pos;
- string rootdir;
+ std::string::size_type pos;
+ std::string rootdir;
if (fn.nargs > 0) {
- string filespec = fn.arg(0).to_string();
+ std::string filespec = fn.arg(0).to_string();
// If there is a second argument to getLocal(), it replaces
// the default path, which is the swf file name, with this
// supplied path.
// the object name appears to be the same as the file name, but
// minus the suffix.
- if ((pos = filespec.find(".sol", 0) == string::npos)) {
+ if ((pos = filespec.find(".sol", 0) == std::string::npos)) {
obj->setObjectName(filespec);
filespec += ".sol";
} else {
- string objname = filespec.substr(0, filespec.size() - 4);
+ std::string objname = filespec.substr(0, filespec.size() - 4);
obj->setObjectName(objname);
}
obj->setFilespec(filespec);
}
- string newspec = rcfile.getSOLSafeDir();
+ std::string newspec = rcfile.getSOLSafeDir();
if (newspec.size() == 0) {
newspec = "/tmp/";
}
@@ -310,7 +308,7 @@
// by the 'base' attribute of OBJECT or EMBED tags trough
// -P base=xxx
//
- const string& origURL = obj->getVM().getSWFUrl();
+ const std::string& origURL = obj->getVM().getSWFUrl();
URL url(origURL);
// log_debug(_("BASE URL=%s (%s)"), url.str(), url.hostname());
@@ -318,11 +316,11 @@
// Get the domain part, or take as 'localhost' if none
// (loaded from filesystem)
//
- string domain=url.hostname();
+ std::string domain = url.hostname();
if (domain.empty()) domain = "localhost";
// Get the path part
- string swfile = url.path();
+ std::string swfile = url.path();
// TODO: if the original url was a relative one, the pp uses just
// the relative portion rather then the resolved absolute path !
@@ -354,16 +352,16 @@
newspec += obj->getFilespec();
obj->setFilespec(newspec);
- if (newspec.find("/", 0) != string::npos) {
+ if (newspec.find("/", 0) != std::string::npos) {
typedef boost::tokenizer<boost::char_separator<char> > Tok;
boost::char_separator<char> sep("/");
Tok t(newspec, sep);
Tok::iterator tit;
- string newdir = "/";
+ std::string newdir = "/";
for(tit=t.begin(); tit!=t.end();++tit){
//cout << *tit << "\n";
newdir += *tit;
- if (newdir.find("..", 0) != string::npos) {
+ if (newdir.find("..", 0) != std::string::npos) {
log_error("Invalid SharedObject path (contains '..'): %s",
newspec);
return as_value(false);
}
@@ -403,31 +401,45 @@
boost::intrusive_ptr<as_object> ptr = as.to_object();
for (it = els.begin(), e = els.end(); it != e; it++) {
- Element *el = (*(it));
-// log_debug("Adding \"%s\"", el->name);
- if (el->getType() == Element::NUMBER_AMF0) {
- double dub = *((double *)el->getData());
- ptr->set_member(st.string_table::find(el->getName()),
as_value(dub));
- }
- if (el->getType() == Element::BOOLEAN_AMF0) {
- if (el->to_bool() == true) {
- ptr->set_member(st.string_table::find(el->getName()),
as_value(true));
- } else {
- ptr->set_member(st.string_table::find(el->getName()),
as_value(false));
- }
- }
- if (el->getType() == Element::STRING_AMF0) {
- if (el->getLength() == 0) {
- ptr->set_member(st.string_table::find(el->getName()),
as_value(""));
- } else {
- string str = (const char *)el->getData();
+ Element *el = *it;
+
+ switch (el->getType())
+ {
+ case Element::NUMBER_AMF0:
+ {
+ double dub = *(reinterpret_cast<double*>(el->getData()));
+ ptr->set_member(st.string_table::find(el->getName()),
as_value(dub));
+ break;
+ }
+
+ case Element::BOOLEAN_AMF0:
+ ptr->set_member(st.string_table::find(el->getName()),
+ as_value(el->to_bool()));
+ break;
+
+ case Element::STRING_AMF0:
+ {
+ if (el->getLength() == 0) {
+ ptr->set_member(st.string_table::find(el->getName()),
as_value(""));
+ break;
+ }
+
+ std::string str(reinterpret_cast<const char*>(el->getData()),
el->getLength());
ptr->set_member(st.string_table::find(el->getName()),
as_value(str));
+ break;
}
- }
- if (el->getType() == Element::OBJECT_AMF0) {
-// data.convert_to_object();
-// ptr->set_member(st.string_table::find(el->name), data);
- }
+
+ case Element::OBJECT_AMF0:
+ // TODO: implement!
+ //data.convert_to_object();
+ //ptr->set_member(st.string_table::find(el->name), data);
+ break;
+
+ default:
+ // TODO: what about other types?
+ break;
+ }
+
}
// ptr->dump_members(); // FIXME: debug crap
=== modified file 'libcore/fill_style.cpp'
--- a/libcore/fill_style.cpp 2008-08-18 23:53:04 +0000
+++ b/libcore/fill_style.cpp 2008-08-19 14:39:16 +0000
@@ -370,16 +370,14 @@
if (ratio < m_gradients[0].m_ratio)
{
IF_VERBOSE_MALFORMED_SWF(
- static bool warned=false;
- if ( ! warned ) {
- log_swferror(
- _("First gradient in a fill_style "
- "have position==%d (expected 0)."
- " This seems to be common, so will"
- " warn only once."),
- (int)m_gradients[0].m_ratio);
- warned=true;
- }
+ LOG_ONCE(
+ log_swferror(
+ _("First gradient in a fill_style "
+ "have position==%d (expected 0)."
+ " This seems to be common, so will"
+ " warn only once."),
+ (int)m_gradients[0].m_ratio)
+ );
);
return m_gradients[0].m_color;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r9628: Minor cleanups only.,
Benjamin Wolsey <=