[Base] Wrap strdup and strcasecmp in xe:: functions
This commit is contained in:
parent
500bbe9e0d
commit
34a952d789
|
@ -67,9 +67,6 @@
|
|||
#endif
|
||||
|
||||
#if XE_PLATFORM_WIN32
|
||||
#define strdup _strdup
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX // Don't want windows.h including min/max macros.
|
||||
#endif // XE_PLATFORM_WIN32
|
||||
|
|
|
@ -9,9 +9,16 @@
|
|||
|
||||
#include "xenia/base/string.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
#include <locale>
|
||||
|
||||
#include "xenia/base/platform.h"
|
||||
|
||||
#if !XE_PLATFORM_WIN32
|
||||
#include <strings.h>
|
||||
#endif // !XE_PLATFORM_WIN32
|
||||
|
||||
#define UTF_CPP_CPLUSPLUS 201703L
|
||||
#include "third_party/utfcpp/source/utf8.h"
|
||||
|
||||
|
@ -19,6 +26,30 @@ namespace utfcpp = utf8;
|
|||
|
||||
namespace xe {
|
||||
|
||||
int xe_strcasecmp(const char* string1, const char* string2) {
|
||||
#if XE_PLATFORM_WIN32
|
||||
return _stricmp(string1, string2);
|
||||
#else
|
||||
return strcasecmp(string1, string2);
|
||||
#endif // XE_PLATFORM_WIN32
|
||||
}
|
||||
|
||||
int xe_strncasecmp(const char* string1, const char* string2, size_t count) {
|
||||
#if XE_PLATFORM_WIN32
|
||||
return _strnicmp(string1, string2, count);
|
||||
#else
|
||||
return strncasecmp(string1, string2, count);
|
||||
#endif // XE_PLATFORM_WIN32
|
||||
}
|
||||
|
||||
char* xe_strdup(const char* source) {
|
||||
#if XE_PLATFORM_WIN32
|
||||
return _strdup(source);
|
||||
#else
|
||||
return strdup(source);
|
||||
#endif // XE_PLATFORM_WIN32
|
||||
}
|
||||
|
||||
std::string to_utf8(const std::u16string_view source) {
|
||||
return utfcpp::utf16to8(source);
|
||||
}
|
||||
|
|
|
@ -12,10 +12,14 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "utf8.h"
|
||||
#include "xenia/base/utf8.h"
|
||||
|
||||
namespace xe {
|
||||
|
||||
int xe_strcasecmp(const char* string1, const char* string2);
|
||||
int xe_strncasecmp(const char* string1, const char* string2, size_t count);
|
||||
char* xe_strdup(const char* source);
|
||||
|
||||
std::string to_utf8(const std::u16string_view source);
|
||||
std::u16string to_utf16(const std::string_view source);
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "third_party/capstone/include/capstone/x86.h"
|
||||
#include "xenia/base/profiling.h"
|
||||
#include "xenia/base/reset_scope.h"
|
||||
#include "xenia/base/string.h"
|
||||
#include "xenia/cpu/backend/x64/x64_backend.h"
|
||||
#include "xenia/cpu/backend/x64/x64_code_cache.h"
|
||||
#include "xenia/cpu/backend/x64/x64_emitter.h"
|
||||
|
@ -86,7 +87,7 @@ bool X64Assembler::Assemble(GuestFunction* function, HIRBuilder* builder,
|
|||
if (debug_info_flags & DebugInfoFlags::kDebugInfoDisasmMachineCode) {
|
||||
DumpMachineCode(machine_code, code_size, function->source_map(),
|
||||
&string_buffer_);
|
||||
debug_info->set_machine_code_disasm(strdup(string_buffer_.buffer()));
|
||||
debug_info->set_machine_code_disasm(xe_strdup(string_buffer_.buffer()));
|
||||
string_buffer_.Reset();
|
||||
}
|
||||
|
||||
|
|
|
@ -25,12 +25,12 @@
|
|||
#include "xenia/cpu/backend/x64/x64_sequences.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "xenia/base/assert.h"
|
||||
#include "xenia/base/clock.h"
|
||||
#include "xenia/base/logging.h"
|
||||
#include "xenia/base/string.h"
|
||||
#include "xenia/base/threading.h"
|
||||
#include "xenia/cpu/backend/x64/x64_emitter.h"
|
||||
#include "xenia/cpu/backend/x64/x64_op.h"
|
||||
|
@ -63,7 +63,7 @@ struct COMMENT : Sequence<COMMENT, I<OPCODE_COMMENT, VoidOp, OffsetOp>> {
|
|||
auto str = reinterpret_cast<const char*>(i.src1.value);
|
||||
// TODO(benvanik): pass through.
|
||||
// TODO(benvanik): don't just leak this memory.
|
||||
auto str_copy = strdup(str);
|
||||
auto str_copy = xe_strdup(str);
|
||||
e.mov(e.rdx, reinterpret_cast<uint64_t>(str_copy));
|
||||
e.CallNative(reinterpret_cast<void*>(TraceString));
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "xenia/base/logging.h"
|
||||
#include "xenia/base/memory.h"
|
||||
#include "xenia/base/profiling.h"
|
||||
#include "xenia/base/string.h"
|
||||
#include "xenia/cpu/cpu_flags.h"
|
||||
#include "xenia/cpu/hir/label.h"
|
||||
#include "xenia/cpu/ppc/ppc_context.h"
|
||||
|
@ -215,25 +216,25 @@ void PPCHIRBuilder::MaybeBreakOnInstruction(uint32_t address) {
|
|||
|
||||
auto op = cvars::break_condition_op.c_str();
|
||||
// TODO(rick): table?
|
||||
if (strcasecmp(op, "eq") == 0) {
|
||||
if (xe_strcasecmp(op, "eq") == 0) {
|
||||
TrapTrue(CompareEQ(left, right));
|
||||
} else if (strcasecmp(op, "ne") == 0) {
|
||||
} else if (xe_strcasecmp(op, "ne") == 0) {
|
||||
TrapTrue(CompareNE(left, right));
|
||||
} else if (strcasecmp(op, "slt") == 0) {
|
||||
} else if (xe_strcasecmp(op, "slt") == 0) {
|
||||
TrapTrue(CompareSLT(left, right));
|
||||
} else if (strcasecmp(op, "sle") == 0) {
|
||||
} else if (xe_strcasecmp(op, "sle") == 0) {
|
||||
TrapTrue(CompareSLE(left, right));
|
||||
} else if (strcasecmp(op, "sgt") == 0) {
|
||||
} else if (xe_strcasecmp(op, "sgt") == 0) {
|
||||
TrapTrue(CompareSGT(left, right));
|
||||
} else if (strcasecmp(op, "sge") == 0) {
|
||||
} else if (xe_strcasecmp(op, "sge") == 0) {
|
||||
TrapTrue(CompareSGE(left, right));
|
||||
} else if (strcasecmp(op, "ult") == 0) {
|
||||
} else if (xe_strcasecmp(op, "ult") == 0) {
|
||||
TrapTrue(CompareULT(left, right));
|
||||
} else if (strcasecmp(op, "ule") == 0) {
|
||||
} else if (xe_strcasecmp(op, "ule") == 0) {
|
||||
TrapTrue(CompareULE(left, right));
|
||||
} else if (strcasecmp(op, "ugt") == 0) {
|
||||
} else if (xe_strcasecmp(op, "ugt") == 0) {
|
||||
TrapTrue(CompareUGT(left, right));
|
||||
} else if (strcasecmp(op, "uge") == 0) {
|
||||
} else if (xe_strcasecmp(op, "uge") == 0) {
|
||||
TrapTrue(CompareUGE(left, right));
|
||||
} else {
|
||||
assert_always();
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "xenia/base/memory.h"
|
||||
#include "xenia/base/profiling.h"
|
||||
#include "xenia/base/reset_scope.h"
|
||||
#include "xenia/base/string.h"
|
||||
#include "xenia/cpu/compiler/compiler_passes.h"
|
||||
#include "xenia/cpu/cpu_flags.h"
|
||||
#include "xenia/cpu/ppc/ppc_frontend.h"
|
||||
|
@ -155,7 +156,7 @@ bool PPCTranslator::Translate(GuestFunction* function,
|
|||
// Stash source.
|
||||
if (debug_info_flags & DebugInfoFlags::kDebugInfoDisasmSource) {
|
||||
DumpSource(function, &string_buffer_);
|
||||
debug_info->set_source_disasm(strdup(string_buffer_.buffer()));
|
||||
debug_info->set_source_disasm(xe_strdup(string_buffer_.buffer()));
|
||||
string_buffer_.Reset();
|
||||
}
|
||||
|
||||
|
@ -171,7 +172,7 @@ bool PPCTranslator::Translate(GuestFunction* function,
|
|||
// Stash raw HIR.
|
||||
if (debug_info_flags & DebugInfoFlags::kDebugInfoDisasmRawHir) {
|
||||
builder_->Dump(&string_buffer_);
|
||||
debug_info->set_raw_hir_disasm(strdup(string_buffer_.buffer()));
|
||||
debug_info->set_raw_hir_disasm(xe_strdup(string_buffer_.buffer()));
|
||||
string_buffer_.Reset();
|
||||
}
|
||||
|
||||
|
@ -183,7 +184,7 @@ bool PPCTranslator::Translate(GuestFunction* function,
|
|||
// Stash optimized HIR.
|
||||
if (debug_info_flags & DebugInfoFlags::kDebugInfoDisasmHir) {
|
||||
builder_->Dump(&string_buffer_);
|
||||
debug_info->set_hir_disasm(strdup(string_buffer_.buffer()));
|
||||
debug_info->set_hir_disasm(xe_strdup(string_buffer_.buffer()));
|
||||
string_buffer_.Reset();
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ DECLARE_XBOXKRNL_EXPORT1(RtlLowerChar, kNone, kImplemented);
|
|||
|
||||
dword_result_t RtlCompareString_entry(lpstring_t string_1, lpstring_t string_2,
|
||||
dword_t case_insensitive) {
|
||||
int ret = case_insensitive ? strcasecmp(string_1, string_2)
|
||||
int ret = case_insensitive ? xe_strcasecmp(string_1, string_2)
|
||||
: std::strcmp(string_1, string_2);
|
||||
|
||||
return ret;
|
||||
|
@ -130,7 +130,7 @@ dword_result_t RtlCompareStringN_entry(lpstring_t string_1,
|
|||
}
|
||||
auto len = std::min(string_1_len, string_2_len);
|
||||
|
||||
int ret = case_insensitive ? strncasecmp(string_1, string_2, len)
|
||||
int ret = case_insensitive ? xe_strncasecmp(string_1, string_2, len)
|
||||
: std::strncmp(string_1, string_2, len);
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "xenia/base/filesystem.h"
|
||||
#include "xenia/base/logging.h"
|
||||
#include "xenia/base/math.h"
|
||||
#include "xenia/base/string.h"
|
||||
#include "xenia/kernel/xfile.h"
|
||||
#include "xenia/vfs/devices/null_entry.h"
|
||||
|
||||
|
@ -50,7 +51,7 @@ Entry* NullDevice::ResolvePath(const std::string_view path) {
|
|||
}
|
||||
|
||||
for (auto& child : root->children()) {
|
||||
if (!strcasecmp(child->path().c_str(), path.data())) {
|
||||
if (!xe_strcasecmp(child->path().c_str(), path.data())) {
|
||||
return child.get();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue