(nw) get rid of the rest of assert_always - it's better to be explicit about what this thing is supposed to do

This commit is contained in:
Vas Crabb 2019-09-20 02:26:16 +10:00
parent 37b02ce7de
commit 8b233839ba
14 changed files with 80 additions and 58 deletions

View File

@ -399,8 +399,10 @@ CMDERR debugger_console::validate_command(const char *command)
void debugger_console::register_command(const char *command, u32 flags, int ref, int minparams, int maxparams, std::function<void(int, const std::vector<std::string> &)> handler)
{
assert_always(m_machine.phase() == machine_phase::INIT, "Can only call register_command() at init time!");
assert_always((m_machine.debug_flags & DEBUG_FLAG_ENABLED) != 0, "Cannot call register_command() when debugger is not running");
if (m_machine.phase() != machine_phase::INIT)
throw emu_fatalerror("Can only call debugger_console::register_command() at init time!");
if (!(m_machine.debug_flags & DEBUG_FLAG_ENABLED))
throw emu_fatalerror("Cannot call debugger_console::register_command() when debugger is not running");
debug_command *cmd = auto_alloc_clear(m_machine, <debug_command>());

View File

@ -31,7 +31,8 @@ void device_network_interface::interface_post_start()
int device_network_interface::send(u8 *buf, int len)
{
// TODO: enable this check when other devices implement delayed transmit
//assert_always(!m_send_timer->enabled(), "attempted to transmit while transmit already in progress");
//if (m_send_timer->enabled())
//throw emu_fatalerror("%s(%s): attempted to transmit while transmit already in progress", device().shortname(), device().tag());
int result = 0;
@ -65,7 +66,8 @@ TIMER_CALLBACK_MEMBER(device_network_interface::send_complete)
void device_network_interface::recv_cb(u8 *buf, int len)
{
assert_always(!m_recv_timer->enabled(), "attempted to receive while receive already in progress");
if (m_recv_timer->enabled())
throw emu_fatalerror("%s(%s): attempted to receive while receive already in progress", device().shortname(), device().tag());
int result = 0;

View File

@ -220,18 +220,6 @@ inline TYPE &operator|=(TYPE &a, TYPE b) { return a = a | b; }
#define FUNC(x) &x, #x
// standard assertion macros
#undef assert_always
#if defined(MAME_DEBUG_FAST)
#define assert_always(x, msg) do { if (!(x)) throw emu_fatalerror("%s\nCaused by assert: %s:%d: %s", msg, __FILE__, __LINE__, #x); } while (0)
#elif defined(MAME_DEBUG)
#define assert_always(x, msg) do { if (!(x)) throw emu_fatalerror("%s\nCaused by assert: %s:%d: %s", msg, __FILE__, __LINE__, #x); } while (0)
#else
#define assert_always(x, msg) do { if (!(x)) throw emu_fatalerror("%s (%s:%d)", msg, __FILE__, __LINE__); } while (0)
#endif
// macros to convert radians to degrees and degrees to radians
template <typename T> constexpr auto RADIAN_TO_DEGREE(T const &x) { return (180.0 / M_PI) * x; }
template <typename T> constexpr auto DEGREE_TO_RADIAN(T const &x) { return (M_PI / 180.0) * x; }

View File

@ -506,7 +506,8 @@ void palette_device::device_start()
const memory_share *share_ext = memshare(tag_ext.c_str());
// make sure we have specified a format
assert_always(m_raw_to_rgb.bytes_per_entry() > 0, "Palette has memory share but no format specified");
if (m_raw_to_rgb.bytes_per_entry() <= 0)
throw emu_fatalerror("palette_device(%s): Palette has memory share but no format specified", tag());
// determine bytes per entry and configure
int bytes_per_entry = m_raw_to_rgb.bytes_per_entry();
@ -522,7 +523,8 @@ void palette_device::device_start()
if (m_membits_supplied)
{
// forcing width only makes sense when narrower than the native bus width
assert_always(m_membits < share->bitwidth(), "Improper use of MCFG_PALETTE_MEMBITS");
if (m_membits >= share->bitwidth())
throw emu_fatalerror("palette_device(%s): Improper use of MCFG_PALETTE_MEMBITS", tag());
m_paletteram.set_membits(m_membits);
if (share_ext != nullptr)
m_paletteram_ext.set_membits(m_membits);
@ -532,7 +534,8 @@ void palette_device::device_start()
if (m_endianness_supplied)
{
// forcing endianness only makes sense when the RAM is narrower than the palette format and not split
assert_always((share_ext == nullptr && m_paletteram.membits() / 8 < bytes_per_entry), "Improper use of MCFG_PALETTE_ENDIANNESS");
if (share_ext || (m_paletteram.membits() / 8) >= bytes_per_entry)
throw emu_fatalerror("palette_device(%s): Improper use of MCFG_PALETTE_ENDIANNESS", tag());
m_paletteram.set_endianness(m_endianness);
}
}

View File

@ -277,7 +277,8 @@ input_device::~input_device()
input_item_id input_device::add_item(const char *name, input_item_id itemid, item_get_state_func getstate, void *internal)
{
assert_always(machine().phase() == machine_phase::INIT, "Can only call input_device::add_item at init time!");
if (machine().phase() != machine_phase::INIT)
throw emu_fatalerror("Can only call input_device::add_item at init time!");
assert(name != nullptr);
assert(itemid > ITEM_ID_INVALID && itemid < ITEM_ID_MAXIMUM);
assert(getstate != nullptr);
@ -494,7 +495,8 @@ input_class::~input_class()
input_device *input_class::add_device(const char *name, const char *id, void *internal)
{
assert_always(machine().phase() == machine_phase::INIT, "Can only call input_class::add_device at init time!");
if (machine().phase() != machine_phase::INIT)
throw emu_fatalerror("Can only call input_class::add_device at init time!");
assert(name != nullptr);
assert(id != nullptr);

View File

@ -1468,7 +1468,8 @@ ioport_field *ioport_port::field(ioport_value mask) const
ioport_value ioport_port::read()
{
assert_always(manager().safe_to_read(), "Input ports cannot be read at init time!");
if (!manager().safe_to_read())
throw emu_fatalerror("Input ports cannot be read at init time!");
// start with the digital state
ioport_value result = m_live->digital;
@ -2716,7 +2717,8 @@ void ioport_manager::record_init()
// open the record file
osd_file::error filerr = m_record_file.open(filename);
assert_always(filerr == osd_file::error::NONE, "Failed to open file for recording");
if (filerr != osd_file::error::NONE)
throw emu_fatalerror("ioport_manager::record_init: Failed to open file for recording");
// get the base time
system_time systime;
@ -2738,15 +2740,18 @@ void ioport_manager::record_init()
}
void ioport_manager::timecode_init() {
void ioport_manager::timecode_init()
{
// check if option -record_timecode is enabled
if (!machine().options().record_timecode()) {
if (!machine().options().record_timecode())
{
machine().video().set_timecode_enabled(false);
return;
}
// if no file, nothing to do
const char *record_filename = machine().options().record();
if (record_filename[0] == 0) {
if (record_filename[0] == 0)
{
machine().video().set_timecode_enabled(false);
return;
}
@ -2759,7 +2764,8 @@ void ioport_manager::timecode_init() {
osd_printf_info("Record input timecode file: %s\n", record_filename);
osd_file::error filerr = m_timecode_file.open(filename.c_str());
assert_always(filerr == osd_file::error::NONE, "Failed to open file for input timecode recording");
if (filerr != osd_file::error::NONE)
throw emu_fatalerror("ioport_manager::timecode_init: Failed to open file for input timecode recording");
m_timecode_file.puts(std::string("# ==========================================\n").c_str());
m_timecode_file.puts(std::string("# TIMECODE FILE FOR VIDEO PREVIEW GENERATION\n").c_str());

View File

@ -299,7 +299,8 @@ int running_machine::run(bool quiet)
{
m_logfile = std::make_unique<emu_file>(OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
osd_file::error filerr = m_logfile->open("error.log");
assert_always(filerr == osd_file::error::NONE, "unable to open log file");
if (filerr != osd_file::error::NONE)
throw emu_fatalerror("running_machine::run: unable to open log file");
using namespace std::placeholders;
add_logerror_callback(std::bind(&running_machine::logfile_callback, this, _1));
@ -771,9 +772,10 @@ void running_machine::toggle_pause()
void running_machine::add_notifier(machine_notification event, machine_notify_delegate callback, bool first)
{
assert_always(m_current_phase == machine_phase::INIT, "Can only call add_notifier at init time!");
if (m_current_phase != machine_phase::INIT)
throw emu_fatalerror("Can only call running_machine::add_notifier at init time!");
if(first)
if (first)
m_notifier_list[event].push_front(std::make_unique<notifier_callback_item>(callback));
// exit notifiers are added to the head, and executed in reverse order
@ -793,8 +795,9 @@ void running_machine::add_notifier(machine_notification event, machine_notify_de
void running_machine::add_logerror_callback(logerror_callback callback)
{
assert_always(m_current_phase == machine_phase::INIT, "Can only call add_logerror_callback at init time!");
m_string_buffer.reserve(1024);
if (m_current_phase != machine_phase::INIT)
throw emu_fatalerror("Can only call running_machine::add_logerror_callback at init time!");
m_string_buffer.reserve(1024);
m_logerror_list.push_back(std::make_unique<logerror_callback_item>(callback));
}

View File

@ -460,7 +460,8 @@ void render_texture::get_scaled(u32 dwidth, u32 dheight, render_texinfo &texinfo
for (scalenum = 0; scalenum < ARRAY_LENGTH(m_scaled); scalenum++)
if ((lowest == -1 || m_scaled[scalenum].seqid < m_scaled[lowest].seqid) && !primlist.has_reference(m_scaled[scalenum].bitmap))
lowest = scalenum;
assert_always(lowest != -1, "Too many live texture instances!");
if (-1 == lowest)
throw emu_fatalerror("render_texture::get_scaled: Too many live texture instances!");
// throw out any existing entries
scaled = &m_scaled[lowest];
@ -2711,7 +2712,8 @@ bool render_target::remove_clear_extent(const render_bounds &bounds)
// make a copy of this extent
memmove(&ext[ext[1] + 2], &ext[0], (last - ext) * sizeof(*ext));
last += ext[1] + 2;
assert_always(last < max, "Ran out of clear extents!\n");
if (last >= max)
throw emu_fatalerror("render_target::remove_clear_extent: Ran out of clear extents!");
// split the extent between pieces
ext[ext[1] + 2] = -(-ext[0] - diff);
@ -2731,7 +2733,8 @@ bool render_target::remove_clear_extent(const render_bounds &bounds)
// make a copy of this extent
memmove(&ext[ext[1] + 2], &ext[0], (last - ext) * sizeof(*ext));
last += ext[1] + 2;
assert_always(last < max, "Ran out of clear extents!\n");
if (last >= max)
throw emu_fatalerror("render_target::remove_clear_extent: Ran out of clear extents!");
// split the extent between pieces
ext[ext[1] + 2] = -diff;
@ -2756,7 +2759,8 @@ bool render_target::remove_clear_extent(const render_bounds &bounds)
memmove(&xext[2], &xext[0], (last - xext) * sizeof(*xext));
last += 2;
linelast += 2;
assert_always(last < max, "Ran out of clear extents!\n");
if (last >= max)
throw emu_fatalerror("render_target::remove_clear_extent: Ran out of clear extents!");
// split this extent into three parts
xext[0] = boundsx0 - x0;

View File

@ -1964,8 +1964,10 @@ void m2_cde_device::start_dma(uint32_t ch)
if (setup & CDE_DATAWIDTH_16)
{
// 16-bit case
assert_always((dma_ch.m_ccnt & 1) == 0, "16-bit DMA: Byte count must be even?");
assert_always((dma_ch.m_cpad & 1) == 0, "16-bit DMA: DMA destination must be word aligned?");
if (dma_ch.m_ccnt & 1)
throw emu_fatalerror("m2_cde_device::start_dma: 16-bit DMA: Byte count must be even?");
if (dma_ch.m_cpad & 1)
throw emu_fatalerror("m2_cde_device::start_dma: 16-bit DMA: DMA destination must be word aligned?");
const uint32_t srcinc = setup & CDE_READ_SETUP_IO ? 0 : 2;
@ -2012,7 +2014,8 @@ void m2_cde_device::next_dma(uint32_t ch)
m_cpu1->set_cache_dirty();
#endif
assert_always(dma_ch.m_ccnt == 0, "DMA count non-zero during next DMA");
if (dma_ch.m_ccnt != 0)
throw emu_fatalerror("m2_cde_device::next_dma: DMA count non-zero during next DMA");
if (dma_ch.m_cntl & CDE_DMA_NEXT_VALID)
{

View File

@ -691,9 +691,10 @@ private:
void start_dma(uint32_t ch);
void next_dma(uint32_t ch);
uint32_t address_to_biobus_slot(uint32_t addr) const
static uint32_t address_to_biobus_slot(uint32_t addr)
{
assert_always(addr >= 0x20000000 && addr <= 0x3fffffff, "Address not within BioBus address range");
if ((addr < 0x20000000) || (addr > 0x3fffffff))
throw emu_fatalerror("m2_cde_device::address_to_biobus_slot: Address not within BioBus address range");
return ((addr >> 24) >> 2) & 7;
}

View File

@ -670,16 +670,20 @@ sampling_profiler::~sampling_profiler()
void sampling_profiler::start()
{
// do the dance to get a handle to ourself
BOOL result = DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &m_target_thread,
THREAD_GET_CONTEXT | THREAD_SUSPEND_RESUME | THREAD_QUERY_INFORMATION, FALSE, 0);
assert_always(result, "Failed to get thread handle for main thread");
BOOL const result = DuplicateHandle(
GetCurrentProcess(), GetCurrentThread(),
GetCurrentProcess(), &m_target_thread,
THREAD_GET_CONTEXT | THREAD_SUSPEND_RESUME | THREAD_QUERY_INFORMATION, FALSE, 0);
if (!result)
throw emu_fatalerror("sampling_profiler::start: Failed to get thread handle for main thread");
// reset the exit flag
m_thread_exit = false;
// start the thread
m_thread = CreateThread(nullptr, 0, thread_entry, (LPVOID)this, 0, &m_thread_id);
assert_always(m_thread != nullptr, "Failed to create profiler thread\n");
if (!m_thread)
throw emu_fatalerror("sampling_profiler::start: Failed to create profiler thread");
// max out the priority
SetThreadPriority(m_thread, THREAD_PRIORITY_TIME_CRITICAL);

View File

@ -7,6 +7,9 @@
#include "modules/osdmodule.h"
#include <algorithm>
osd_module_manager::osd_module_manager()
{
for (int i=0; i<MAX_MODULES; i++)
@ -25,17 +28,15 @@ osd_module_manager::~osd_module_manager()
void osd_module_manager::register_module(const module_type &mod_type)
{
auto const slot = std::find(std::begin(m_modules), std::end(m_modules), nullptr);
if (std::end(m_modules) == slot)
throw emu_fatalerror("osd_module_manager::register_module: Module registration beyond MAX_MODULES!");
osd_module *module = mod_type();
if (module->probe())
{
osd_printf_verbose("===> registered module %s %s\n", module->name(), module->type());
int i;
for (i = 0; i < MAX_MODULES && m_modules[i] != nullptr; i++)
;
assert_always(i < MAX_MODULES, "Module registration beyond MAX_MODULES!");
m_modules[i] = module;
*slot = module;
}
else
{
@ -51,8 +52,8 @@ bool osd_module_manager::type_has_name(const char *type, const char *name) const
osd_module *osd_module_manager::get_module_generic(const char *type, const char *name)
{
int i = get_module_index(type, name);
if (i>=0)
int const i = get_module_index(type, name);
if (i >= 0)
return m_modules[i];
else
return nullptr;

View File

@ -178,14 +178,16 @@ public:
static const int FLAG_NEEDS_ASYNCBLIT = 0x0200;
osd_renderer(std::shared_ptr<osd_window> window, const int flags)
: m_sliders_dirty(false), m_window(window), m_flags(flags) { }
: m_sliders_dirty(false), m_window(window), m_flags(flags)
{ }
virtual ~osd_renderer() { }
std::shared_ptr<osd_window> assert_window() const
{
auto win = m_window.lock();
assert_always(win != nullptr, "Window weak_ptr is not available!");
if (!win)
throw emu_fatalerror("osd_renderer::assert_window: Window weak_ptr is not available!");
return win;
}

View File

@ -2026,10 +2026,11 @@ ogl_texture_info *renderer_ogl::texture_create(const render_texinfo *texsource,
m_texhash[i] = texture;
break;
}
assert_always(i < HASH_SIZE + OVERFLOW_SIZE, "texture hash exhausted ...");
if ((HASH_SIZE + OVERFLOW_SIZE) <= i)
throw emu_fatalerror("renderer_ogl::texture_create: texture hash exhausted ...");
}
if(m_usevbo)
if (m_usevbo)
{
// Generate And Bind The Texture Coordinate Buffer
pfn_glGenBuffers( 1, &(texture->texCoordBufferName) );