ENSURES usage removed

This commit is contained in:
Nekotekina 2016-08-14 22:41:01 +03:00
parent b0f5796c90
commit 1f3433464c
9 changed files with 17 additions and 24 deletions

View file

@ -2283,7 +2283,7 @@ std::string named_thread::get_name() const
void named_thread::start_thread(const std::shared_ptr<void>& _this) void named_thread::start_thread(const std::shared_ptr<void>& _this)
{ {
// Ensure it's not called from the constructor and the correct object is passed // Ensure it's not called from the constructor and the correct object is passed
ENSURES(_this.get() == this); verify("named_thread::start_thread" HERE), _this.get() == this;
// Run thread // Run thread
thread_ctrl::spawn(m_thread, get_name(), [this, _this]() thread_ctrl::spawn(m_thread, get_name(), [this, _this]()

View file

@ -16,30 +16,27 @@ namespace memory_helper
void* reserve_memory(size_t size) void* reserve_memory(size_t size)
{ {
#ifdef _WIN32 #ifdef _WIN32
void* ret = VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS); return verify(VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS), "reserve_memory" HERE);
ENSURES(ret != NULL);
#else #else
void* ret = mmap(nullptr, size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); return verify(::mmap(nullptr, size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0), "reserve_memory" HERE);
ENSURES(ret != 0);
#endif #endif
return ret;
} }
void commit_page_memory(void* pointer, size_t size) void commit_page_memory(void* pointer, size_t size)
{ {
#ifdef _WIN32 #ifdef _WIN32
VERIFY(VirtualAlloc(pointer, size, MEM_COMMIT, PAGE_READWRITE) != NULL); verify(HERE), VirtualAlloc(pointer, size, MEM_COMMIT, PAGE_READWRITE);
#else #else
VERIFY(mprotect((void*)((u64)pointer & -4096), size, PROT_READ | PROT_WRITE) != -1); verify(HERE), ::mprotect((void*)((u64)pointer & -4096), size, PROT_READ | PROT_WRITE) != -1;
#endif #endif
} }
void free_reserved_memory(void* pointer, size_t size) void free_reserved_memory(void* pointer, size_t size)
{ {
#ifdef _WIN32 #ifdef _WIN32
VERIFY(VirtualFree(pointer, 0, MEM_DECOMMIT) != 0); verify(HERE), VirtualFree(pointer, 0, MEM_DECOMMIT);
#else #else
VERIFY(mprotect(pointer, size, PROT_NONE) != -1); verify(HERE), ::mprotect(pointer, size, PROT_NONE) != -1;
#endif #endif
} }
} }

View file

@ -58,14 +58,12 @@
#define HERE "\n(in file " __FILE__ ":" STRINGIZE(__LINE__) ")" #define HERE "\n(in file " __FILE__ ":" STRINGIZE(__LINE__) ")"
// Wrap an expression into lambda // Wrap an expression into lambda. Obsolete.
#define WRAP_EXPR(...) [&] { return __VA_ARGS__; } #define WRAP_EXPR(...) [&] { return __VA_ARGS__; }
// Ensure that the expression is evaluated to true. Always evaluated and allowed to have side effects (unlike assert() macro). // Ensure that the expression is evaluated to true. Obsolete.
#define VERIFY(...) do { if (!(__VA_ARGS__)) fmt::raw_error("Verification failed: " #__VA_ARGS__ HERE); } while (0) #define VERIFY(...) do { if (!(__VA_ARGS__)) fmt::raw_error("Verification failed: " #__VA_ARGS__ HERE); } while (0)
// EXPECTS() and ENSURES() are intended to check function arguments and results.
// Expressions are not guaranteed to evaluate.
#define EXPECTS(...) do { if (!(__VA_ARGS__)) fmt::raw_error("Precondition failed: " #__VA_ARGS__ HERE); } while (0) #define EXPECTS(...) do { if (!(__VA_ARGS__)) fmt::raw_error("Precondition failed: " #__VA_ARGS__ HERE); } while (0)
#define ENSURES(...) do { if (!(__VA_ARGS__)) fmt::raw_error("Postcondition failed: " #__VA_ARGS__ HERE); } while (0) #define ENSURES(...) do { if (!(__VA_ARGS__)) fmt::raw_error("Postcondition failed: " #__VA_ARGS__ HERE); } while (0)

View file

@ -249,9 +249,8 @@ SPUThread::SPUThread(const std::string& name, u32 index)
: cpu_thread() : cpu_thread()
, m_name(name) , m_name(name)
, index(index) , index(index)
, offset(vm::alloc(0x40000, vm::main)) , offset(verify(vm::alloc(0x40000, vm::main), __func__))
{ {
ENSURES(offset);
} }
void SPUThread::push_snr(u32 number, u32 value) void SPUThread::push_snr(u32 number, u32 value)

