Skip to content

Commit cb6a458

Browse files
committed
More test coverage
1 parent 13c5fa9 commit cb6a458

File tree

6 files changed

+866
-120
lines changed

6 files changed

+866
-120
lines changed

modules/yup_core/system/yup_SystemStats.cpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ uint64 SystemStats::getCompileUniqueId()
214214
}
215215

216216
//==============================================================================
217-
#if YUP_ANDROID
217+
#if YUP_ANDROID && __ANDROID_API__ < 33
218218
struct BacktraceState
219219
{
220220
BacktraceState (void** current, void** end)
@@ -295,26 +295,11 @@ String SystemStats::getStackBacktrace()
295295
_Unwind_Backtrace (unwindCallback, &state);
296296

297297
auto frames = static_cast<size_t> (state.current - &stack[0]);
298-
for (auto i = (decltype (frames)) 0; i < frames; ++i)
299-
{
300-
Dl_info info;
301-
if (dladdr (stack[i], &info))
302-
{
303-
int status = 0;
304-
std::unique_ptr<char, decltype (::free)*> demangled (abi::__cxa_demangle (info.dli_sname, nullptr, 0, &status), ::free);
305-
306-
result
307-
<< yup::String (i).paddedRight (' ', 3)
308-
<< " " << yup::File (yup::String (info.dli_fname)).getFileName().paddedRight (' ', 35)
309-
<< " 0x" << yup::String::toHexString ((size_t) stack[i]).paddedLeft ('0', sizeof (void*) * 2)
310-
<< " " << demangled.get()
311-
<< " + " << ((char*) stack[i] - (char*) info.dli_saddr) << newLine;
312-
}
313-
}
314-
298+
char** frameStrings = nullptr;
315299
#else
316300
auto frames = backtrace (stack, numElementsInArray (stack));
317301
char** frameStrings = backtrace_symbols (stack, frames);
302+
#endif
318303

319304
for (auto i = (decltype (frames)) 0; i < frames; ++i)
320305
{
@@ -336,9 +321,9 @@ String SystemStats::getStackBacktrace()
336321
}
337322
}
338323

339-
result << frameStrings[i] << newLine;
324+
if (frameStrings != nullptr)
325+
result << frameStrings[i] << newLine;
340326
}
341-
#endif
342327
#endif
343328

344329
return result;

modules/yup_core/text/yup_String.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,26 +2031,18 @@ bool String::containsNonWhitespaceChars() const noexcept
20312031

