Merge branch 'cpp-11' into crashlog_improvements
# Conflicts: # Makefile.src.in # projects/determineversion.vbs # source.list # src/crashlog.cpp # src/misc.cpp # src/os/unix/crashlog_unix.cpp # src/os/windows/crashlog_win.cpp # src/rev.h # src/thread/thread.h # src/thread/thread_morphos.cpp # src/thread/thread_none.cpp # src/thread/thread_os2.cpp # src/thread/thread_pthread.cpp # src/thread/thread_win32.cpp
This commit is contained in:
@@ -31,9 +31,6 @@
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
static const uint MAX_SYMBOL_LEN = 512;
|
||||
static const uint MAX_FRAMES = 64;
|
||||
|
||||
/* printf format specification for 32/64-bit addresses. */
|
||||
#ifdef _M_AMD64
|
||||
#define PRINTF_PTR "0x%016IX"
|
||||
@@ -48,14 +45,14 @@ class CrashLogWindows : public CrashLog {
|
||||
/** Information about the encountered exception */
|
||||
EXCEPTION_POINTERS *ep;
|
||||
|
||||
/* virtual */ char *LogOSVersion(char *buffer, const char *last) const;
|
||||
/* virtual */ char *LogError(char *buffer, const char *last, const char *message) const;
|
||||
/* virtual */ char *LogStacktrace(char *buffer, const char *last) const;
|
||||
/* virtual */ char *LogRegisters(char *buffer, const char *last) const;
|
||||
/* virtual */ char *LogModules(char *buffer, const char *last) const;
|
||||
char *LogOSVersion(char *buffer, const char *last) const override;
|
||||
char *LogError(char *buffer, const char *last, const char *message) const override;
|
||||
char *LogStacktrace(char *buffer, const char *last) const override;
|
||||
char *LogRegisters(char *buffer, const char *last) const override;
|
||||
char *LogModules(char *buffer, const char *last) const override;
|
||||
public:
|
||||
#if defined(_MSC_VER) || defined(WITH_DBGHELP)
|
||||
/* virtual */ int WriteCrashDump(char *filename, const char *filename_last) const;
|
||||
int WriteCrashDump(char *filename, const char *filename_last) const override;
|
||||
char *AppendDecodedStacktrace(char *buffer, const char *last) const;
|
||||
#else
|
||||
char *AppendDecodedStacktrace(char *buffer, const char *last) const { return buffer; }
|
||||
@@ -329,6 +326,9 @@ static char *PrintModuleInfo(char *output, const char *last, HMODULE mod)
|
||||
|
||||
#if defined(_MSC_VER) || defined(WITH_DBGHELP)
|
||||
#if defined(_MSC_VER)
|
||||
static const uint MAX_SYMBOL_LEN = 512;
|
||||
static const uint MAX_FRAMES = 64;
|
||||
|
||||
#pragma warning(disable:4091)
|
||||
#endif
|
||||
#include <dbghelp.h>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#define APSTUDIO_HIDDEN_SYMBOLS
|
||||
#include "windows.h"
|
||||
#undef APSTUDIO_HIDDEN_SYMBOLS
|
||||
#ifdef MSVC
|
||||
#ifndef __MINGW32__
|
||||
#include "winres.h"
|
||||
#else
|
||||
#define IDC_STATIC (-1) // all static controls
|
||||
@@ -79,8 +79,8 @@ END
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,9,0,!!ISODATE!!
|
||||
PRODUCTVERSION 1,9,0,!!ISODATE!!
|
||||
FILEVERSION 1,10,0,!!ISODATE!!
|
||||
PRODUCTVERSION 1,10,0,!!ISODATE!!
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@@ -100,7 +100,7 @@ BEGIN
|
||||
VALUE "FileDescription", "OpenTTD\0"
|
||||
VALUE "FileVersion", "!!VERSION!!\0"
|
||||
VALUE "InternalName", "openttd\0"
|
||||
VALUE "LegalCopyright", "Copyright \xA9 OpenTTD Developers 2002-2018. All Rights Reserved.\0"
|
||||
VALUE "LegalCopyright", "Copyright \xA9 OpenTTD Developers 2002-2019. All Rights Reserved.\0"
|
||||
VALUE "LegalTrademarks", "\0"
|
||||
VALUE "OriginalFilename", "openttd.exe\0"
|
||||
VALUE "PrivateBuild", "\0"
|
||||
@@ -117,5 +117,9 @@ END
|
||||
|
||||
#endif // !_MAC
|
||||
|
||||
#ifdef __MINGW32__
|
||||
1 24 "..\\..\\..\\projects\\dpi_aware.manifest"
|
||||
#endif
|
||||
|
||||
#endif // Neutral (Default) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -106,12 +106,12 @@ public:
|
||||
};
|
||||
|
||||
/** A single line worth of VisualRuns. */
|
||||
class UniscribeLine : public AutoDeleteSmallVector<UniscribeVisualRun *, 4>, public ParagraphLayouter::Line {
|
||||
class UniscribeLine : public AutoDeleteSmallVector<UniscribeVisualRun *>, public ParagraphLayouter::Line {
|
||||
public:
|
||||
virtual int GetLeading() const;
|
||||
virtual int GetWidth() const;
|
||||
virtual int CountRuns() const { return this->Length(); }
|
||||
virtual const VisualRun *GetVisualRun(int run) const { return *this->Get(run); }
|
||||
virtual int CountRuns() const { return (uint)this->size(); }
|
||||
virtual const VisualRun *GetVisualRun(int run) const { return this->at(run); }
|
||||
|
||||
int GetInternalCharLength(WChar c) const
|
||||
{
|
||||
@@ -195,6 +195,7 @@ static bool UniscribeShapeRun(const UniscribeParagraphLayoutFactory::CharType *b
|
||||
for (int i = 0; i < range.len; i++) {
|
||||
if (buff[range.pos + i] >= SCC_SPRITE_START && buff[range.pos + i] <= SCC_SPRITE_END) {
|
||||
range.ft_glyphs[range.char_to_glyph[i]] = range.font->fc->MapCharToGlyph(buff[range.pos + i]);
|
||||
range.offsets[range.char_to_glyph[i]].dv = range.font->fc->GetAscender() - range.font->fc->GetGlyph(range.ft_glyphs[range.char_to_glyph[i]])->height - 1; // Align sprite glyphs to font baseline.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,8 +282,8 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
|
||||
if (length == 0) return NULL;
|
||||
|
||||
/* Can't layout our in-built sprite fonts. */
|
||||
for (FontMap::const_iterator i = fontMapping.Begin(); i != fontMapping.End(); i++) {
|
||||
if (i->second->fc->IsBuiltInFont()) return NULL;
|
||||
for (auto const &pair : fontMapping) {
|
||||
if (pair.second->fc->IsBuiltInFont()) return NULL;
|
||||
}
|
||||
|
||||
/* Itemize text. */
|
||||
@@ -295,12 +296,12 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
|
||||
|
||||
int cur_pos = 0;
|
||||
std::vector<SCRIPT_ITEM>::iterator cur_item = items.begin();
|
||||
for (FontMap::const_iterator i = fontMapping.Begin(); i != fontMapping.End(); i++) {
|
||||
while (cur_pos < i->first && cur_item != items.end() - 1) {
|
||||
for (auto const &i : fontMapping) {
|
||||
while (cur_pos < i.first && cur_item != items.end() - 1) {
|
||||
/* Add a range that spans the intersection of the remaining item and font run. */
|
||||
int stop_pos = min(i->first, (cur_item + 1)->iCharPos);
|
||||
int stop_pos = min(i.first, (cur_item + 1)->iCharPos);
|
||||
assert(stop_pos - cur_pos > 0);
|
||||
ranges.push_back(UniscribeRun(cur_pos, stop_pos - cur_pos, i->second, cur_item->a));
|
||||
ranges.push_back(UniscribeRun(cur_pos, stop_pos - cur_pos, i.second, cur_item->a));
|
||||
|
||||
/* Shape the range. */
|
||||
if (!UniscribeShapeRun(buff, ranges.back())) {
|
||||
@@ -423,7 +424,7 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
|
||||
if (!UniscribeShapeRun(this->text_buffer, run)) return NULL;
|
||||
}
|
||||
|
||||
*line->Append() = new UniscribeVisualRun(run, cur_pos);
|
||||
line->push_back(new UniscribeVisualRun(run, cur_pos));
|
||||
cur_pos += run.total_advance;
|
||||
}
|
||||
|
||||
@@ -447,8 +448,8 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
|
||||
int UniscribeParagraphLayout::UniscribeLine::GetLeading() const
|
||||
{
|
||||
int leading = 0;
|
||||
for (const UniscribeVisualRun * const *run = this->Begin(); run != this->End(); run++) {
|
||||
leading = max(leading, (*run)->GetLeading());
|
||||
for (const UniscribeVisualRun *run : *this) {
|
||||
leading = max(leading, run->GetLeading());
|
||||
}
|
||||
|
||||
return leading;
|
||||
@@ -461,8 +462,8 @@ int UniscribeParagraphLayout::UniscribeLine::GetLeading() const
|
||||
int UniscribeParagraphLayout::UniscribeLine::GetWidth() const
|
||||
{
|
||||
int length = 0;
|
||||
for (const UniscribeVisualRun * const *run = this->Begin(); run != this->End(); run++) {
|
||||
length += (*run)->GetAdvance();
|
||||
for (const UniscribeVisualRun *run : *this) {
|
||||
length += run->GetAdvance();
|
||||
}
|
||||
|
||||
return length;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <windows.h>
|
||||
#include <fcntl.h>
|
||||
#include <regstr.h>
|
||||
#define NO_SHOBJIDL_SORTDIRECTION // Avoid multiple definition of SORT_ASCENDING
|
||||
#include <shlobj.h> /* SHGetFolderPath */
|
||||
#include <shellapi.h>
|
||||
#include "win32.h"
|
||||
@@ -29,11 +30,9 @@
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include "../../language.h"
|
||||
#include "../../thread.h"
|
||||
|
||||
/* Due to TCHAR, strncat and strncpy have to remain (for a while). */
|
||||
#include "../../safeguards.h"
|
||||
#undef strncat
|
||||
#undef strncpy
|
||||
|
||||
bool _in_event_loop_post_crash;
|
||||
|
||||
@@ -83,7 +82,7 @@ void ShowOSErrorBox(const char *buf, bool system)
|
||||
{
|
||||
_in_event_loop_post_crash = true;
|
||||
MyShowCursor(true);
|
||||
MessageBox(GetActiveWindow(), OTTD2FS(buf), _T("Error!"), MB_ICONSTOP);
|
||||
MessageBox(GetActiveWindow(), OTTD2FS(buf), _T("Error!"), MB_ICONSTOP | MB_TASKMODAL);
|
||||
}
|
||||
|
||||
void OSOpenBrowser(const char *url)
|
||||
@@ -303,7 +302,7 @@ void CreateConsole()
|
||||
if (_has_console) return;
|
||||
_has_console = true;
|
||||
|
||||
AllocConsole();
|
||||
if (!AllocConsole()) return;
|
||||
|
||||
hand = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
GetConsoleScreenBufferInfo(hand, &coninfo);
|
||||
@@ -548,12 +547,6 @@ bool GetClipboardContents(char *buffer, const char *last)
|
||||
}
|
||||
|
||||
|
||||
void CSleep(int milliseconds)
|
||||
{
|
||||
Sleep(milliseconds);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert to OpenTTD's encoding from that of the local environment.
|
||||
* When the project is built in UNICODE, the system codepage is irrelevant and
|
||||
@@ -628,11 +621,11 @@ char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen)
|
||||
* Convert from OpenTTD's encoding to that of the environment in
|
||||
* UNICODE. OpenTTD encoding is UTF8, local is wide
|
||||
* @param name pointer to a valid string that will be converted
|
||||
* @param utf16_buf pointer to a valid wide-char buffer that will receive the
|
||||
* @param system_buf pointer to a valid wide-char buffer that will receive the
|
||||
* converted string
|
||||
* @param buflen length in wide characters of the receiving buffer
|
||||
* @param console_cp convert to the console encoding instead of the normal system encoding.
|
||||
* @return pointer to utf16_buf. If conversion fails the string is of zero-length
|
||||
* @return pointer to system_buf. If conversion fails the string is of zero-length
|
||||
*/
|
||||
TCHAR *convert_to_fs(const char *name, TCHAR *system_buf, size_t buflen, bool console_cp)
|
||||
{
|
||||
@@ -735,14 +728,6 @@ const char *GetCurrentLocale(const char *)
|
||||
return retbuf;
|
||||
}
|
||||
|
||||
uint GetCPUCoreCount()
|
||||
{
|
||||
SYSTEM_INFO info;
|
||||
|
||||
GetSystemInfo(&info);
|
||||
return info.dwNumberOfProcessors;
|
||||
}
|
||||
|
||||
|
||||
static WCHAR _cur_iso_locale[16] = L"";
|
||||
|
||||
@@ -807,6 +792,42 @@ int OTTDStringCompare(const char *s1, const char *s2)
|
||||
return CompareString(MAKELCID(_current_language->winlangid, SORT_DEFAULT), NORM_IGNORECASE, s1_buf, -1, s2_buf, -1);
|
||||
}
|
||||
|
||||
static DWORD main_thread_id;
|
||||
|
||||
void SetSelfAsMainThread()
|
||||
{
|
||||
main_thread_id = GetCurrentThreadId();
|
||||
}
|
||||
|
||||
bool IsMainThread()
|
||||
{
|
||||
return main_thread_id == GetCurrentThreadId();
|
||||
}
|
||||
|
||||
bool IsNonMainThread()
|
||||
{
|
||||
return main_thread_id != GetCurrentThreadId();
|
||||
}
|
||||
|
||||
static std::map<DWORD, std::string> _thread_name_map;
|
||||
static std::mutex _thread_name_map_mutex;
|
||||
|
||||
static void Win32SetThreadName(uint id, const char *name)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_thread_name_map_mutex);
|
||||
_thread_name_map[id] = name;
|
||||
}
|
||||
|
||||
int GetCurrentThreadName(char *str, const char *last)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_thread_name_map_mutex);
|
||||
auto iter = _thread_name_map.find(GetCurrentThreadId());
|
||||
if (iter != _thread_name_map.end()) {
|
||||
return seprintf(str, last, "%s", iter->second.c_str());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
/* Based on code from MSDN: https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx */
|
||||
const DWORD MS_VC_EXCEPTION = 0x406D1388;
|
||||
@@ -821,12 +842,14 @@ PACK_N(struct THREADNAME_INFO {
|
||||
/**
|
||||
* Signal thread name to any attached debuggers.
|
||||
*/
|
||||
void SetWin32ThreadName(DWORD dwThreadID, const char* threadName)
|
||||
void SetCurrentThreadName(const char *threadName)
|
||||
{
|
||||
Win32SetThreadName(GetCurrentThreadId(), threadName);
|
||||
|
||||
THREADNAME_INFO info;
|
||||
info.dwType = 0x1000;
|
||||
info.szName = threadName;
|
||||
info.dwThreadID = dwThreadID;
|
||||
info.dwThreadID = -1;
|
||||
info.dwFlags = 0;
|
||||
|
||||
#pragma warning(push)
|
||||
@@ -837,4 +860,9 @@ void SetWin32ThreadName(DWORD dwThreadID, const char* threadName)
|
||||
}
|
||||
#pragma warning(pop)
|
||||
}
|
||||
#else
|
||||
void SetCurrentThreadName(const char *)
|
||||
{
|
||||
Win32SetThreadName(GetCurrentThreadId(), threadName);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -39,12 +39,6 @@ HRESULT OTTDSHGetFolderPath(HWND, int, HANDLE, DWORD, LPTSTR);
|
||||
#define SHGFP_TYPE_CURRENT 0
|
||||
#endif /* __MINGW32__ */
|
||||
|
||||
#ifdef _MSC_VER
|
||||
void SetWin32ThreadName(DWORD dwThreadID, const char* threadName);
|
||||
#else
|
||||
static inline void SetWin32ThreadName(DWORD dwThreadID, const char* threadName) {}
|
||||
#endif
|
||||
|
||||
void Win32SetCurrentLocaleName(const char *iso_code);
|
||||
int OTTDStringCompare(const char *s1, const char *s2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user