diff --git a/src/xenia/apu/apu.cc b/src/xenia/apu/apu.cc index 7c9b84adf..4bac1f732 100644 --- a/src/xenia/apu/apu.cc +++ b/src/xenia/apu/apu.cc @@ -10,22 +10,16 @@ #include #include - - using namespace xe; using namespace xe::apu; - -DEFINE_string(apu, "any", - "Audio system. Use: [any, nop, xaudio2]"); - +DEFINE_string(apu, "any", "Audio system. Use: [any, nop, xaudio2]"); #include -AudioSystem* xe::apu::CreateNop(Emulator* emulator) { +std::unique_ptr xe::apu::CreateNop(Emulator* emulator) { return xe::apu::nop::Create(emulator); } - #if XE_PLATFORM_WIN32 #include AudioSystem* xe::apu::CreateXAudio2(Emulator* emulator) { @@ -33,17 +27,16 @@ AudioSystem* xe::apu::CreateXAudio2(Emulator* emulator) { } #endif // WIN32 -AudioSystem* xe::apu::Create(Emulator* emulator) { +std::unique_ptr xe::apu::Create(Emulator* emulator) { if (FLAGS_apu.compare("nop") == 0) { return CreateNop(emulator); #if XE_PLATFORM_WIN32 - } - else if (FLAGS_apu.compare("xaudio2") == 0) { + } else if (FLAGS_apu.compare("xaudio2") == 0) { return CreateXAudio2(emulator); #endif // WIN32 } else { // Create best available. - AudioSystem* best = NULL; + std::unique_ptr best; #if XE_PLATFORM_WIN32 best = CreateXAudio2(emulator); diff --git a/src/xenia/apu/apu.h b/src/xenia/apu/apu.h index 9c39b5079..2a5178a3a 100644 --- a/src/xenia/apu/apu.h +++ b/src/xenia/apu/apu.h @@ -10,6 +10,8 @@ #ifndef XENIA_APU_APU_H_ #define XENIA_APU_APU_H_ +#include + #include namespace xe { @@ -19,12 +21,12 @@ class Emulator; namespace xe { namespace apu { -AudioSystem* Create(Emulator* emulator); +std::unique_ptr Create(Emulator* emulator); -AudioSystem* CreateNop(Emulator* emulator); +std::unique_ptr CreateNop(Emulator* emulator); #if XE_PLATFORM_WIN32 -AudioSystem* CreateXAudio2(Emulator* emulator); +std::unique_ptr CreateXAudio2(Emulator* emulator); #endif // WIN32 } // namespace apu diff --git a/src/xenia/apu/nop/nop_apu.cc b/src/xenia/apu/nop/nop_apu.cc index ecd2b4a67..1ab673338 100644 --- a/src/xenia/apu/nop/nop_apu.cc +++ b/src/xenia/apu/nop/nop_apu.cc @@ -11,34 +11,30 @@ #include - using namespace xe; using namespace xe::apu; using namespace xe::apu::nop; - namespace { - void InitializeIfNeeded(); - void CleanupOnShutdown(); +void InitializeIfNeeded(); +void CleanupOnShutdown(); - void InitializeIfNeeded() { - static bool has_initialized = false; - if (has_initialized) { - return; - } - has_initialized = true; - - // - - atexit(CleanupOnShutdown); +void InitializeIfNeeded() { + static bool has_initialized = false; + if (has_initialized) { + return; } + has_initialized = true; - void CleanupOnShutdown() { - } + // + + atexit(CleanupOnShutdown); } +void CleanupOnShutdown() {} +} -AudioSystem* xe::apu::nop::Create(Emulator* emulator) { +std::unique_ptr xe::apu::nop::Create(Emulator* emulator) { InitializeIfNeeded(); - return new NopAudioSystem(emulator); + return std::make_unique(emulator); } diff --git a/src/xenia/apu/nop/nop_apu.h b/src/xenia/apu/nop/nop_apu.h index d7df58711..2cc6e771b 100644 --- a/src/xenia/apu/nop/nop_apu.h +++ b/src/xenia/apu/nop/nop_apu.h @@ -10,6 +10,8 @@ #ifndef XENIA_APU_NOP_NOP_APU_H_ #define XENIA_APU_NOP_NOP_APU_H_ +#include + #include namespace xe { @@ -21,7 +23,7 @@ namespace apu { class AudioSystem; namespace nop { -AudioSystem* Create(Emulator* emulator); +std::unique_ptr Create(Emulator* emulator); } // namespace nop } // namespace apu diff --git a/src/xenia/apu/xaudio2/xaudio2_apu.cc b/src/xenia/apu/xaudio2/xaudio2_apu.cc index 06d10e43b..2c02ccb5f 100644 --- a/src/xenia/apu/xaudio2/xaudio2_apu.cc +++ b/src/xenia/apu/xaudio2/xaudio2_apu.cc @@ -11,34 +11,30 @@ #include - using namespace xe; using namespace xe::apu; using namespace xe::apu::xaudio2; - namespace { - void InitializeIfNeeded(); - void CleanupOnShutdown(); +void InitializeIfNeeded(); +void CleanupOnShutdown(); - void InitializeIfNeeded() { - static bool has_initialized = false; - if (has_initialized) { - return; - } - has_initialized = true; - - // - - atexit(CleanupOnShutdown); +void InitializeIfNeeded() { + static bool has_initialized = false; + if (has_initialized) { + return; } + has_initialized = true; - void CleanupOnShutdown() { - } + // + + atexit(CleanupOnShutdown); } +void CleanupOnShutdown() {} +} -AudioSystem* xe::apu::xaudio2::Create(Emulator* emulator) { +std::unique_ptr xe::apu::xaudio2::Create(Emulator* emulator) { InitializeIfNeeded(); - return new XAudio2AudioSystem(emulator); + return std::make_unique(emulator); } diff --git a/src/xenia/apu/xaudio2/xaudio2_apu.h b/src/xenia/apu/xaudio2/xaudio2_apu.h index 4b5a97bf7..565f93d01 100644 --- a/src/xenia/apu/xaudio2/xaudio2_apu.h +++ b/src/xenia/apu/xaudio2/xaudio2_apu.h @@ -10,24 +10,23 @@ #ifndef XENIA_APU_XAUDIO2_XAUDIO2_APU_H_ #define XENIA_APU_XAUDIO2_XAUDIO2_APU_H_ +#include + #include - -XEDECLARECLASS1(xe, Emulator); -XEDECLARECLASS2(xe, apu, AudioSystem); - +namespace xe { +class Emulator; +} // namespace xe namespace xe { namespace apu { +class AudioSystem; namespace xaudio2 { - -AudioSystem* Create(Emulator* emulator); - +std::unique_ptr Create(Emulator* emulator); } // namespace xaudio2 } // namespace apu } // namespace xe - #endif // XENIA_APU_XAUDIO2_XAUDIO2_APU_H_ diff --git a/src/xenia/common.h b/src/xenia/common.h index 821b83cc7..f20beaa90 100644 --- a/src/xenia/common.h +++ b/src/xenia/common.h @@ -18,6 +18,5 @@ #include #include -#include #endif // XENIA_COMMON_H_ diff --git a/src/xenia/core.h b/src/xenia/core.h index 6027d653d..5bf4ebbbe 100644 --- a/src/xenia/core.h +++ b/src/xenia/core.h @@ -17,4 +17,15 @@ #include #include +// TODO(benvanik): remove. +#define XEFAIL() goto XECLEANUP +#define XEEXPECTZERO(expr) \ + if ((expr) != 0) { \ + goto XECLEANUP; \ + } +#define XEEXPECTNOTNULL(expr) \ + if ((expr) == NULL) { \ + goto XECLEANUP; \ + } + #endif // XENIA_CORE_H_ diff --git a/src/xenia/emulator.cc b/src/xenia/emulator.cc index 81467ad67..484571271 100644 --- a/src/xenia/emulator.cc +++ b/src/xenia/emulator.cc @@ -33,18 +33,7 @@ using namespace xe::kernel::fs; using namespace xe::ui; Emulator::Emulator(const std::wstring& command_line) - : command_line_(command_line), - main_window_(0), - memory_(0), - processor_(0), - audio_system_(0), - graphics_system_(0), - input_system_(0), - export_resolver_(0), - file_system_(0), - kernel_state_(0), - xam_(0), - xboxkrnl_(0) {} + : command_line_(command_line) {} Emulator::~Emulator() { // Note that we delete things in the reverse order they were initialized. @@ -60,23 +49,23 @@ Emulator::~Emulator() { debug_agent_.reset(); - delete xam_; - delete xboxkrnl_; - delete kernel_state_; + xam_.reset(); + xboxkrnl_.reset(); + kernel_state_.reset(); - delete file_system_; + file_system_.reset(); - delete input_system_; + input_system_.reset(); // Give the systems time to shutdown before we delete them. graphics_system_->Shutdown(); audio_system_->Shutdown(); - delete graphics_system_; - delete audio_system_; + graphics_system_.reset(); + audio_system_.reset(); - delete processor_; + processor_.reset(); - delete export_resolver_; + export_resolver_.reset(); } X_STATUS Emulator::Setup() { @@ -84,63 +73,71 @@ X_STATUS Emulator::Setup() { debug_agent_.reset(new DebugAgent(this)); result = debug_agent_->Initialize(); - XEEXPECTZERO(result); + if (result) { + return result; + } // Create memory system first, as it is required for other systems. - memory_ = new Memory(); - XEEXPECTNOTNULL(memory_); + memory_ = std::make_unique(); result = memory_->Initialize(); - XEEXPECTZERO(result); + if (result) { + return result; + } memory_->set_trace_base(debug_agent_->trace_base()); // Shared export resolver used to attach and query for HLE exports. - export_resolver_ = new ExportResolver(); - XEEXPECTNOTNULL(export_resolver_); + export_resolver_ = std::make_unique(); // Initialize the CPU. - processor_ = new Processor(this); - XEEXPECTNOTNULL(processor_); + processor_ = std::make_unique(this); // Initialize the APU. - audio_system_ = xe::apu::Create(this); - XEEXPECTNOTNULL(audio_system_); + audio_system_ = std::move(xe::apu::Create(this)); + if (!audio_system_) { + return X_STATUS_NOT_IMPLEMENTED; + } // Initialize the GPU. - graphics_system_ = xe::gpu::Create(this); - XEEXPECTNOTNULL(graphics_system_); + graphics_system_ = std::move(xe::gpu::Create(this)); + if (!graphics_system_) { + return X_STATUS_NOT_IMPLEMENTED; + } // Initialize the HID. - input_system_ = xe::hid::Create(this); - XEEXPECTNOTNULL(input_system_); + input_system_ = std::move(xe::hid::Create(this)); + if (!input_system_) { + return X_STATUS_NOT_IMPLEMENTED; + } // Setup the core components. result = processor_->Setup(); - XEEXPECTZERO(result); + if (result) { + return result; + } result = audio_system_->Setup(); - XEEXPECTZERO(result); + if (result) { + return result; + } result = graphics_system_->Setup(); - XEEXPECTZERO(result); + if (result) { + return result; + } result = input_system_->Setup(); - XEEXPECTZERO(result); + if (result) { + return result; + } // Bring up the virtual filesystem used by the kernel. - file_system_ = new FileSystem(); - XEEXPECTNOTNULL(file_system_); + file_system_ = std::make_unique(); // Shared kernel state. - kernel_state_ = new KernelState(this); - XEEXPECTNOTNULL(kernel_state_); + kernel_state_ = std::make_unique(this); // HLE kernel modules. - xboxkrnl_ = new XboxkrnlModule(this, kernel_state_); - XEEXPECTNOTNULL(xboxkrnl_); - xam_ = new XamModule(this, kernel_state_); - XEEXPECTNOTNULL(xam_); + xboxkrnl_ = std::make_unique(this, kernel_state_); + xam_ = std::make_unique(this, kernel_state_); return result; - -XECLEANUP: - return result; } void Emulator::set_main_window(Window* window) { diff --git a/src/xenia/emulator.h b/src/xenia/emulator.h index 6da650108..dd07a2be3 100644 --- a/src/xenia/emulator.h +++ b/src/xenia/emulator.h @@ -54,20 +54,22 @@ class Emulator { ui::Window* main_window() const { return main_window_; } void set_main_window(ui::Window* window); - Memory* memory() const { return memory_; } + Memory* memory() const { return memory_.get(); } DebugAgent* debug_agent() const { return debug_agent_.get(); } - cpu::Processor* processor() const { return processor_; } - apu::AudioSystem* audio_system() const { return audio_system_; } - gpu::GraphicsSystem* graphics_system() const { return graphics_system_; } - hid::InputSystem* input_system() const { return input_system_; } + cpu::Processor* processor() const { return processor_.get(); } + apu::AudioSystem* audio_system() const { return audio_system_.get(); } + gpu::GraphicsSystem* graphics_system() const { + return graphics_system_.get(); + } + hid::InputSystem* input_system() const { return input_system_.get(); } - ExportResolver* export_resolver() const { return export_resolver_; } - kernel::fs::FileSystem* file_system() const { return file_system_; } + ExportResolver* export_resolver() const { return export_resolver_.get(); } + kernel::fs::FileSystem* file_system() const { return file_system_.get(); } - kernel::XboxkrnlModule* xboxkrnl() const { return xboxkrnl_; } - kernel::XamModule* xam() const { return xam_; } + kernel::XboxkrnlModule* xboxkrnl() const { return xboxkrnl_.get(); } + kernel::XamModule* xam() const { return xam_.get(); } X_STATUS Setup(); @@ -82,23 +84,24 @@ class Emulator { std::wstring command_line_; + // TODO(benvanik): remove from here? ui::Window* main_window_; - Memory* memory_; + std::unique_ptr memory_; std::unique_ptr debug_agent_; - cpu::Processor* processor_; - apu::AudioSystem* audio_system_; - gpu::GraphicsSystem* graphics_system_; - hid::InputSystem* input_system_; + std::unique_ptr processor_; + std::unique_ptr audio_system_; + std::unique_ptr graphics_system_; + std::unique_ptr input_system_; - ExportResolver* export_resolver_; - kernel::fs::FileSystem* file_system_; + std::unique_ptr export_resolver_; + std::unique_ptr file_system_; - kernel::KernelState* kernel_state_; - kernel::XamModule* xam_; - kernel::XboxkrnlModule* xboxkrnl_; + std::unique_ptr kernel_state_; + std::unique_ptr xam_; + std::unique_ptr xboxkrnl_; }; } // namespace xe diff --git a/src/xenia/gpu/d3d11/d3d11_gpu.cc b/src/xenia/gpu/d3d11/d3d11_gpu.cc index 52dd9a7b6..dbd5bc4c8 100644 --- a/src/xenia/gpu/d3d11/d3d11_gpu.cc +++ b/src/xenia/gpu/d3d11/d3d11_gpu.cc @@ -11,34 +11,30 @@ #include - using namespace xe; using namespace xe::gpu; using namespace xe::gpu::d3d11; - namespace { - void InitializeIfNeeded(); - void CleanupOnShutdown(); +void InitializeIfNeeded(); +void CleanupOnShutdown(); - void InitializeIfNeeded() { - static bool has_initialized = false; - if (has_initialized) { - return; - } - has_initialized = true; - - // - - atexit(CleanupOnShutdown); +void InitializeIfNeeded() { + static bool has_initialized = false; + if (has_initialized) { + return; } + has_initialized = true; - void CleanupOnShutdown() { - } + // + + atexit(CleanupOnShutdown); } +void CleanupOnShutdown() {} +} -GraphicsSystem* xe::gpu::d3d11::Create(Emulator* emulator) { +std::unique_ptr xe::gpu::d3d11::Create(Emulator* emulator) { InitializeIfNeeded(); - return new D3D11GraphicsSystem(emulator); + return std::make_unique(emulator); } diff --git a/src/xenia/gpu/d3d11/d3d11_gpu.h b/src/xenia/gpu/d3d11/d3d11_gpu.h index 5003c7afd..3ab0265e1 100644 --- a/src/xenia/gpu/d3d11/d3d11_gpu.h +++ b/src/xenia/gpu/d3d11/d3d11_gpu.h @@ -10,24 +10,23 @@ #ifndef XENIA_GPU_D3D11_D3D11_GPU_H_ #define XENIA_GPU_D3D11_D3D11_GPU_H_ +#include + #include - -XEDECLARECLASS1(xe, Emulator); -XEDECLARECLASS2(xe, gpu, GraphicsSystem); - +namespace xe { +class Emulator; +} // namespace xe namespace xe { namespace gpu { +class GraphicsSystem; namespace d3d11 { - -GraphicsSystem* Create(Emulator* emulator); - +std::unique_ptr Create(Emulator* emulator); } // namespace d3d11 } // namespace gpu } // namespace xe - #endif // XENIA_GPU_D3D11_D3D11_GPU_H_ diff --git a/src/xenia/gpu/gpu.cc b/src/xenia/gpu/gpu.cc index 102f2a488..11af8022e 100644 --- a/src/xenia/gpu/gpu.cc +++ b/src/xenia/gpu/gpu.cc @@ -10,37 +10,28 @@ #include #include - - using namespace xe; using namespace xe::gpu; +DEFINE_string(gpu, "any", "Graphics system. Use: [any, nop, d3d11]"); -DEFINE_string(gpu, "any", - "Graphics system. Use: [any, nop, d3d11]"); - - -DEFINE_bool(trace_ring_buffer, false, - "Trace GPU ring buffer packets."); +DEFINE_bool(trace_ring_buffer, false, "Trace GPU ring buffer packets."); DEFINE_string(dump_shaders, "", - "Path to write GPU shaders to as they are compiled."); - + "Path to write GPU shaders to as they are compiled."); #include -GraphicsSystem* xe::gpu::CreateNop(Emulator* emulator) { +std::unique_ptr xe::gpu::CreateNop(Emulator* emulator) { return xe::gpu::nop::Create(emulator); } - #if XE_PLATFORM_WIN32 #include -GraphicsSystem* xe::gpu::CreateD3D11(Emulator* emulator) { +std::unique_ptr xe::gpu::CreateD3D11(Emulator* emulator) { return xe::gpu::d3d11::Create(emulator); } #endif // WIN32 - -GraphicsSystem* xe::gpu::Create(Emulator* emulator) { +std::unique_ptr xe::gpu::Create(Emulator* emulator) { if (FLAGS_gpu.compare("nop") == 0) { return CreateNop(emulator); #if XE_PLATFORM_WIN32 @@ -49,7 +40,7 @@ GraphicsSystem* xe::gpu::Create(Emulator* emulator) { #endif // WIN32 } else { // Create best available. - GraphicsSystem* best = NULL; + std::unique_ptr best; #if XE_PLATFORM_WIN32 best = CreateD3D11(emulator); diff --git a/src/xenia/gpu/gpu.h b/src/xenia/gpu/gpu.h index 7015fef24..43690f1e2 100644 --- a/src/xenia/gpu/gpu.h +++ b/src/xenia/gpu/gpu.h @@ -10,6 +10,8 @@ #ifndef XENIA_GPU_GPU_H_ #define XENIA_GPU_GPU_H_ +#include + #include namespace xe { @@ -19,12 +21,12 @@ class Emulator; namespace xe { namespace gpu { -GraphicsSystem* Create(Emulator* emulator); +std::unique_ptr Create(Emulator* emulator); -GraphicsSystem* CreateNop(Emulator* emulator); +std::unique_ptr CreateNop(Emulator* emulator); #if XE_PLATFORM_WIN32 -GraphicsSystem* CreateD3D11(Emulator* emulator); +std::unique_ptr CreateD3D11(Emulator* emulator); #endif // WIN32 } // namespace gpu diff --git a/src/xenia/gpu/nop/nop_gpu.cc b/src/xenia/gpu/nop/nop_gpu.cc index d976f5fa4..e9281f404 100644 --- a/src/xenia/gpu/nop/nop_gpu.cc +++ b/src/xenia/gpu/nop/nop_gpu.cc @@ -11,34 +11,30 @@ #include - using namespace xe; using namespace xe::gpu; using namespace xe::gpu::nop; - namespace { - void InitializeIfNeeded(); - void CleanupOnShutdown(); +void InitializeIfNeeded(); +void CleanupOnShutdown(); - void InitializeIfNeeded() { - static bool has_initialized = false; - if (has_initialized) { - return; - } - has_initialized = true; - - // - - atexit(CleanupOnShutdown); +void InitializeIfNeeded() { + static bool has_initialized = false; + if (has_initialized) { + return; } + has_initialized = true; - void CleanupOnShutdown() { - } + // + + atexit(CleanupOnShutdown); } +void CleanupOnShutdown() {} +} -GraphicsSystem* xe::gpu::nop::Create(Emulator* emulator) { +std::unique_ptr xe::gpu::nop::Create(Emulator* emulator) { InitializeIfNeeded(); - return new NopGraphicsSystem(emulator); + return std::make_unique(emulator); } diff --git a/src/xenia/gpu/nop/nop_gpu.h b/src/xenia/gpu/nop/nop_gpu.h index c9dfd5ead..54de9d619 100644 --- a/src/xenia/gpu/nop/nop_gpu.h +++ b/src/xenia/gpu/nop/nop_gpu.h @@ -10,6 +10,8 @@ #ifndef XENIA_GPU_NOP_NOP_GPU_H_ #define XENIA_GPU_NOP_NOP_GPU_H_ +#include + #include namespace xe { @@ -21,7 +23,7 @@ namespace gpu { class GraphicsSystem; namespace nop { -GraphicsSystem* Create(Emulator* emulator); +std::unique_ptr Create(Emulator* emulator); } // namespace nop } // namespace gpu diff --git a/src/xenia/hid/hid.cc b/src/xenia/hid/hid.cc index fbd66630d..50fed497c 100644 --- a/src/xenia/hid/hid.cc +++ b/src/xenia/hid/hid.cc @@ -10,15 +10,10 @@ #include #include - - using namespace xe; using namespace xe::hid; - -DEFINE_string(hid, "any", - "Input system. Use: [any, nop, winkey, xinput]"); - +DEFINE_string(hid, "any", "Input system. Use: [any, nop, winkey, xinput]"); #include #if XE_PLATFORM_WIN32 @@ -26,41 +21,40 @@ DEFINE_string(hid, "any", #include #endif // WIN32 - -InputSystem* xe::hid::Create(Emulator* emulator) { - //return xe::hid::nop::Create(emulator); - InputSystem* input_system = new InputSystem(emulator); +std::unique_ptr xe::hid::Create(Emulator* emulator) { + std::unique_ptr input_system = + std::make_unique(emulator); if (FLAGS_hid.compare("nop") == 0) { - input_system->AddDriver(xe::hid::nop::Create(input_system)); + input_system->AddDriver(xe::hid::nop::Create(input_system.get())); #if XE_PLATFORM_WIN32 } else if (FLAGS_hid.compare("winkey") == 0) { - input_system->AddDriver(xe::hid::winkey::Create(input_system)); + input_system->AddDriver(xe::hid::winkey::Create(input_system.get())); } else if (FLAGS_hid.compare("xinput") == 0) { - input_system->AddDriver(xe::hid::xinput::Create(input_system)); + input_system->AddDriver(xe::hid::xinput::Create(input_system.get())); #endif // WIN32 } else { // Create all available. bool any_created = false; - // NOTE: in any mode we create as many as we can, falling back to nop. +// NOTE: in any mode we create as many as we can, falling back to nop. #if XE_PLATFORM_WIN32 - InputDriver* xinput_driver = xe::hid::xinput::Create(input_system); + auto xinput_driver = xe::hid::xinput::Create(input_system.get()); if (xinput_driver) { - input_system->AddDriver(xinput_driver); + input_system->AddDriver(std::move(xinput_driver)); any_created = true; } - InputDriver* winkey_driver = xe::hid::winkey::Create(input_system); + auto winkey_driver = xe::hid::winkey::Create(input_system.get()); if (winkey_driver) { - input_system->AddDriver(winkey_driver); + input_system->AddDriver(std::move(winkey_driver)); any_created = true; } #endif // WIN32 // Fallback to nop if none created. if (!any_created) { - input_system->AddDriver(xe::hid::nop::Create(input_system)); + input_system->AddDriver(xe::hid::nop::Create(input_system.get())); } } diff --git a/src/xenia/hid/hid.h b/src/xenia/hid/hid.h index 095dcfd9a..ca589e150 100644 --- a/src/xenia/hid/hid.h +++ b/src/xenia/hid/hid.h @@ -10,6 +10,8 @@ #ifndef XENIA_HID_HID_H_ #define XENIA_HID_HID_H_ +#include + #include namespace xe { @@ -19,7 +21,7 @@ class Emulator; namespace xe { namespace hid { -InputSystem* Create(Emulator* emulator); +std::unique_ptr Create(Emulator* emulator); } // namespace hid } // namespace xe diff --git a/src/xenia/hid/nop/nop_hid.cc b/src/xenia/hid/nop/nop_hid.cc index 520147285..86240e9ae 100644 --- a/src/xenia/hid/nop/nop_hid.cc +++ b/src/xenia/hid/nop/nop_hid.cc @@ -32,9 +32,9 @@ void InitializeIfNeeded() { void CleanupOnShutdown() {} -InputDriver* xe::hid::nop::Create(InputSystem* input_system) { +std::unique_ptr Create(InputSystem* input_system) { InitializeIfNeeded(); - return new NopInputDriver(input_system); + return std::make_unique(input_system); } } // namespace nop diff --git a/src/xenia/hid/nop/nop_hid.h b/src/xenia/hid/nop/nop_hid.h index 6080d159e..79c29aecd 100644 --- a/src/xenia/hid/nop/nop_hid.h +++ b/src/xenia/hid/nop/nop_hid.h @@ -10,6 +10,8 @@ #ifndef XENIA_HID_NOP_NOP_HID_H_ #define XENIA_HID_NOP_NOP_HID_H_ +#include + #include namespace xe { @@ -18,7 +20,7 @@ class InputDriver; class InputSystem; namespace nop { -InputDriver* Create(InputSystem* input_system); +std::unique_ptr Create(InputSystem* input_system); } // namespace nop } // namespace hid diff --git a/src/xenia/hid/winkey/winkey_hid.cc b/src/xenia/hid/winkey/winkey_hid.cc index f0fc06663..d837a6548 100644 --- a/src/xenia/hid/winkey/winkey_hid.cc +++ b/src/xenia/hid/winkey/winkey_hid.cc @@ -32,9 +32,9 @@ void InitializeIfNeeded() { void CleanupOnShutdown() {} -InputDriver* xe::hid::winkey::Create(InputSystem* input_system) { +std::unique_ptr Create(InputSystem* input_system) { InitializeIfNeeded(); - return new WinKeyInputDriver(input_system); + return std::make_unique(input_system); } } // namespace winkey diff --git a/src/xenia/hid/winkey/winkey_hid.h b/src/xenia/hid/winkey/winkey_hid.h index eac1fc9c5..b249d8b30 100644 --- a/src/xenia/hid/winkey/winkey_hid.h +++ b/src/xenia/hid/winkey/winkey_hid.h @@ -10,16 +10,17 @@ #ifndef XENIA_HID_WINKEY_WINKEY_HID_H_ #define XENIA_HID_WINKEY_WINKEY_HID_H_ -#include +#include -XEDECLARECLASS2(xe, hid, InputDriver); -XEDECLARECLASS2(xe, hid, InputSystem); +#include namespace xe { namespace hid { +class InputDriver; +class InputSystem; namespace winkey { -InputDriver* Create(InputSystem* input_system); +std::unique_ptr Create(InputSystem* input_system); } // namespace winkey } // namespace hid diff --git a/src/xenia/hid/xinput/xinput_hid.cc b/src/xenia/hid/xinput/xinput_hid.cc index 7850cf258..1535d9a19 100644 --- a/src/xenia/hid/xinput/xinput_hid.cc +++ b/src/xenia/hid/xinput/xinput_hid.cc @@ -32,9 +32,9 @@ void InitializeIfNeeded() { void CleanupOnShutdown() {} -InputDriver* xe::hid::xinput::Create(InputSystem* input_system) { +std::unique_ptr Create(InputSystem* input_system) { InitializeIfNeeded(); - return new XInputInputDriver(input_system); + return std::make_unique(input_system); } } // namespace xinput diff --git a/src/xenia/hid/xinput/xinput_hid.h b/src/xenia/hid/xinput/xinput_hid.h index 9e1194a7a..d6c8d78c9 100644 --- a/src/xenia/hid/xinput/xinput_hid.h +++ b/src/xenia/hid/xinput/xinput_hid.h @@ -10,16 +10,17 @@ #ifndef XENIA_HID_XINPUT_XINPUT_HID_H_ #define XENIA_HID_XINPUT_XINPUT_HID_H_ -#include +#include -XEDECLARECLASS2(xe, hid, InputDriver); -XEDECLARECLASS2(xe, hid, InputSystem); +#include namespace xe { namespace hid { +class InputDriver; +class InputSystem; namespace xinput { -InputDriver* Create(InputSystem* input_system); +std::unique_ptr Create(InputSystem* input_system); } // namespace xinput } // namespace hid diff --git a/src/xenia/kernel/fs/device.h b/src/xenia/kernel/fs/device.h index af24004da..eff460bf5 100644 --- a/src/xenia/kernel/fs/device.h +++ b/src/xenia/kernel/fs/device.h @@ -10,6 +10,7 @@ #ifndef XENIA_KERNEL_FS_DEVICE_H_ #define XENIA_KERNEL_FS_DEVICE_H_ +#include #include #include @@ -26,7 +27,7 @@ class Device { const std::string& path() const { return path_; } - virtual Entry* ResolvePath(const char* path) = 0; + virtual std::unique_ptr ResolvePath(const char* path) = 0; virtual X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) = 0; virtual X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info, diff --git a/src/xenia/kernel/fs/devices/disc_image_device.cc b/src/xenia/kernel/fs/devices/disc_image_device.cc index 9e9ab7efe..320e1332f 100644 --- a/src/xenia/kernel/fs/devices/disc_image_device.cc +++ b/src/xenia/kernel/fs/devices/disc_image_device.cc @@ -42,7 +42,7 @@ int DiscImageDevice::Init() { return 0; } -Entry* DiscImageDevice::ResolvePath(const char* path) { +std::unique_ptr DiscImageDevice::ResolvePath(const char* path) { // The filesystem will have stripped our prefix off already, so the path will // be in the form: // some\PATH.foo @@ -64,7 +64,8 @@ Entry* DiscImageDevice::ResolvePath(const char* path) { Entry::Type type = gdfx_entry->attributes & X_FILE_ATTRIBUTE_DIRECTORY ? Entry::Type::DIRECTORY : Entry::Type::FILE; - return new DiscImageEntry(type, this, path, mmap_.get(), gdfx_entry); + return std::make_unique(type, this, path, mmap_.get(), + gdfx_entry); } X_STATUS DiscImageDevice::QueryVolume(XVolumeInfo* out_info, size_t length) { diff --git a/src/xenia/kernel/fs/devices/disc_image_device.h b/src/xenia/kernel/fs/devices/disc_image_device.h index f1fb3fb4d..97b6feb41 100644 --- a/src/xenia/kernel/fs/devices/disc_image_device.h +++ b/src/xenia/kernel/fs/devices/disc_image_device.h @@ -31,7 +31,7 @@ class DiscImageDevice : public Device { int Init(); - Entry* ResolvePath(const char* path) override; + std::unique_ptr ResolvePath(const char* path) override; X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) override; X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info, diff --git a/src/xenia/kernel/fs/devices/disc_image_entry.cc b/src/xenia/kernel/fs/devices/disc_image_entry.cc index fb74c2842..cc1110355 100644 --- a/src/xenia/kernel/fs/devices/disc_image_entry.cc +++ b/src/xenia/kernel/fs/devices/disc_image_entry.cc @@ -96,23 +96,22 @@ X_STATUS DiscImageEntry::QueryDirectory(XDirectoryInfo* out_info, size_t length, return X_STATUS_SUCCESS; } -MemoryMapping* DiscImageEntry::CreateMemoryMapping(Mode map_mode, - const size_t offset, - const size_t length) { +std::unique_ptr DiscImageEntry::CreateMemoryMapping( + Mode map_mode, const size_t offset, const size_t length) { if (map_mode != Mode::READ) { // Only allow reads. - return NULL; + return nullptr; } size_t real_offset = gdfx_entry_->offset + offset; size_t real_length = length ? std::min(length, gdfx_entry_->size) : gdfx_entry_->size; - return new DiscImageMemoryMapping(mmap_->data() + real_offset, real_length, - mmap_); + return std::make_unique(mmap_->data() + real_offset, + real_length, mmap_); } -X_STATUS DiscImageEntry::Open(KernelState* kernel_state, Mode mode, - bool async, XFile** out_file) { +X_STATUS DiscImageEntry::Open(KernelState* kernel_state, Mode mode, bool async, + XFile** out_file) { *out_file = new DiscImageFile(kernel_state, mode, this); return X_STATUS_SUCCESS; } diff --git a/src/xenia/kernel/fs/devices/disc_image_entry.h b/src/xenia/kernel/fs/devices/disc_image_entry.h index 76c971d02..b1a076698 100644 --- a/src/xenia/kernel/fs/devices/disc_image_entry.h +++ b/src/xenia/kernel/fs/devices/disc_image_entry.h @@ -37,11 +37,11 @@ class DiscImageEntry : public Entry { const char* file_name, bool restart); virtual bool can_map() { return true; } - virtual MemoryMapping* CreateMemoryMapping(Mode map_mode, const size_t offset, - const size_t length); + virtual std::unique_ptr CreateMemoryMapping( + Mode map_mode, const size_t offset, const size_t length); - virtual X_STATUS Open(KernelState* kernel_state, Mode mode, - bool async, XFile** out_file); + virtual X_STATUS Open(KernelState* kernel_state, Mode mode, bool async, + XFile** out_file); private: poly::MappedMemory* mmap_; diff --git a/src/xenia/kernel/fs/devices/host_path_device.cc b/src/xenia/kernel/fs/devices/host_path_device.cc index 88d88ba12..d14852a91 100644 --- a/src/xenia/kernel/fs/devices/host_path_device.cc +++ b/src/xenia/kernel/fs/devices/host_path_device.cc @@ -22,7 +22,7 @@ HostPathDevice::HostPathDevice(const std::string& path, HostPathDevice::~HostPathDevice() {} -Entry* HostPathDevice::ResolvePath(const char* path) { +std::unique_ptr HostPathDevice::ResolvePath(const char* path) { // The filesystem will have stripped our prefix off already, so the path will // be in the form: // some\PATH.foo @@ -38,8 +38,7 @@ Entry* HostPathDevice::ResolvePath(const char* path) { // TODO(benvanik): switch based on type auto type = Entry::Type::FILE; - HostPathEntry* entry = new HostPathEntry(type, this, path, full_path); - return entry; + return std::make_unique(type, this, path, full_path); } // TODO(gibbed): call into HostPathDevice? diff --git a/src/xenia/kernel/fs/devices/host_path_device.h b/src/xenia/kernel/fs/devices/host_path_device.h index 0380508b2..bc662ada6 100644 --- a/src/xenia/kernel/fs/devices/host_path_device.h +++ b/src/xenia/kernel/fs/devices/host_path_device.h @@ -25,7 +25,7 @@ class HostPathDevice : public Device { HostPathDevice(const std::string& path, const std::wstring& local_path); ~HostPathDevice() override; - Entry* ResolvePath(const char* path) override; + std::unique_ptr ResolvePath(const char* path) override; X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) override; X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info, diff --git a/src/xenia/kernel/fs/devices/host_path_entry.cc b/src/xenia/kernel/fs/devices/host_path_entry.cc index 783c12119..037bb4f2d 100644 --- a/src/xenia/kernel/fs/devices/host_path_entry.cc +++ b/src/xenia/kernel/fs/devices/host_path_entry.cc @@ -121,9 +121,8 @@ X_STATUS HostPathEntry::QueryDirectory(XDirectoryInfo* out_info, size_t length, return X_STATUS_SUCCESS; } -MemoryMapping* HostPathEntry::CreateMemoryMapping(Mode map_mode, - const size_t offset, - const size_t length) { +std::unique_ptr HostPathEntry::CreateMemoryMapping( + Mode map_mode, const size_t offset, const size_t length) { auto mmap = poly::MappedMemory::Open( local_path_, map_mode == Mode::READ ? poly::MappedMemory::Mode::READ @@ -133,13 +132,11 @@ MemoryMapping* HostPathEntry::CreateMemoryMapping(Mode map_mode, return nullptr; } - HostPathMemoryMapping* lfmm = new HostPathMemoryMapping(std::move(mmap)); - - return lfmm; + return std::make_unique(std::move(mmap)); } -X_STATUS HostPathEntry::Open(KernelState* kernel_state, Mode mode, - bool async, XFile** out_file) { +X_STATUS HostPathEntry::Open(KernelState* kernel_state, Mode mode, bool async, + XFile** out_file) { DWORD desired_access = mode == Mode::READ ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE); DWORD share_mode = FILE_SHARE_READ; diff --git a/src/xenia/kernel/fs/devices/host_path_entry.h b/src/xenia/kernel/fs/devices/host_path_entry.h index b7624ffdf..913ece216 100644 --- a/src/xenia/kernel/fs/devices/host_path_entry.h +++ b/src/xenia/kernel/fs/devices/host_path_entry.h @@ -31,8 +31,8 @@ class HostPathEntry : public Entry { const char* file_name, bool restart); virtual bool can_map() { return true; } - virtual MemoryMapping* CreateMemoryMapping(Mode map_mode, const size_t offset, - const size_t length); + virtual std::unique_ptr CreateMemoryMapping( + Mode map_mode, const size_t offset, const size_t length); virtual X_STATUS Open(KernelState* kernel_state, Mode mode, bool async, XFile** out_file); diff --git a/src/xenia/kernel/fs/devices/stfs_container_device.cc b/src/xenia/kernel/fs/devices/stfs_container_device.cc index 98cab9dc8..c562ea1fa 100644 --- a/src/xenia/kernel/fs/devices/stfs_container_device.cc +++ b/src/xenia/kernel/fs/devices/stfs_container_device.cc @@ -42,7 +42,7 @@ int STFSContainerDevice::Init() { return 0; } -Entry* STFSContainerDevice::ResolvePath(const char* path) { +std::unique_ptr STFSContainerDevice::ResolvePath(const char* path) { // The filesystem will have stripped our prefix off already, so the path will // be in the form: // some\PATH.foo @@ -64,7 +64,8 @@ Entry* STFSContainerDevice::ResolvePath(const char* path) { Entry::Type type = stfs_entry->attributes & X_FILE_ATTRIBUTE_DIRECTORY ? Entry::Type::DIRECTORY : Entry::Type::FILE; - return new STFSContainerEntry(type, this, path, mmap_.get(), stfs_entry); + return std::make_unique(type, this, path, mmap_.get(), + stfs_entry); } X_STATUS STFSContainerDevice::QueryVolume(XVolumeInfo* out_info, diff --git a/src/xenia/kernel/fs/devices/stfs_container_device.h b/src/xenia/kernel/fs/devices/stfs_container_device.h index b5368bf97..0022e6545 100644 --- a/src/xenia/kernel/fs/devices/stfs_container_device.h +++ b/src/xenia/kernel/fs/devices/stfs_container_device.h @@ -31,7 +31,7 @@ class STFSContainerDevice : public Device { int Init(); - Entry* ResolvePath(const char* path) override; + std::unique_ptr ResolvePath(const char* path) override; X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) override; X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info, diff --git a/src/xenia/kernel/fs/entry.h b/src/xenia/kernel/fs/entry.h index 1e3c9e0e7..e9082d6b4 100644 --- a/src/xenia/kernel/fs/entry.h +++ b/src/xenia/kernel/fs/entry.h @@ -10,6 +10,7 @@ #ifndef XENIA_KERNEL_FS_ENTRY_H_ #define XENIA_KERNEL_FS_ENTRY_H_ +#include #include #include @@ -72,8 +73,8 @@ class Entry { virtual bool can_map() { return false; } - virtual MemoryMapping* CreateMemoryMapping(Mode map_mode, const size_t offset, - const size_t length) { + virtual std::unique_ptr CreateMemoryMapping( + Mode map_mode, const size_t offset, const size_t length) { return NULL; } diff --git a/src/xenia/kernel/fs/filesystem.cc b/src/xenia/kernel/fs/filesystem.cc index 0b9054359..8499c3185 100644 --- a/src/xenia/kernel/fs/filesystem.cc +++ b/src/xenia/kernel/fs/filesystem.cc @@ -142,7 +142,7 @@ int FileSystem::DeleteSymbolicLink(const std::string& path) { return 0; } -Entry* FileSystem::ResolvePath(const std::string& path) { +std::unique_ptr FileSystem::ResolvePath(const std::string& path) { // Strip off prefix and pass to device. // e.g., d:\some\PATH.foo -> some\PATH.foo // Support both symlinks and device specifiers, like: @@ -173,7 +173,7 @@ Entry* FileSystem::ResolvePath(const std::string& path) { } XELOGE("ResolvePath(%s) failed - no root found", path.c_str()); - return NULL; + return nullptr; } } // namespace fs diff --git a/src/xenia/kernel/fs/filesystem.h b/src/xenia/kernel/fs/filesystem.h index de0107fac..c785966be 100644 --- a/src/xenia/kernel/fs/filesystem.h +++ b/src/xenia/kernel/fs/filesystem.h @@ -10,6 +10,7 @@ #ifndef XENIA_KERNEL_FS_FILESYSTEM_H_ #define XENIA_KERNEL_FS_FILESYSTEM_H_ +#include #include #include #include @@ -50,7 +51,7 @@ class FileSystem { int CreateSymbolicLink(const std::string& path, const std::string& target); int DeleteSymbolicLink(const std::string& path); - Entry* ResolvePath(const std::string& path); + std::unique_ptr ResolvePath(const std::string& path); private: std::vector devices_; diff --git a/src/xenia/kernel/objects/xuser_module.cc b/src/xenia/kernel/objects/xuser_module.cc index 634da5530..164f407ad 100644 --- a/src/xenia/kernel/objects/xuser_module.cc +++ b/src/xenia/kernel/objects/xuser_module.cc @@ -33,41 +33,33 @@ const xe_xex2_header_t* XUserModule::xex_header() { X_STATUS XUserModule::LoadFromFile(const char* path) { X_STATUS result = X_STATUS_UNSUCCESSFUL; XFile* file = NULL; - uint8_t* buffer = 0; // Resolve the file to open. // TODO(benvanik): make this code shared? - fs::Entry* fs_entry = kernel_state()->file_system()->ResolvePath(path); + auto fs_entry = kernel_state()->file_system()->ResolvePath(path); if (!fs_entry) { XELOGE("File not found: %s", path); - result = X_STATUS_NO_SUCH_FILE; - XEFAIL(); + return X_STATUS_NO_SUCH_FILE; } if (fs_entry->type() != fs::Entry::Type::FILE) { XELOGE("Invalid file type: %s", path); - result = X_STATUS_NO_SUCH_FILE; - XEFAIL(); + return X_STATUS_NO_SUCH_FILE; } // If the FS supports mapping, map the file in and load from that. if (fs_entry->can_map()) { // Map. - fs::MemoryMapping* mmap = - fs_entry->CreateMemoryMapping(fs::Mode::READ, 0, 0); + auto mmap = fs_entry->CreateMemoryMapping(fs::Mode::READ, 0, 0); XEEXPECTNOTNULL(mmap); // Load the module. result = LoadFromMemory(mmap->address(), mmap->length()); - - // Unmap memory and cleanup. - delete mmap; } else { XFileInfo file_info; result = fs_entry->QueryInfo(&file_info); XEEXPECTZERO(result); - size_t buffer_length = file_info.file_length; - buffer = (uint8_t*)malloc(buffer_length); + std::vector buffer(file_info.file_length); // Open file for reading. result = fs_entry->Open(kernel_state(), fs::Mode::READ, false, &file); @@ -76,21 +68,17 @@ X_STATUS XUserModule::LoadFromFile(const char* path) { // Read entire file into memory. // Ugh. size_t bytes_read = 0; - result = file->Read(buffer, buffer_length, 0, &bytes_read); + result = file->Read(buffer.data(), buffer.size(), 0, &bytes_read); XEEXPECTZERO(result); // Load the module. - result = LoadFromMemory(buffer, bytes_read); + result = LoadFromMemory(buffer.data(), bytes_read); } XECLEANUP: - if (buffer) { - free(buffer); - } if (file) { file->Release(); } - delete fs_entry; return result; } diff --git a/src/xenia/kernel/xboxkrnl_io.cc b/src/xenia/kernel/xboxkrnl_io.cc index 06da957b9..7b8dfcab3 100644 --- a/src/xenia/kernel/xboxkrnl_io.cc +++ b/src/xenia/kernel/xboxkrnl_io.cc @@ -81,7 +81,7 @@ SHIM_CALL NtCreateFile_shim(PPCContext* ppc_state, KernelState* state) { uint32_t handle; FileSystem* fs = state->file_system(); - Entry* entry; + std::unique_ptr entry; XFile* root_file = NULL; if (attrs.root_directory != 0xFFFFFFFD && // ObDosDevices @@ -93,10 +93,10 @@ SHIM_CALL NtCreateFile_shim(PPCContext* ppc_state, KernelState* state) { auto root_path = root_file->absolute_path(); auto target_path = root_path + object_name; - entry = fs->ResolvePath(target_path); + entry = std::move(fs->ResolvePath(target_path)); } else { // Resolve the file using the virtual file system. - entry = fs->ResolvePath(object_name); + entry = std::move(fs->ResolvePath(object_name)); } auto mode = @@ -169,7 +169,7 @@ SHIM_CALL NtOpenFile_shim(PPCContext* ppc_state, KernelState* state) { // Resolve the file using the virtual file system. FileSystem* fs = state->file_system(); - Entry* entry = fs->ResolvePath(object_name); + auto entry = fs->ResolvePath(object_name); XFile* file = NULL; if (entry && entry->type() == Entry::Type::FILE) { // Open the file. @@ -480,7 +480,7 @@ SHIM_CALL NtQueryFullAttributesFile_shim(PPCContext* ppc_state, // Resolve the file using the virtual file system. FileSystem* fs = state->file_system(); - Entry* entry = fs->ResolvePath(object_name); + auto entry = fs->ResolvePath(object_name); if (entry && entry->type() == Entry::Type::FILE) { // Found. XFileInfo file_info; diff --git a/src/xenia/memory.cc b/src/xenia/memory.cc index 4ee269353..bd216231a 100644 --- a/src/xenia/memory.cc +++ b/src/xenia/memory.cc @@ -147,7 +147,6 @@ int Memory::Initialize() { if (result) { return result; } - result = 1; // Create main page file-backed mapping. This is all reserved but // uncommitted (so it shouldn't expand page file). @@ -165,7 +164,7 @@ int Memory::Initialize() { if (!mapping_) { XELOGE("Unable to reserve the 4gb guest address space."); assert_not_null(mapping_); - XEFAIL(); + return 1; } // Attempt to create our views. This may fail at the first address @@ -181,7 +180,7 @@ int Memory::Initialize() { if (!mapping_base_) { XELOGE("Unable to find a continuous block in the 64bit address space."); assert_always(); - XEFAIL(); + return 1; } membase_ = mapping_base_; @@ -200,7 +199,7 @@ int Memory::Initialize() { if (!mmio_handler_) { XELOGE("Unable to install MMIO handlers"); assert_always(); - XEFAIL(); + return 1; } // Allocate dirty page table. @@ -210,9 +209,6 @@ int Memory::Initialize() { X_MEM_COMMIT, 16 * 1024); return 0; - -XECLEANUP: - return result; } const static struct { @@ -243,13 +239,13 @@ int Memory::MapViews(uint8_t* mapping_base) { PROT_NONE, MAP_SHARED | MAP_FIXED, mapping_, map_info[n].target_address)); #endif // XE_PLATFORM_WIN32 - XEEXPECTNOTNULL(views_.all_views[n]); + if (!views_.all_views[n]) { + // Failed, so bail and try again. + UnmapViews(); + return 1; + } } return 0; - -XECLEANUP: - UnmapViews(); - return 1; } void Memory::UnmapViews() { diff --git a/src/xenia/sources.gypi b/src/xenia/sources.gypi index 23345750f..5f85ac199 100644 --- a/src/xenia/sources.gypi +++ b/src/xenia/sources.gypi @@ -15,7 +15,6 @@ 'memory.h', 'profiling.cc', 'profiling.h', - 'types.h', 'xbox.h', ], diff --git a/src/xenia/types.h b/src/xenia/types.h deleted file mode 100644 index ad208a60d..000000000 --- a/src/xenia/types.h +++ /dev/null @@ -1,43 +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_TYPES_H_ -#define XENIA_TYPES_H_ - -#define XEFAIL() goto XECLEANUP -#define XEEXPECT(expr) \ - if (!(expr)) { \ - goto XECLEANUP; \ - } -#define XEEXPECTTRUE(expr) \ - if (!(expr)) { \ - goto XECLEANUP; \ - } -#define XEEXPECTFALSE(expr) \ - if ((expr)) { \ - goto XECLEANUP; \ - } -#define XEEXPECTZERO(expr) \ - if ((expr) != 0) { \ - goto XECLEANUP; \ - } -#define XEEXPECTNOTZERO(expr) \ - if ((expr) == 0) { \ - goto XECLEANUP; \ - } -#define XEEXPECTNULL(expr) \ - if ((expr) != NULL) { \ - goto XECLEANUP; \ - } -#define XEEXPECTNOTNULL(expr) \ - if ((expr) == NULL) { \ - goto XECLEANUP; \ - } - -#endif // XENIA_TYPES_H_