From 24fe169f36277899dc1e8896365cac5df7949815 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sun, 17 Aug 2014 11:48:29 -0700 Subject: [PATCH] Last bit of string cleanup. string.h finally gone. --- .../compiler/passes/finalization_pass.cc | 2 +- src/alloy/frontend/ppc/ppc_context.cc | 2 +- src/alloy/frontend/ppc/ppc_disasm.cc | 6 +- src/alloy/frontend/ppc/ppc_hir_builder.cc | 4 +- src/alloy/frontend/ppc/ppc_instr.cc | 32 ++++---- src/alloy/hir/hir_builder.cc | 2 +- src/poly/string.cc | 16 ++++ src/poly/string.h | 6 ++ src/xenia/common.h | 2 +- src/xenia/core/mmap.h | 2 +- src/xenia/core/mmap_win.cc | 2 +- src/xenia/cpu/xex_module.cc | 28 +++---- src/xenia/export_resolver.cc | 77 +++++++++---------- src/xenia/export_resolver.h | 53 ++++++------- src/xenia/gpu/d3d11/d3d11_geometry_shader.cc | 6 +- src/xenia/gpu/d3d11/d3d11_shader_resource.cc | 7 +- src/xenia/gpu/d3d11/d3d11_shader_translator.h | 3 +- src/xenia/gpu/xenos/ucode_disassembler.cc | 3 +- .../kernel/fs/devices/disc_image_device.cc | 29 +------ .../fs/devices/stfs_container_device.cc | 29 +------ src/xenia/kernel/objects/xthread.cc | 2 +- src/xenia/kernel/util/xex2.cc | 9 +-- src/xenia/kernel/util/xex2.h | 1 - src/xenia/logging.cc | 9 ++- src/xenia/logging.h | 2 +- src/xenia/profiling.h | 2 +- src/xenia/sources.gypi | 1 - src/xenia/string.h | 47 ----------- 28 files changed, 148 insertions(+), 236 deletions(-) delete mode 100644 src/xenia/string.h diff --git a/src/alloy/compiler/passes/finalization_pass.cc b/src/alloy/compiler/passes/finalization_pass.cc index 5066b53ab..fcd827d1f 100644 --- a/src/alloy/compiler/passes/finalization_pass.cc +++ b/src/alloy/compiler/passes/finalization_pass.cc @@ -45,7 +45,7 @@ int FinalizationPass::Run(HIRBuilder* builder) { if (!label->name) { const size_t label_len = 6 + 4 + 1; char* name = (char*)arena->Alloc(label_len); - xesnprintfa(name, label_len, "_label%d", label->id); + snprintf(name, label_len, "_label%d", label->id); label->name = name; } label = label->next; diff --git a/src/alloy/frontend/ppc/ppc_context.cc b/src/alloy/frontend/ppc/ppc_context.cc index b6b743621..c7a070696 100644 --- a/src/alloy/frontend/ppc/ppc_context.cc +++ b/src/alloy/frontend/ppc/ppc_context.cc @@ -32,7 +32,7 @@ bool PPCContext::CompareRegWithString(const char* name, const char* value, if (sscanf(name, "r%d", &n) == 1) { uint64_t expected = ParseInt64(value); if (this->r[n] != expected) { - xesnprintfa(out_value, out_value_size, "%016llX", this->r[n]); + snprintf(out_value, out_value_size, "%016llX", this->r[n]); return false; } return true; diff --git a/src/alloy/frontend/ppc/ppc_disasm.cc b/src/alloy/frontend/ppc/ppc_disasm.cc index 726e5486e..54746b335 100644 --- a/src/alloy/frontend/ppc/ppc_disasm.cc +++ b/src/alloy/frontend/ppc/ppc_disasm.cc @@ -294,7 +294,7 @@ void Disasm_bcx(InstrData& i, StringBuffer* str) { } char s2[8] = {0}; if (!select_bits(i.B.BO, 4, 4)) { - xesnprintfa(s2, poly::countof(s2), "cr%d, ", i.B.BI >> 2); + snprintf(s2, poly::countof(s2), "cr%d, ", i.B.BI >> 2); } uint32_t nia; if (i.B.AA) { @@ -310,7 +310,7 @@ void Disasm_bcctrx(InstrData& i, StringBuffer* str) { const char* s0 = i.XL.LK ? "lr, " : ""; char s2[8] = {0}; if (!select_bits(i.XL.BO, 4, 4)) { - xesnprintfa(s2, poly::countof(s2), "cr%d, ", i.XL.BI >> 2); + snprintf(s2, poly::countof(s2), "cr%d, ", i.XL.BI >> 2); } str->Append("%-8s %s%sctr", i.type->name, s0, s2); // TODO(benvanik): resolve target name? @@ -328,7 +328,7 @@ void Disasm_bclrx(InstrData& i, StringBuffer* str) { } char s2[8] = {0}; if (!select_bits(i.XL.BO, 4, 4)) { - xesnprintfa(s2, poly::countof(s2), "cr%d, ", i.XL.BI >> 2); + snprintf(s2, poly::countof(s2), "cr%d, ", i.XL.BI >> 2); } str->Append("%-8s %s%s", name, s1, s2); } diff --git a/src/alloy/frontend/ppc/ppc_hir_builder.cc b/src/alloy/frontend/ppc/ppc_hir_builder.cc index a426dd257..627c4cac8 100644 --- a/src/alloy/frontend/ppc/ppc_hir_builder.cc +++ b/src/alloy/frontend/ppc/ppc_hir_builder.cc @@ -168,8 +168,8 @@ int PPCHIRBuilder::Emit(FunctionInfo* symbol_info, uint32_t flags) { void PPCHIRBuilder::AnnotateLabel(uint64_t address, Label* label) { char name_buffer[13]; - xesnprintfa(name_buffer, poly::countof(name_buffer), "loc_%.8X", - (uint32_t)address); + snprintf(name_buffer, poly::countof(name_buffer), "loc_%.8X", + (uint32_t)address); label->name = (char*)arena_->Alloc(sizeof(name_buffer)); xe_copy_struct(label->name, name_buffer, sizeof(name_buffer)); } diff --git a/src/alloy/frontend/ppc/ppc_instr.cc b/src/alloy/frontend/ppc/ppc_instr.cc index 0410a1502..c90c46a37 100644 --- a/src/alloy/frontend/ppc/ppc_instr.cc +++ b/src/alloy/frontend/ppc/ppc_instr.cc @@ -30,28 +30,28 @@ void InstrOperand::Dump(std::string& out_str) { case InstrOperand::kRegister: switch (reg.set) { case InstrRegister::kXER: - xesnprintfa(buffer, max_count, "XER"); + snprintf(buffer, max_count, "XER"); break; case InstrRegister::kLR: - xesnprintfa(buffer, max_count, "LR"); + snprintf(buffer, max_count, "LR"); break; case InstrRegister::kCTR: - xesnprintfa(buffer, max_count, "CTR"); + snprintf(buffer, max_count, "CTR"); break; case InstrRegister::kCR: - xesnprintfa(buffer, max_count, "CR%d", reg.ordinal); + snprintf(buffer, max_count, "CR%d", reg.ordinal); break; case InstrRegister::kFPSCR: - xesnprintfa(buffer, max_count, "FPSCR"); + snprintf(buffer, max_count, "FPSCR"); break; case InstrRegister::kGPR: - xesnprintfa(buffer, max_count, "r%d", reg.ordinal); + snprintf(buffer, max_count, "r%d", reg.ordinal); break; case InstrRegister::kFPR: - xesnprintfa(buffer, max_count, "f%d", reg.ordinal); + snprintf(buffer, max_count, "f%d", reg.ordinal); break; case InstrRegister::kVMX: - xesnprintfa(buffer, max_count, "vr%d", reg.ordinal); + snprintf(buffer, max_count, "vr%d", reg.ordinal); break; } break; @@ -59,30 +59,30 @@ void InstrOperand::Dump(std::string& out_str) { switch (imm.width) { case 1: if (imm.is_signed) { - xesnprintfa(buffer, max_count, "%d", (int32_t)(int8_t)imm.value); + snprintf(buffer, max_count, "%d", (int32_t)(int8_t)imm.value); } else { - xesnprintfa(buffer, max_count, "0x%.2X", (uint8_t)imm.value); + snprintf(buffer, max_count, "0x%.2X", (uint8_t)imm.value); } break; case 2: if (imm.is_signed) { - xesnprintfa(buffer, max_count, "%d", (int32_t)(int16_t)imm.value); + snprintf(buffer, max_count, "%d", (int32_t)(int16_t)imm.value); } else { - xesnprintfa(buffer, max_count, "0x%.4X", (uint16_t)imm.value); + snprintf(buffer, max_count, "0x%.4X", (uint16_t)imm.value); } break; case 4: if (imm.is_signed) { - xesnprintfa(buffer, max_count, "%d", (int32_t)imm.value); + snprintf(buffer, max_count, "%d", (int32_t)imm.value); } else { - xesnprintfa(buffer, max_count, "0x%.8X", (uint32_t)imm.value); + snprintf(buffer, max_count, "0x%.8X", (uint32_t)imm.value); } break; case 8: if (imm.is_signed) { - xesnprintfa(buffer, max_count, "%lld", (int64_t)imm.value); + snprintf(buffer, max_count, "%lld", (int64_t)imm.value); } else { - xesnprintfa(buffer, max_count, "0x%.16llX", imm.value); + snprintf(buffer, max_count, "0x%.16llX", imm.value); } break; } diff --git a/src/alloy/hir/hir_builder.cc b/src/alloy/hir/hir_builder.cc index ac6eec173..2a0bec6f3 100644 --- a/src/alloy/hir/hir_builder.cc +++ b/src/alloy/hir/hir_builder.cc @@ -625,7 +625,7 @@ void HIRBuilder::Comment(const char* format, ...) { char buffer[1024]; va_list args; va_start(args, format); - xevsnprintfa(buffer, 1024, format, args); + vsnprintf(buffer, 1024, format, args); va_end(args); size_t len = strlen(buffer); if (!len) { diff --git a/src/poly/string.cc b/src/poly/string.cc index 0525b5541..8c877ec0d 100644 --- a/src/poly/string.cc +++ b/src/poly/string.cc @@ -51,6 +51,22 @@ std::wstring to_absolute_path(const std::wstring& path) { #endif // XE_LIKE_WIN32 } +std::vector split_path(const std::string& path) { + std::vector parts; + size_t n = 0; + size_t last = 0; + while ((n = path.find_first_of("\\/", last)) != path.npos) { + if (last != n) { + parts.push_back(path.substr(last, n - last)); + } + last = n + 1; + } + if (last != path.size()) { + parts.push_back(path.substr(last)); + } + return parts; +} + std::wstring join_paths(const std::wstring& left, const std::wstring& right, wchar_t sep) { if (!left.size()) { diff --git a/src/poly/string.h b/src/poly/string.h index 688dd4c1b..0787ba935 100644 --- a/src/poly/string.h +++ b/src/poly/string.h @@ -10,13 +10,16 @@ #ifndef POLY_STRING_H_ #define POLY_STRING_H_ +#include #include +#include #include #if XE_LIKE_WIN32 #define strcasecmp _stricmp #define strncasecmp _strnicmp +#define snprintf _snprintf #endif // XE_LIKE_WIN32 namespace poly { @@ -31,6 +34,9 @@ std::string::size_type find_first_of_case(const std::string& target, // Converts the given path to an absolute path based on cwd. std::wstring to_absolute_path(const std::wstring& path); +// Splits the given path on any valid path separator and returns all parts. +std::vector split_path(const std::string& path); + // Joins two path segments with the given separator. std::wstring join_paths(const std::wstring& left, const std::wstring& right, wchar_t sep = poly::path_separator); diff --git a/src/xenia/common.h b/src/xenia/common.h index 3e027f858..3b911ea0f 100644 --- a/src/xenia/common.h +++ b/src/xenia/common.h @@ -14,11 +14,11 @@ #include #include #include +#include #include #include #include -#include #include #endif // XENIA_COMMON_H_ diff --git a/src/xenia/core/mmap.h b/src/xenia/core/mmap.h index 29178c963..eaa217c46 100644 --- a/src/xenia/core/mmap.h +++ b/src/xenia/core/mmap.h @@ -22,7 +22,7 @@ typedef enum { kXEFileModeWrite = (1 << 1), } xe_file_mode; -xe_mmap_ref xe_mmap_open(const xe_file_mode mode, const xechar_t *path, +xe_mmap_ref xe_mmap_open(const xe_file_mode mode, const wchar_t *path, const size_t offset, const size_t length); xe_mmap_ref xe_mmap_retain(xe_mmap_ref mmap); void xe_mmap_release(xe_mmap_ref mmap); diff --git a/src/xenia/core/mmap_win.cc b/src/xenia/core/mmap_win.cc index 38b9ca025..4121fd2af 100644 --- a/src/xenia/core/mmap_win.cc +++ b/src/xenia/core/mmap_win.cc @@ -21,7 +21,7 @@ typedef struct xe_mmap { } xe_mmap_t; -xe_mmap_ref xe_mmap_open(const xe_file_mode mode, const xechar_t *path, +xe_mmap_ref xe_mmap_open(const xe_file_mode mode, const wchar_t *path, const size_t offset, const size_t length) { xe_mmap_ref mmap = (xe_mmap_ref)xe_calloc(sizeof(xe_mmap_t)); xe_ref_init((xe_ref)mmap); diff --git a/src/xenia/cpu/xex_module.cc b/src/xenia/cpu/xex_module.cc index 05bc443ef..9532ef16f 100644 --- a/src/xenia/cpu/xex_module.cc +++ b/src/xenia/cpu/xex_module.cc @@ -114,12 +114,12 @@ int XexModule::SetupLibraryImports(const xe_xex2_import_library_t* library) { if (kernel_export) { if (info->thunk_address) { - xesnprintfa(name, poly::countof(name), "__imp_%s", kernel_export->name); + snprintf(name, poly::countof(name), "__imp_%s", kernel_export->name); } else { - xesnprintfa(name, poly::countof(name), "%s", kernel_export->name); + snprintf(name, poly::countof(name), "%s", kernel_export->name); } } else { - xesnprintfa(name, poly::countof(name), "__imp_%s_%.3X", library->name, + snprintf(name, poly::countof(name), "__imp_%s_%.3X", library->name, info->ordinal); } @@ -159,10 +159,10 @@ int XexModule::SetupLibraryImports(const xe_xex2_import_library_t* library) { if (info->thunk_address) { if (kernel_export) { - xesnprintfa(name, poly::countof(name), "%s", kernel_export->name); + snprintf(name, poly::countof(name), "%s", kernel_export->name); } else { - xesnprintfa(name, poly::countof(name), "__kernel_%s_%.3X", - library->name, info->ordinal); + snprintf(name, poly::countof(name), "__kernel_%s_%.3X", library->name, + info->ordinal); } // On load we have something like this in memory: @@ -423,7 +423,7 @@ int XexModule::FindSaveRest() { if (gplr_start) { uint64_t address = gplr_start; for (int n = 14; n <= 31; n++) { - xesnprintfa(name, poly::countof(name), "__savegprlr_%d", n); + snprintf(name, poly::countof(name), "__savegprlr_%d", n); FunctionInfo* symbol_info; DeclareFunction(address, &symbol_info); symbol_info->set_end_address(address + (31 - n) * 4 + 2 * 4); @@ -436,7 +436,7 @@ int XexModule::FindSaveRest() { } address = gplr_start + 20 * 4; for (int n = 14; n <= 31; n++) { - xesnprintfa(name, poly::countof(name), "__restgprlr_%d", n); + snprintf(name, poly::countof(name), "__restgprlr_%d", n); FunctionInfo* symbol_info; DeclareFunction(address, &symbol_info); symbol_info->set_end_address(address + (31 - n) * 4 + 3 * 4); @@ -451,7 +451,7 @@ int XexModule::FindSaveRest() { if (fpr_start) { uint64_t address = fpr_start; for (int n = 14; n <= 31; n++) { - xesnprintfa(name, poly::countof(name), "__savefpr_%d", n); + snprintf(name, poly::countof(name), "__savefpr_%d", n); FunctionInfo* symbol_info; DeclareFunction(address, &symbol_info); symbol_info->set_end_address(address + (31 - n) * 4 + 1 * 4); @@ -464,7 +464,7 @@ int XexModule::FindSaveRest() { } address = fpr_start + (18 * 4) + (1 * 4); for (int n = 14; n <= 31; n++) { - xesnprintfa(name, poly::countof(name), "__restfpr_%d", n); + snprintf(name, poly::countof(name), "__restfpr_%d", n); FunctionInfo* symbol_info; DeclareFunction(address, &symbol_info); symbol_info->set_end_address(address + (31 - n) * 4 + 1 * 4); @@ -484,7 +484,7 @@ int XexModule::FindSaveRest() { // 64-127 rest uint64_t address = vmx_start; for (int n = 14; n <= 31; n++) { - xesnprintfa(name, poly::countof(name), "__savevmx_%d", n); + snprintf(name, poly::countof(name), "__savevmx_%d", n); FunctionInfo* symbol_info; DeclareFunction(address, &symbol_info); symbol_info->set_name(name); @@ -496,7 +496,7 @@ int XexModule::FindSaveRest() { } address += 4; for (int n = 64; n <= 127; n++) { - xesnprintfa(name, poly::countof(name), "__savevmx_%d", n); + snprintf(name, poly::countof(name), "__savevmx_%d", n); FunctionInfo* symbol_info; DeclareFunction(address, &symbol_info); symbol_info->set_name(name); @@ -508,7 +508,7 @@ int XexModule::FindSaveRest() { } address = vmx_start + (18 * 2 * 4) + (1 * 4) + (64 * 2 * 4) + (1 * 4); for (int n = 14; n <= 31; n++) { - xesnprintfa(name, poly::countof(name), "__restvmx_%d", n); + snprintf(name, poly::countof(name), "__restvmx_%d", n); FunctionInfo* symbol_info; DeclareFunction(address, &symbol_info); symbol_info->set_name(name); @@ -520,7 +520,7 @@ int XexModule::FindSaveRest() { } address += 4; for (int n = 64; n <= 127; n++) { - xesnprintfa(name, poly::countof(name), "__restvmx_%d", n); + snprintf(name, poly::countof(name), "__restvmx_%d", n); FunctionInfo* symbol_info; DeclareFunction(address, &symbol_info); symbol_info->set_name(name); diff --git a/src/xenia/export_resolver.cc b/src/xenia/export_resolver.cc index 7f56d89a1..3cfa87710 100644 --- a/src/xenia/export_resolver.cc +++ b/src/xenia/export_resolver.cc @@ -11,92 +11,87 @@ #include -using namespace xe; +namespace xe { +ExportResolver::ExportResolver() {} -ExportResolver::ExportResolver() { -} +ExportResolver::~ExportResolver() {} -ExportResolver::~ExportResolver() { -} - -void ExportResolver::RegisterTable( - const char* library_name, KernelExport* exports, const size_t count) { - ExportTable table; - xestrcpya(table.name, poly::countof(table.name), library_name); - table.exports = exports; - table.count = count; - tables_.push_back(table); +void ExportResolver::RegisterTable(const std::string& library_name, + KernelExport* exports, const size_t count) { + tables_.emplace_back(library_name, exports, count); for (size_t n = 0; n < count; n++) { exports[n].is_implemented = false; exports[n].variable_ptr = 0; - exports[n].function_data.shim_data = NULL; - exports[n].function_data.shim = NULL; + exports[n].function_data.shim_data = nullptr; + exports[n].function_data.shim = nullptr; } } -uint16_t ExportResolver::GetLibraryOrdinal(const char* library_name) { +uint16_t ExportResolver::GetLibraryOrdinal(const std::string& library_name) { uint16_t n = 0; - for (auto it = tables_.begin(); it != tables_.end(); ++it, n++) { - if (!strcmp(library_name, it->name)) { + for (const auto& table : tables_) { + if (table.name != library_name) { return n; } + ++n; } return -1; } -KernelExport* ExportResolver::GetExportByOrdinal( - const uint16_t library_ordinal, const uint32_t ordinal) { - auto& table = tables_[library_ordinal]; +KernelExport* ExportResolver::GetExportByOrdinal(const uint16_t library_ordinal, + const uint32_t ordinal) { + const auto& table = tables_[library_ordinal]; // TODO(benvanik): binary search? for (size_t n = 0; n < table.count; n++) { if (table.exports[n].ordinal == ordinal) { return &table.exports[n]; } } - return NULL; + return nullptr; } -KernelExport* ExportResolver::GetExportByOrdinal(const char* library_name, - const uint32_t ordinal) { - for (std::vector::iterator it = tables_.begin(); - it != tables_.end(); ++it) { - if (!strcmp(library_name, it->name)) { +KernelExport* ExportResolver::GetExportByOrdinal( + const std::string& library_name, const uint32_t ordinal) { + for (const auto& table : tables_) { + if (table.name == library_name) { // TODO(benvanik): binary search? - for (size_t n = 0; n < it->count; n++) { - if (it->exports[n].ordinal == ordinal) { - return &it->exports[n]; + for (size_t n = 0; n < table.count; n++) { + if (table.exports[n].ordinal == ordinal) { + return &table.exports[n]; } } - return NULL; + return nullptr; } } - return NULL; + return nullptr; } -KernelExport* ExportResolver::GetExportByName(const char* library_name, - const char* name) { +KernelExport* ExportResolver::GetExportByName(const std::string& library_name, + const std::string& name) { // TODO(benvanik): lookup by name. assert_always(); - return NULL; + return nullptr; } -void ExportResolver::SetVariableMapping(const char* library_name, +void ExportResolver::SetVariableMapping(const std::string& library_name, const uint32_t ordinal, uint32_t value) { - KernelExport* kernel_export = GetExportByOrdinal(library_name, ordinal); + auto kernel_export = GetExportByOrdinal(library_name, ordinal); assert_not_null(kernel_export); kernel_export->is_implemented = true; kernel_export->variable_ptr = value; } -void ExportResolver::SetFunctionMapping( - const char* library_name, const uint32_t ordinal, - void* shim_data, xe_kernel_export_shim_fn shim) { - KernelExport* kernel_export = GetExportByOrdinal(library_name, ordinal); +void ExportResolver::SetFunctionMapping(const std::string& library_name, + const uint32_t ordinal, void* shim_data, + xe_kernel_export_shim_fn shim) { + auto kernel_export = GetExportByOrdinal(library_name, ordinal); assert_not_null(kernel_export); kernel_export->is_implemented = true; kernel_export->function_data.shim_data = shim_data; kernel_export->function_data.shim = shim; } + +} // namespace xe diff --git a/src/xenia/export_resolver.h b/src/xenia/export_resolver.h index 50d328209..057c80f37 100644 --- a/src/xenia/export_resolver.h +++ b/src/xenia/export_resolver.h @@ -12,36 +12,34 @@ #include +#include #include - typedef struct xe_ppc_state xe_ppc_state_t; - namespace xe { - typedef void (*xe_kernel_export_shim_fn)(xe_ppc_state_t*, void*); class KernelExport { -public: + public: enum ExportType { Function = 0, Variable = 1, }; - uint32_t ordinal; - ExportType type; - uint32_t flags; - char name[96]; + uint32_t ordinal; + ExportType type; + uint32_t flags; + char name[96]; - bool is_implemented; + bool is_implemented; union { // Variable data. Only valid when kXEKernelExportFlagVariable is set. // This is an address in the client memory space that the variable can // be found at. - uint32_t variable_ptr; + uint32_t variable_ptr; struct { // Second argument passed to the shim function. @@ -55,41 +53,40 @@ public: }; }; - class ExportResolver { -public: + public: ExportResolver(); ~ExportResolver(); - void RegisterTable(const char* library_name, KernelExport* exports, + void RegisterTable(const std::string& library_name, KernelExport* exports, const size_t count); - uint16_t GetLibraryOrdinal(const char* library_name); + uint16_t GetLibraryOrdinal(const std::string& library_name); KernelExport* GetExportByOrdinal(const uint16_t library_ordinal, const uint32_t ordinal); - KernelExport* GetExportByOrdinal(const char* library_name, + KernelExport* GetExportByOrdinal(const std::string& library_name, const uint32_t ordinal); - KernelExport* GetExportByName(const char* library_name, const char* name); + KernelExport* GetExportByName(const std::string& library_name, + const std::string& name); - void SetVariableMapping(const char* library_name, const uint32_t ordinal, - uint32_t value); - void SetFunctionMapping(const char* library_name, const uint32_t ordinal, - void* shim_data, xe_kernel_export_shim_fn shim); + void SetVariableMapping(const std::string& library_name, + const uint32_t ordinal, uint32_t value); + void SetFunctionMapping(const std::string& library_name, + const uint32_t ordinal, void* shim_data, + xe_kernel_export_shim_fn shim); -private: - class ExportTable { - public: - char name[32]; + private: + struct ExportTable { + std::string name; KernelExport* exports; - size_t count; + size_t count; + ExportTable(const std::string& name, KernelExport* exports, size_t count) + : name(name), exports(exports), count(count) {} }; - std::vector tables_; }; - } // namespace xe - #endif // XENIA_EXPORT_RESOLVER_H_ diff --git a/src/xenia/gpu/d3d11/d3d11_geometry_shader.cc b/src/xenia/gpu/d3d11/d3d11_geometry_shader.cc index 511d8dd93..64214e31a 100644 --- a/src/xenia/gpu/d3d11/d3d11_geometry_shader.cc +++ b/src/xenia/gpu/d3d11/d3d11_geometry_shader.cc @@ -99,10 +99,8 @@ ID3D10Blob* D3D11GeometryShader::Compile(const char* shader_source) { } uint64_t hash = hash64(shader_source, strlen(shader_source)); // ? char file_name[poly::max_path]; - xesnprintfa(file_name, poly::countof(file_name), - "%s/gen_%.16llX.gs", - base_path, - hash); + snprintf(file_name, poly::countof(file_name), "%s/gen_%.16llX.gs", base_path, + hash); if (FLAGS_dump_shaders.size()) { FILE* f = fopen(file_name, "w"); diff --git a/src/xenia/gpu/d3d11/d3d11_shader_resource.cc b/src/xenia/gpu/d3d11/d3d11_shader_resource.cc index e8bb26956..8e749ce47 100644 --- a/src/xenia/gpu/d3d11/d3d11_shader_resource.cc +++ b/src/xenia/gpu/d3d11/d3d11_shader_resource.cc @@ -50,11 +50,8 @@ ID3D10Blob* D3D11ShaderCompile(XE_GPU_SHADER_TYPE type, } size_t hash = hash64(disasm_source, strlen(disasm_source)); // ? char file_name[poly::max_path]; - xesnprintfa(file_name, poly::countof(file_name), - "%s/gen_%.16llX.%s", - base_path, - hash, - type == XE_GPU_SHADER_TYPE_VERTEX ? "vs" : "ps"); + snprintf(file_name, poly::countof(file_name), "%s/gen_%.16llX.%s", base_path, + hash, type == XE_GPU_SHADER_TYPE_VERTEX ? "vs" : "ps"); if (FLAGS_dump_shaders.size()) { FILE* f = fopen(file_name, "w"); diff --git a/src/xenia/gpu/d3d11/d3d11_shader_translator.h b/src/xenia/gpu/d3d11/d3d11_shader_translator.h index ad85c7775..1f8823cc1 100644 --- a/src/xenia/gpu/d3d11/d3d11_shader_translator.h +++ b/src/xenia/gpu/d3d11/d3d11_shader_translator.h @@ -48,8 +48,7 @@ private: void append(const char* format, ...) { va_list args; va_start(args, format); - int len = xevsnprintfa(buffer_ + offset_, capacity_ - offset_, - format, args); + int len = vsnprintf(buffer_ + offset_, capacity_ - offset_, format, args); va_end(args); offset_ += len; buffer_[offset_] = 0; diff --git a/src/xenia/gpu/xenos/ucode_disassembler.cc b/src/xenia/gpu/xenos/ucode_disassembler.cc index 0e0ac9875..92f7ad480 100644 --- a/src/xenia/gpu/xenos/ucode_disassembler.cc +++ b/src/xenia/gpu/xenos/ucode_disassembler.cc @@ -58,8 +58,7 @@ struct Output { void append(const char* format, ...) { va_list args; va_start(args, format); - int len = xevsnprintfa( - buffer + offset, capacity - offset, format, args); + int len = vsnprintf(buffer + offset, capacity - offset, format, args); va_end(args); offset += len; buffer[offset] = 0; diff --git a/src/xenia/kernel/fs/devices/disc_image_device.cc b/src/xenia/kernel/fs/devices/disc_image_device.cc index 0e282af49..9b5a381bc 100644 --- a/src/xenia/kernel/fs/devices/disc_image_device.cc +++ b/src/xenia/kernel/fs/devices/disc_image_device.cc @@ -56,34 +56,13 @@ Entry* DiscImageDevice::ResolvePath(const char* path) { GDFXEntry* gdfx_entry = gdfx_->root_entry(); // Walk the path, one separator at a time. - // We copy it into the buffer and shift it left over and over. - char remaining[poly::max_path]; - xestrcpya(remaining, poly::countof(remaining), path); - while (remaining[0]) { - char* next_slash = strchr(remaining, '\\'); - if (next_slash == remaining) { - // Leading slash - shift - xestrcpya(remaining, poly::countof(remaining), remaining + 1); - continue; - } - - // Make the buffer just the name. - if (next_slash) { - *next_slash = 0; - } - - // Look up in the entry. - gdfx_entry = gdfx_entry->GetChild(remaining); + auto path_parts = poly::split_path(path); + for (auto& part : path_parts) { + gdfx_entry = gdfx_entry->GetChild(part.c_str()); if (!gdfx_entry) { // Not found. - return NULL; + return nullptr; } - - // Shift the buffer down, unless we are at the end. - if (!next_slash) { - break; - } - xestrcpya(remaining, poly::countof(remaining), next_slash + 1); } Entry::Type type = gdfx_entry->attributes & X_FILE_ATTRIBUTE_DIRECTORY ? diff --git a/src/xenia/kernel/fs/devices/stfs_container_device.cc b/src/xenia/kernel/fs/devices/stfs_container_device.cc index 219d8bdee..7d58f1171 100644 --- a/src/xenia/kernel/fs/devices/stfs_container_device.cc +++ b/src/xenia/kernel/fs/devices/stfs_container_device.cc @@ -56,34 +56,13 @@ Entry* STFSContainerDevice::ResolvePath(const char* path) { STFSEntry* stfs_entry = stfs_->root_entry(); // Walk the path, one separator at a time. - // We copy it into the buffer and shift it left over and over. - char remaining[poly::max_path]; - xestrcpya(remaining, poly::countof(remaining), path); - while (remaining[0]) { - char* next_slash = strchr(remaining, '\\'); - if (next_slash == remaining) { - // Leading slash - shift - xestrcpya(remaining, poly::countof(remaining), remaining + 1); - continue; - } - - // Make the buffer just the name. - if (next_slash) { - *next_slash = 0; - } - - // Look up in the entry. - stfs_entry = stfs_entry->GetChild(remaining); + auto path_parts = poly::split_path(path); + for (auto& part : path_parts) { + stfs_entry = stfs_entry->GetChild(part.c_str()); if (!stfs_entry) { // Not found. - return NULL; + return nullptr; } - - // Shift the buffer down, unless we are at the end. - if (!next_slash) { - break; - } - xestrcpya(remaining, poly::countof(remaining), next_slash + 1); } Entry::Type type = stfs_entry->attributes & X_FILE_ATTRIBUTE_DIRECTORY ? diff --git a/src/xenia/kernel/objects/xthread.cc b/src/xenia/kernel/objects/xthread.cc index 646178c8a..65e5cb712 100644 --- a/src/xenia/kernel/objects/xthread.cc +++ b/src/xenia/kernel/objects/xthread.cc @@ -219,7 +219,7 @@ X_STATUS XThread::Create() { } char thread_name[32]; - xesnprintfa(thread_name, poly::countof(thread_name), "XThread%04X", handle()); + snprintf(thread_name, poly::countof(thread_name), "XThread%04X", handle()); set_name(thread_name); uint32_t proc_mask = creation_params_.creation_flags >> 24; diff --git a/src/xenia/kernel/util/xex2.cc b/src/xenia/kernel/util/xex2.cc index 23308e96b..fc2e0b15b 100644 --- a/src/xenia/kernel/util/xex2.cc +++ b/src/xenia/kernel/util/xex2.cc @@ -111,11 +111,6 @@ void xe_xex2_release(xe_xex2_ref xex) { xe_ref_release((xe_ref)xex, (xe_ref_dealloc_t)xe_xex2_dealloc); } -const xechar_t* xe_xex2_get_name(xe_xex2_ref xex) { - // TODO(benvanik): get name. - return NULL; -} - const xe_xex2_header_t* xe_xex2_get_header(xe_xex2_ref xex) { return &xex->header; } @@ -264,8 +259,8 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length, for (size_t i = 0, j = 0; i < string_table_size;) { assert_true(j <= 0xFF); if (j == name_index) { - xestrcpya(library->name, poly::countof(library->name), - string_table + i); + std::strncpy(library->name, string_table + i, + poly::countof(library->name)); break; } if (string_table[i] == 0) { diff --git a/src/xenia/kernel/util/xex2.h b/src/xenia/kernel/util/xex2.h index 4e865bd5d..f55b71caa 100644 --- a/src/xenia/kernel/util/xex2.h +++ b/src/xenia/kernel/util/xex2.h @@ -51,7 +51,6 @@ xe_xex2_ref xe_xex2_load(xe::Memory* memory, xe_xex2_ref xe_xex2_retain(xe_xex2_ref xex); void xe_xex2_release(xe_xex2_ref xex); -const xechar_t *xe_xex2_get_name(xe_xex2_ref xex); const xe_xex2_header_t *xe_xex2_get_header(xe_xex2_ref xex); const PESection* xe_xex2_get_pe_section(xe_xex2_ref xex, const char* name); diff --git a/src/xenia/logging.cc b/src/xenia/logging.cc index f585bddf1..dbabd593a 100644 --- a/src/xenia/logging.cc +++ b/src/xenia/logging.cc @@ -42,12 +42,13 @@ void xe_format_log_line( // Format string - add a trailing newline if required. const char* outfmt = "XE[%c] %s:%d: "; - char* buffer_ptr = buffer + xesnprintfa( - buffer, buffer_count - 1, outfmt, level_char, filename, line_number); + char* buffer_ptr = buffer + snprintf(buffer, buffer_count - 1, outfmt, + level_char, filename, line_number); // Scribble args into the print buffer. - buffer_ptr = buffer_ptr + xevsnprintfa( - buffer_ptr, buffer_count - (buffer_ptr - buffer) - 1, fmt, args); + buffer_ptr = buffer_ptr + vsnprintf(buffer_ptr, + buffer_count - (buffer_ptr - buffer) - 1, + fmt, args); // Add a trailing newline. if (buffer_ptr[-1] != '\n') { diff --git a/src/xenia/logging.h b/src/xenia/logging.h index 8e2f29fd5..2f55b5b3f 100644 --- a/src/xenia/logging.h +++ b/src/xenia/logging.h @@ -12,7 +12,7 @@ #include -#include +#include #define XE_OPTION_ENABLE_LOGGING 1 #define XE_OPTION_LOG_ERROR 1 diff --git a/src/xenia/profiling.h b/src/xenia/profiling.h index 88c63c994..d3102e980 100644 --- a/src/xenia/profiling.h +++ b/src/xenia/profiling.h @@ -12,7 +12,7 @@ #include -#include +#include #include #define XE_OPTION_PROFILING 1 diff --git a/src/xenia/sources.gypi b/src/xenia/sources.gypi index 0afc479e1..cec755d15 100644 --- a/src/xenia/sources.gypi +++ b/src/xenia/sources.gypi @@ -15,7 +15,6 @@ 'malloc.h', 'profiling.cc', 'profiling.h', - 'string.h', 'types.h', 'xbox.h', ], diff --git a/src/xenia/string.h b/src/xenia/string.h deleted file mode 100644 index 2a166ad78..000000000 --- a/src/xenia/string.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - ****************************************************************************** - * Xenia : Xbox 360 Emulator Research Project * - ****************************************************************************** - * Copyright 2013 Ben Vanik. All rights reserved. * - * Released under the BSD license - see LICENSE in the root for more details. * - ****************************************************************************** - */ - -#ifndef XENIA_STRING_H_ -#define XENIA_STRING_H_ - -#include - -// NOTE: these differing implementations should behave pretty much the same. -// If they don't, then they will have to be abstracted out. - -#if !XE_LIKE_WIN32 -int strncpy_s(char* dest, size_t destLength, const char* source, size_t count); -#define strcpy_s(dest, destLength, source) !(strcpy(dest, source) == dest + (destLength*0)) -#define _snprintf_s(dest, destLength, x, format, ...) snprintf(dest, destLength, format, ##__VA_ARGS__) -#endif // !WIN32 - -#define xesnprintfw(buffer, bufferCount, format, ...) _snwprintf_s(buffer, bufferCount, (bufferCount) ? (bufferCount - 1) : 0, format, ##__VA_ARGS__) - -#define xestrcpya(dest, destLength, source) (strcpy_s(dest, destLength, source) == 0) -#define xesnprintfa(buffer, bufferCount, format, ...) _snprintf_s(buffer, bufferCount, bufferCount, format, ##__VA_ARGS__) -#define xevsnprintfa(buffer, bufferCount, format, args) vsnprintf(buffer, bufferCount, format, args) - -#if XE_PLATFORM_WIN32 && defined(UNICODE) && UNICODE - -typedef wchar_t xechar_t; - -// xestrcpy fs + module -// xesnprintf many uses - only remove some? - -#define xesnprintf xesnprintfw - -#else - -typedef char xechar_t; - -#define xesnprintf xesnprintfa - -#endif // WIN32 - -#endif // XENIA_STRING_H_