summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon')
-rwxr-xr-xindra/llcommon/llapp.cpp33
-rwxr-xr-xindra/llcommon/stringize.h51
-rwxr-xr-xindra/llcommon/tests/stringize_test.cpp20
3 files changed, 80 insertions, 24 deletions
diff --git a/indra/llcommon/llapp.cpp b/indra/llcommon/llapp.cpp
index b219f66a29..e75e741db8 100755
--- a/indra/llcommon/llapp.cpp
+++ b/indra/llcommon/llapp.cpp
@@ -47,6 +47,7 @@
#include "llstring.h"
#include "lleventtimer.h"
#include "google_breakpad/exception_handler.h"
+#include "stringize.h"
//
// Signal handling
@@ -338,10 +339,7 @@ void LLApp::setupErrorHandling()
{
llwarns << "adding breakpad exception handler" << llendl;
- std::wostringstream ws;
- ws << mCrashReportPipeStr << getPid();
- std::wstring wpipe_name = ws.str();
- std::string ptmp = std::string(wpipe_name.begin(), wpipe_name.end());
+ const std::wstring wpipe_name(wstringize(getPid());
::Sleep(3000); //HACK hopefully a static wait won't blow up in my face before google fixes their implementation.
@@ -349,13 +347,13 @@ void LLApp::setupErrorHandling()
for (int retries=0;retries<5;++retries)
{
mExceptionHandler = new google_breakpad::ExceptionHandler(
- std::wstring(mDumpPath.begin(),mDumpPath.end()),
+ wstringize(mDumpPath),
NULL, //No filter
windows_post_minidump_callback,
0,
google_breakpad::ExceptionHandler::HANDLER_ALL,
MiniDumpNormal, //Generate a 'normal' minidump.
- (WCHAR *)wpipe_name.c_str(),
+ strinize(wpipe_name).c_str(),
NULL); //No custom client info.
if (mExceptionHandler)
{
@@ -370,7 +368,7 @@ void LLApp::setupErrorHandling()
{
llwarns << "Failed to initialize OOP exception handler. Defaulting to In Process handling" << llendl;
mExceptionHandler = new google_breakpad::ExceptionHandler(
- std::wstring(mDumpPath.begin(),mDumpPath.end()), //Dump path
+ wstringize(mDumpPath),
0, //dump filename
windows_post_minidump_callback,
0,
@@ -900,26 +898,21 @@ bool unix_minidump_callback(const google_breakpad::MinidumpDescriptor& minidump_
// heap allocations in a crash handler.
// path format: <dump_dir>/<minidump_id>.dmp
-
- //HACK: *path points to the buffer in getMiniDumpFilename which has already allocated space
- //to avoid doing allocation during crash.
- char * path = LLApp::instance()->getMiniDumpFilename();
- int dir_path_len = strlen(path);
+ int dirPathLength = strlen(minidump_desc.path());
// The path must not be truncated.
- S32 remaining = LLApp::MAX_MINDUMP_PATH_LENGTH - dir_path_len;
-
- llassert( (remaining - strlen(minidump_desc.path())) > 5);
+ llassert((dirPathLength + 5) <= LLApp::MAX_MINDUMP_PATH_LENGTH);
- path += dir_path_len;
-
- if (dir_path_len > 0 && path[-1] != '/')
+ char * path = LLApp::instance()->getMiniDumpFilename();
+ S32 remaining = LLApp::MAX_MINDUMP_PATH_LENGTH;
+ strncpy(path, minidump_desc.path(), remaining);
+ remaining -= dirPathLength;
+ path += dirPathLength;
+ if (remaining > 0 && dirPathLength > 0 && path[-1] != '/')
{
*path++ = '/';
--remaining;
}
-
- strncpy(path, minidump_desc.path(), remaining);
llinfos << "generated minidump: " << LLApp::instance()->getMiniDumpFilename() << llendl;
LLApp::runErrorHandler();
diff --git a/indra/llcommon/stringize.h b/indra/llcommon/stringize.h
index 72f2e58ce1..acae74b584 100755
--- a/indra/llcommon/stringize.h
+++ b/indra/llcommon/stringize.h
@@ -31,21 +31,64 @@
#include <sstream>
#include <boost/lambda/lambda.hpp>
+#include <llstring.h>
/**
- * stringize(item) encapsulates an idiom we use constantly, using
+ * gstringize(item) encapsulates an idiom we use constantly, using
* operator<<(std::ostringstream&, TYPE) followed by std::ostringstream::str()
+ * or their wstring equivalents
* to render a string expressing some item.
*/
-template <typename T>
-std::string stringize(const T& item)
+template <typename CHARTYPE, typename T>
+std::basic_string<CHARTYPE> gstringize(const T& item)
{
- std::ostringstream out;
+ std::basic_ostringstream<CHARTYPE> out;
out << item;
return out.str();
}
/**
+ *partial specialization of stringize for handling wstring
+ *TODO: we should have similar specializations for wchar_t[] but not until it is needed.
+ */
+inline std::string stringize(const std::wstring& item)
+{
+ llwarns << "WARNING: Possible narrowing" << llendl;
+
+ std::string s;
+
+ s = wstring_to_utf8str(item);
+ return gstringize<char>(s);
+}
+
+/**
+ * Specialization of gstringize for std::string return types
+ */
+template <typename T>
+std::string stringize(const T& item)
+{
+ return gstringize<char>(item);
+}
+
+/**
+ * Specialization for generating wstring from string.
+ * Both a convenience function and saves a miniscule amount of overhead.
+ */
+inline std::wstring wstringize(const std::string& item)
+{
+ return gstringize<wchar_t>(item.c_str());
+}
+
+/**
+ * Specialization of gstringize for std::wstring return types
+ */
+template <typename T>
+std::wstring wstringize(const T& item)
+{
+ return gstringize<wchar_t>(item);
+}
+
+/**
* stringize_f(functor)
*/
template <typename Functor>
diff --git a/indra/llcommon/tests/stringize_test.cpp b/indra/llcommon/tests/stringize_test.cpp
index 3d34f23998..3e4ca548e5 100755
--- a/indra/llcommon/tests/stringize_test.cpp
+++ b/indra/llcommon/tests/stringize_test.cpp
@@ -67,6 +67,8 @@ namespace tut
llsd["i"] = i;
llsd["d"] = d;
llsd["abc"] = abc;
+ def = L"def ghi";
+
}
char c;
@@ -76,6 +78,7 @@ namespace tut
float f;
double d;
std::string abc;
+ std::wstring def;
LLSD llsd;
};
typedef test_group<stringize_data> stringize_group;
@@ -92,6 +95,7 @@ namespace tut
ensure_equals(stringize(f), "3.14159");
ensure_equals(stringize(d), "3.14159");
ensure_equals(stringize(abc), "abc def");
+ ensure_equals(stringize(def), "def ghi"); //Will generate llwarns due to narrowing.
ensure_equals(stringize(llsd), "{'abc':'abc def','d':r3.14159,'i':i34}");
}
@@ -101,4 +105,20 @@ namespace tut
ensure_equals(STRINGIZE("c is " << c), "c is c");
ensure_equals(STRINGIZE(std::setprecision(4) << d), "3.142");
}
+
+ template<> template<>
+ void stringize_object::test<3>()
+ {
+ //Tests rely on validity of wstring_to_utf8str()
+ ensure_equals(wstring_to_utf8str(wstringize(c)), wstring_to_utf8str(L"c"));
+ ensure_equals(wstring_to_utf8str(wstringize(s)), wstring_to_utf8str(L"17"));
+ ensure_equals(wstring_to_utf8str(wstringize(i)), wstring_to_utf8str(L"34"));
+ ensure_equals(wstring_to_utf8str(wstringize(l)), wstring_to_utf8str(L"68"));
+ ensure_equals(wstring_to_utf8str(wstringize(f)), wstring_to_utf8str(L"3.14159"));
+ ensure_equals(wstring_to_utf8str(wstringize(d)), wstring_to_utf8str(L"3.14159"));
+ ensure_equals(wstring_to_utf8str(wstringize(abc)), wstring_to_utf8str(L"abc def"));
+ ensure_equals(wstring_to_utf8str(wstringize(abc)), wstring_to_utf8str(wstringize(abc.c_str())));
+ ensure_equals(wstring_to_utf8str(wstringize(def)), wstring_to_utf8str(L"def ghi"));
+ // ensure_equals(wstring_to_utf8str(wstringize(llsd)), wstring_to_utf8str(L"{'abc':'abc def','d':r3.14159,'i':i34}"));
+ }
} // namespace tut