View file

@ -276,7 +276,6 @@ s32 sys_event_queue_receive(ppu_thread& ppu, u32 equeue_id, vm::ptr<sys_event_t>
if (ppu.gpr[3]) if (ppu.gpr[3])
{ {
ENSURES(!idm::check<lv2_event_queue_t>(equeue_id));
return CELL_ECANCELED; return CELL_ECANCELED;
} }

View file

@ -473,7 +473,7 @@ void CgBinaryDisasm::TaskFP()
break; break;
} }
ENSURES(m_step % sizeof(u32) == 0); verify(HERE), m_step % sizeof(u32) == 0;
data += m_step / sizeof(u32); data += m_step / sizeof(u32);
} }
} }

View file

@ -373,7 +373,7 @@ public:
m_offset = prog.ucode; m_offset = prog.ucode;
u32* vdata = (u32*)&m_buffer[m_offset]; u32* vdata = (u32*)&m_buffer[m_offset];
ENSURES((m_buffer_size - m_offset) % sizeof(u32) == 0); verify(HERE), (m_buffer_size - m_offset) % sizeof(u32) == 0;
for (u32 i = 0; i < (m_buffer_size - m_offset) / sizeof(u32); i++) for (u32 i = 0; i < (m_buffer_size - m_offset) / sizeof(u32); i++)
{ {
vdata[i] = se_storage<u32>::swap(vdata[i]); // WTF, cannot use be_t<> there? vdata[i] = se_storage<u32>::swap(vdata[i]); // WTF, cannot use be_t<> there?
@ -394,4 +394,4 @@ public:
u32 GetData(const u32 d) const { return d << 16 | d >> 16; } u32 GetData(const u32 d) const { return d << 16 | d >> 16; }
void TaskFP(); void TaskFP();
void TaskVP(); void TaskVP();
}; };

View file

@ -662,7 +662,7 @@ std::string FragmentProgramDecompiler::Decompile()
if (dst.end) break; if (dst.end) break;
ENSURES(m_offset % sizeof(u32) == 0); verify(HERE), m_offset % sizeof(u32) == 0;
data += m_offset / sizeof(u32); data += m_offset / sizeof(u32);
} }

View file

@ -44,13 +44,13 @@ HMODULE D3DCompiler;
void loadD3D12FunctionPointers() void loadD3D12FunctionPointers()
{ {
VERIFY(D3D12Module = LoadLibrary(L"d3d12.dll")); D3D12Module = verify(LoadLibrary(L"d3d12.dll"), "d3d12.dll");
wrapD3D12CreateDevice = (PFN_D3D12_CREATE_DEVICE)GetProcAddress(D3D12Module, "D3D12CreateDevice"); wrapD3D12CreateDevice = (PFN_D3D12_CREATE_DEVICE)GetProcAddress(D3D12Module, "D3D12CreateDevice");
wrapD3D12GetDebugInterface = (PFN_D3D12_GET_DEBUG_INTERFACE)GetProcAddress(D3D12Module, "D3D12GetDebugInterface"); wrapD3D12GetDebugInterface = (PFN_D3D12_GET_DEBUG_INTERFACE)GetProcAddress(D3D12Module, "D3D12GetDebugInterface");
wrapD3D12SerializeRootSignature = (PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)GetProcAddress(D3D12Module, "D3D12SerializeRootSignature"); wrapD3D12SerializeRootSignature = (PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)GetProcAddress(D3D12Module, "D3D12SerializeRootSignature");
VERIFY(D3D11Module = LoadLibrary(L"d3d11.dll")); D3D11Module = verify(LoadLibrary(L"d3d11.dll"), "d3d11.dll");
wrapD3D11On12CreateDevice = (PFN_D3D11ON12_CREATE_DEVICE)GetProcAddress(D3D11Module, "D3D11On12CreateDevice"); wrapD3D11On12CreateDevice = (PFN_D3D11ON12_CREATE_DEVICE)GetProcAddress(D3D11Module, "D3D11On12CreateDevice");
VERIFY(D3DCompiler = LoadLibrary(L"d3dcompiler_47.dll")); D3DCompiler = verify(LoadLibrary(L"d3dcompiler_47.dll"), "d3dcompiler_47.dll");
wrapD3DCompile = (pD3DCompile)GetProcAddress(D3DCompiler, "D3DCompile"); wrapD3DCompile = (pD3DCompile)GetProcAddress(D3DCompiler, "D3DCompile");
} }