Some cleanup of string to wstring conversion and vice versa.
parent
1269634e21
commit
ea7e6a5174
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -31,18 +31,61 @@
|
|||
|
||||
#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 CHARTYPE, typename T>
|
||||
std::basic_string<CHARTYPE> gstringize(const T& item)
|
||||
{
|
||||
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)
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << item;
|
||||
return out.str();
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -3512,7 +3512,10 @@ void LLAppViewer::handleViewerCrash()
|
|||
gDebugInfo["Dynamic"]["MinidumpPath"] = minidump_file;
|
||||
}
|
||||
#ifdef LL_WINDOWS
|
||||
getFileList();
|
||||
else
|
||||
{
|
||||
getFileList();
|
||||
}
|
||||
#endif
|
||||
gDebugInfo["Dynamic"]["CrashType"]="crash";
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@
|
|||
#include "stdafx.h"
|
||||
#include <stdlib.h>
|
||||
#include "llcrashloggerwindows.h"
|
||||
#include <iostream>
|
||||
|
||||
int APIENTRY WinMain(HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
|
|
|
|||
Loading…
Reference in New Issue