summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorAura Linden <aura@lindenlab.com>2014-01-14 15:28:35 -0800
committerAura Linden <aura@lindenlab.com>2014-01-14 15:28:35 -0800
commitea7e6a5174f1bdfc51ada864736d354706534d8b (patch)
treec3b6be6d25b33e41ce01edabb6f0bf91ce3afb38 /indra
parent1269634e21078ad0af12d29c41778039e9f195ec (diff)
Some cleanup of string to wstring conversion and vice versa.
Diffstat (limited to 'indra')
-rwxr-xr-xindra/llcommon/llapp.cpp33
-rwxr-xr-xindra/llcommon/stringize.h51
-rwxr-xr-xindra/llcommon/tests/stringize_test.cpp20
-rwxr-xr-xindra/newview/llappviewer.cpp5
-rw-r--r--indra/newview/llappviewerwin32.cpp6
-rw-r--r--indra/win_crash_logger/llcrashloggerwindows.cpp9
-rwxr-xr-xindra/win_crash_logger/win_crash_logger.cpp1
7 files changed, 91 insertions, 34 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
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 307a02b527..5c0368df19 100755
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -3512,7 +3512,10 @@ void LLAppViewer::handleViewerCrash()
gDebugInfo["Dynamic"]["MinidumpPath"] = minidump_file;
}
#ifdef LL_WINDOWS
- getFileList();
+ else
+ {
+ getFileList();
+ }
#endif
gDebugInfo["Dynamic"]["CrashType"]="crash";
diff --git a/indra/newview/llappviewerwin32.cpp b/indra/newview/llappviewerwin32.cpp
index 6946130631..c861d0a99f 100644
--- a/indra/newview/llappviewerwin32.cpp
+++ b/indra/newview/llappviewerwin32.cpp
@@ -65,6 +65,8 @@
#include "llwindebug.h"
#endif
+#include "stringize.h"
+
#include <exception>
namespace
{
@@ -685,8 +687,6 @@ void LLAppViewerWin32::initCrashReporting(bool reportFreeze)
exe_path += gDirUtilp->getDirDelimiter();
exe_path += logger_name;
- std::stringstream pid_str;
- pid_str << LLApp::getPid();
std::string logdir = gDirUtilp->getExpandedFilename(LL_PATH_DUMP, "");
std::string appname = gDirUtilp->getExecutableFilename();
@@ -698,7 +698,7 @@ void LLAppViewerWin32::initCrashReporting(bool reportFreeze)
{
logdir = logdir.substr(0,end+1);
}
- std::string arg_str = "\"" + exe_path + "\" -dumpdir \"" + logdir + "\" -procname \"" + appname + "\" -pid " + pid_str.str();
+ std::string arg_str = "\"" + exe_path + "\" -dumpdir \"" + logdir + "\" -procname \"" + appname + "\" -pid " + stringize(LLApp::getPid());
_spawnl(_P_NOWAIT, exe_path.c_str(), arg_str.c_str(), NULL);
}
diff --git a/indra/win_crash_logger/llcrashloggerwindows.cpp b/indra/win_crash_logger/llcrashloggerwindows.cpp
index 49c7ade135..f0bc03a9c4 100644
--- a/indra/win_crash_logger/llcrashloggerwindows.cpp
+++ b/indra/win_crash_logger/llcrashloggerwindows.cpp
@@ -383,18 +383,17 @@ bool LLCrashLoggerWindows::initCrashServer()
mPID = options["pid"].asInteger();
mProcName = options["procname"].asString();
- std::wostringstream ws;
//Generate a quasi-uniq name for the named pipe. For our purposes
//this is unique-enough with least hassle. Worst case for duplicate name
//is a second instance of the viewer will not do crash reporting.
- ws << mCrashReportPipeStr << mPID;
- std::wstring wpipe_name = ws.str();
+ std::wstring wpipe_name;
+ wpipe_name = mCrashReportPipeStr + stringize(mPID);
std::wstring wdump_path;
- wdump_path.assign(dump_path.begin(), dump_path.end());
+ wdump_path = stringize(dump_path);
//Pipe naming conventions: http://msdn.microsoft.com/en-us/library/aa365783%28v=vs.85%29.aspx
- mCrashHandler = new CrashGenerationServer( (WCHAR *)wpipe_name.c_str(),
+ mCrashHandler = new CrashGenerationServer( stringize(wpipe_name).c_str(),
NULL,
&LLCrashLoggerWindows::OnClientConnected, this,
NULL, NULL, // &LLCrashLoggerWindows::OnClientDumpRequest, this,
diff --git a/indra/win_crash_logger/win_crash_logger.cpp b/indra/win_crash_logger/win_crash_logger.cpp
index 0078559c24..0f125028a3 100755
--- a/indra/win_crash_logger/win_crash_logger.cpp
+++ b/indra/win_crash_logger/win_crash_logger.cpp
@@ -28,7 +28,6 @@
#include "stdafx.h"
#include <stdlib.h>
#include "llcrashloggerwindows.h"
-#include <iostream>
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,