20322032
String String::reversed() const
20332033
{
2034-
if (isEmpty())
2035-
return *this;
2036-
2037-
// Count characters first to know how much space we need
2038-
int numChars = length();
2034+
const int numChars = length();
20392035
if (numChars <= 0)
2040-
return {};
2036+
return *this;
20412037

2042-
// Create array to store character positions
20432038
HeapBlock<CharPointerType> positions (numChars);
20442039

2045-
// Build the result by iterating backwards through characters
20462040
StringCreationHelper builder (text);
20472041

2048-
// Store the start position of each character
20492042
int index = 0;
20502043
for (auto it = text; ! it.isEmpty() && index < numChars; ++it, ++index)
20512044
positions[index] = it;
20522045

2053-
// Now write characters in reverse order
20542046
for (int i = index - 1; i >= 0; --i)
20552047
builder.write (*positions[i]);
20562048

modules/yup_core/xml/yup_XmlElement.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,9 @@ bool XmlElement::hasTagName (StringRef possibleTagName) const noexcept
467467

468468
String XmlElement::getNamespace() const
469469
{
470-
return tagName.upToFirstOccurrenceOf (":", false, false);
470+
return tagName.contains(":")
471+
? tagName.upToFirstOccurrenceOf (":", false, false)
472+
: String();
471473
}
472474

473475
String XmlElement::getTagNameWithoutNamespace() const

modules/yup_python/utilities/yup_CrashHandling.cpp

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -21,94 +21,14 @@
2121

2222
#include "yup_CrashHandling.h"
2323

24-
#if defined(_LIBCPP_VERSION) || defined(__GLIBCXX__) || defined(__GLIBCPP__)
25-
#include <cxxabi.h>
26-
#include <execinfo.h>
27-
#include <dlfcn.h>
28-
#else
29-
#include "yup_WindowsIncludes.h"
30-
#endif
31-
3224
namespace yup::Helpers
3325
{
3426

3527
//==============================================================================
3628

37-
String getStackBacktrace()
38-
{
39-
String result;
40-
41-
#if YUP_WINDOWS
42-
HANDLE process = GetCurrentProcess();
43-
SymInitialize (process, nullptr, TRUE);
44-
45-
void* stack[128];
46-
int frames = static_cast<int> (CaptureStackBackTrace (0, numElementsInArray (stack), stack, nullptr));
47-
48-
HeapBlock<SYMBOL_INFO> symbol;
49-
symbol.calloc (sizeof (SYMBOL_INFO) + 256, 1);
50-
symbol->MaxNameLen = 255;
51-
symbol->SizeOfStruct = sizeof (SYMBOL_INFO);
52-
53-
for (int i = 0; i < frames; ++i)
54-
{
55-
DWORD64 displacement = 0;
56-
57-
if (SymFromAddr (process, reinterpret_cast<DWORD64> (stack[i]), &displacement, symbol))
58-
{
59-
result << i << ": ";
60-
61-
IMAGEHLP_MODULE64 moduleInfo;
62-
zerostruct (moduleInfo);
63-
moduleInfo.SizeOfStruct = sizeof (moduleInfo);
64-
65-
if (::SymGetModuleInfo64 (process, symbol->ModBase, &moduleInfo))
66-
result << moduleInfo.ModuleName << ": ";
67-
68-
result << symbol->Name << " + 0x" << String::toHexString (static_cast<int64> (displacement)) << newLine;
69-
}
70-
}
71-
72-
#else
73-
void* stack[128];
74-
auto frames = backtrace (stack, numElementsInArray (stack));
75-
char** frameStrings = backtrace_symbols (stack, frames);
76-
77-
for (int i = 0; i < frames; ++i)
78-
{
79-
Dl_info info;
80-
if (dladdr (stack[i], &info))
81-
{
82-
int status = 0;
83-
84-
std::unique_ptr<char, decltype (::free)*> demangled (abi::__cxa_demangle (info.dli_sname, nullptr, nullptr, &status), ::free);
85-
if (status == 0)
86-
{
87-
result
88-
<< String (i).paddedRight (' ', 3)
89-
<< " " << File (String (info.dli_fname)).getFileName().paddedRight (' ', 35)
90-
<< " 0x" << String::toHexString (reinterpret_cast<size_t> (stack[i])).paddedLeft ('0', sizeof (void*) * 2)
91-
<< " " << demangled.get()
92-
<< " + " << (reinterpret_cast<char*> (stack[i]) - reinterpret_cast<char*> (info.dli_saddr)) << newLine;
93-
94-
continue;
95-
}
96-
}
97-
98-
result << frameStrings[i] << newLine;
99-
}
100-
101-
::free (frameStrings);
102-
#endif
103-
104-
return result;
105-
}
106-
107-
//==============================================================================
108-
10929
void applicationCrashHandler ([[maybe_unused]] void* stackFrame)
11030
{
111-
Logger::getCurrentLogger()->outputDebugString (getStackBacktrace());
31+
Logger::getCurrentLogger()->outputDebugString (SystemStats::getStackBacktrace());
11232
}
11333

11434
} // namespace yup::Helpers

modules/yup_python/utilities/yup_CrashHandling.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ namespace yup::Helpers
2828

2929
//==============================================================================
3030

31-
/**
32-
* @brief Obtain stack traces.
33-
*/
34-
String getStackBacktrace();
35-
36-
//==============================================================================
37-
3831
/**
3932
* @brief Crash handler.
4033
*/

0 commit comments

Comments
 (0)