Commit 56e788d5 authored by Libretro-Admin's avatar Libretro-Admin
Browse files

Get rid of a bunch of try/catches - get rid of what() function

parent 83be5723
Pipeline #44480 passed with stage
in 42 seconds
......@@ -94,14 +94,7 @@ static MDFN_COLD void Cleanup(void)
if(affinity_save)
{
try
{
MThreading::Thread_SetAffinity(nullptr, affinity_save);
}
catch(std::exception& e)
{
MDFND_OutputNotice(MDFN_NOTICE_ERROR, e.what());
}
MThreading::Thread_SetAffinity(nullptr, affinity_save);
//
affinity_save = 0;
}
......@@ -453,8 +446,6 @@ RETRO_API void retro_run(void)
{
for(auto const& cfie : cgi->CheatInfo.CheatFormatInfo)
{
try
{
if(!cfie.DecodeCheat(Cheats[i], &mp))
{
MDFNI_AddCheat(mp);
......@@ -462,11 +453,6 @@ RETRO_API void retro_run(void)
mp = MemoryPatch();
}
break;
}
catch(...)
{
mp = MemoryPatch();
}
}
}
......@@ -515,17 +501,9 @@ RETRO_API bool retro_serialize(void* data, size_t size)
{
assert(data);
//
try
{
ExtMemStream ssms(data, size);
ExtMemStream ssms(data, size);
MDFNI_SaveState(&ssms);
}
catch(std::exception& e)
{
MDFND_OutputNotice(MDFN_NOTICE_ERROR, e.what());
return false;
}
MDFNI_SaveState(&ssms);
return true;
}
......@@ -534,17 +512,9 @@ RETRO_API bool retro_unserialize(const void* data, size_t size)
{
assert(data);
//
try
{
ExtMemStream ssms(data, size);
ExtMemStream ssms(data, size);
MDFNI_LoadState(&ssms);
}
catch(std::exception& e)
{
MDFND_OutputNotice(MDFN_NOTICE_ERROR, e.what());
return false;
}
MDFNI_LoadState(&ssms);
return true;
}
......@@ -554,8 +524,6 @@ MDFN_COLD RETRO_API bool retro_load_game(const retro_game_info* game)
assert(game);
assert(game->data);
//
try
{
MDFN_PixelFormat nf(MDFN_COLORSPACE_RGB, 16, 8, 0, 24);
ports_active = 2;
......@@ -741,14 +709,6 @@ MDFN_COLD RETRO_API bool retro_load_game(const retro_game_info* game)
}
//
options_defaults.clear();
}
catch(std::exception& e)
{
Cleanup();
//
MDFND_OutputNotice(MDFN_NOTICE_ERROR, e.what());
return false;
}
return true;
}
......
......@@ -35,17 +35,7 @@ class FileStream : public Stream
// Convenience function so we don't need so many try { } catch { } for ENOENT
static INLINE FileStream* open(const std::string& path, const uint32 mode)
{
try
{
return new FileStream(path, mode);
}
catch(MDFN_Error& e)
{
if(e.GetErrno() == ENOENT)
return nullptr;
throw;
}
}
enum
......
......@@ -60,22 +60,14 @@ int MTStreamReader::read_thread_entry_(void* data)
MTStreamReader::MTStreamReader(const uint64 affinity)
{
try
{
command_sem = MThreading::Sem_Create();
ack_sem = MThreading::Sem_Create();
thread = MThreading::Thread_Create(read_thread_entry_, this);
if(affinity)
MThreading::Thread_SetAffinity(thread, affinity);
pending_command = Command_NOP;
MThreading::Sem_Post(command_sem);
}
catch(...)
{
cleanup();
throw;
}
command_sem = MThreading::Sem_Create();
ack_sem = MThreading::Sem_Create();
thread = MThreading::Thread_Create(read_thread_entry_, this);
if(affinity)
MThreading::Thread_SetAffinity(thread, affinity);
pending_command = Command_NOP;
MThreading::Sem_Post(command_sem);
}
MTStreamReader::~MTStreamReader()
......@@ -159,10 +151,8 @@ int MTStreamReader::read_thread_entry(void)
{
bool running = true;
try
while(running)
{
while(running)
{
MThreading::Sem_Wait(command_sem);
//
const uint32 command = pending_command;
......@@ -206,21 +196,6 @@ int MTStreamReader::read_thread_entry(void)
}
//
MThreading::Sem_Post(ack_sem);
}
}
catch(std::exception& e)
{
MDFN_Notify(MDFN_NOTICE_ERROR, _("MTStreamReader() error: %s"), e.what());
while(running)
{
MThreading::Sem_Wait(command_sem);
//
if(pending_command == Command_Exit)
running = false;
//
MThreading::Sem_Post(ack_sem);
}
}
return 0;
......
......@@ -53,17 +53,7 @@ Stream* NativeVFS::open(const std::string& path, const uint32 mode, const bool t
if(canary != CanaryType::open)
_exit(-1);
try
{
return new FileStream(path, mode);
}
catch(MDFN_Error& e)
{
if(e.GetErrno() != ENOENT || throw_on_noent)
throw;
return nullptr;
}
return new FileStream(path, mode);
}
void NativeVFS::readdirentries(const std::string& path, std::function<bool(const std::string&)> callb)
......@@ -84,8 +74,6 @@ void NativeVFS::readdirentries(const std::string& path, std::function<bool(const
if(invalid_utf8)
throw MDFN_Error(EINVAL, _("Error reading directory entries from \"%s\": %s"), path.c_str(), _("Invalid UTF-8"));
try
{
if(!(dp = FindFirstFileW((const wchar_t*)u16path.c_str(), &ded)))
{
#if 0
......@@ -113,24 +101,12 @@ void NativeVFS::readdirentries(const std::string& path, std::function<bool(const
}
FindClose(dp);
dp = nullptr;
}
catch(...)
{
if(dp)
{
FindClose(dp);
dp = nullptr;
}
throw;
}
#else
DIR* dp = nullptr;
std::string fname;
fname.reserve(512);
try
{
if(!(dp = opendir(path.c_str())))
{
ErrnoHolder ene(errno);
......@@ -163,16 +139,6 @@ void NativeVFS::readdirentries(const std::string& path, std::function<bool(const
//
closedir(dp);
dp = nullptr;
}
catch(...)
{
if(dp)
{
closedir(dp);
dp = nullptr;
}
throw;
}
#endif
}
......
......@@ -92,10 +92,8 @@ uint64 Stream::alloc_and_read(void** data_out, uint64 size_limit)
uint64 data_buffer_size = 0;
uint64 data_buffer_alloced = 0;
try
if(attributes() & ATTRIBUTE_SLOW_SIZE)
{
if(attributes() & ATTRIBUTE_SLOW_SIZE)
{
uint64 rti;
data_buffer_size = 0;
......@@ -147,9 +145,9 @@ uint64 Stream::alloc_and_read(void** data_out, uint64 size_limit)
data_buffer_alloced = new_data_buffer_alloced;
}
}
}
else
{
}
else
{
data_buffer_size = size();
data_buffer_size -= std::min<uint64>(data_buffer_size, tell());
data_buffer_alloced = std::max<uint64>(data_buffer_size, 1);
......@@ -164,16 +162,6 @@ uint64 Stream::alloc_and_read(void** data_out, uint64 size_limit)
throw MDFN_Error(ErrnoHolder(ENOMEM));
read(data_buffer, data_buffer_size);
}
}
catch(...)
{
if(data_buffer)
{
free(data_buffer);
data_buffer = NULL;
}
throw;
}
*data_out = data_buffer;
......
......@@ -32,67 +32,35 @@ MDFN_Error::MDFN_Error()
MDFN_Error::MDFN_Error(int errno_code_new, const char *format, ...)
{
va_list ap;
char* ret = NULL;
errno_code = errno_code_new;
va_start(ap, format);
if (vasprintf(&ret, format, ap) != -1)
error_message = ret;
va_end(ap);
}
MDFN_Error::MDFN_Error(const ErrnoHolder &enh)
{
errno_code = enh.Errno();
error_message = strdup(enh.StrError());
}
MDFN_Error::~MDFN_Error()
{
if(error_message)
{
free(error_message);
error_message = NULL;
}
}
MDFN_Error::MDFN_Error(const MDFN_Error &ze_error)
{
if(ze_error.error_message)
error_message = strdup(ze_error.error_message);
else
error_message = NULL;
errno_code = ze_error.errno_code;
}
MDFN_Error& MDFN_Error::operator=(const MDFN_Error &ze_error)
{
char *new_error_message = ze_error.error_message ? strdup(ze_error.error_message) : NULL;
int new_errno_code = ze_error.errno_code;
if(error_message)
free(error_message);
error_message = new_error_message;
errno_code = new_errno_code;
return(*this);
}
const char * MDFN_Error::what(void)
{
if(!error_message)
return("Error allocating memory for the error message!");
return(error_message);
}
int MDFN_Error::GetErrno(void)
{
return(errno_code);
......
......@@ -42,17 +42,13 @@ class MDFN_Error : public std::exception
MDFN_Error(const MDFN_Error &ze_error) MDFN_COLD;
MDFN_Error & operator=(const MDFN_Error &ze_error) MDFN_COLD;
virtual const char *what(void);
int GetErrno(void);
private:
int errno_code;
char *error_message;
};
//#define DEFMDFNERROR(name, en) struct Error_##name : public MDFN_Error { template<typename ...Z> INLINE Error_##name(Z... args) : MDFN_Error(en, args...) { } }
class ErrnoHolder
{
public:
......
......@@ -150,7 +150,6 @@ MDFNGI *MDFNI_LoadGame(GameFile* gf)
{
MDFNI_CloseGame();
try
{
MDFN_AutoIndent aind(1);
......@@ -175,12 +174,6 @@ MDFNGI *MDFNI_LoadGame(GameFile* gf)
LoadCommonPost();
}
catch(...)
{
MDFNGameInfo = nullptr;
throw;
}
return MDFNGameInfo;
}
......
......@@ -231,7 +231,6 @@ static void ValidateSetting(const char *value, const MDFNSetting *setting)
else if(base_type == MDFNST_ENUM)
{
const MDFNSetting_EnumList *enum_list = setting->enum_list;
bool found = false;
std::string valid_string_list;
assert(enum_list);
......@@ -239,21 +238,13 @@ static void ValidateSetting(const char *value, const MDFNSetting *setting)
while(enum_list->string)
{
if(!MDFN_strazicmp(value, enum_list->string))
{
found = true;
break;
}
if(enum_list->description) // Don't list out undocumented and deprecated values.
valid_string_list = valid_string_list + (enum_list == setting->enum_list ? "" : " ") + std::string(enum_list->string);
enum_list++;
}
if(!found)
{
throw MDFN_Error(0, _("Setting \"%s\", value \"%s\", is not a recognized string. Recognized strings: %s"), setting->name, value, valid_string_list.c_str());
}
}
else if(base_type == MDFNST_MULTI_ENUM)
{
......@@ -446,7 +437,6 @@ static int GetEnum(const MDFNCS *setting, const char *value)
{
const MDFNSetting_EnumList *enum_list = setting->desc->enum_list;
int ret = 0;
bool found = false;
assert(enum_list);
......@@ -454,14 +444,12 @@ static int GetEnum(const MDFNCS *setting, const char *value)
{
if(!MDFN_strazicmp(value, enum_list->string))
{
found = true;
ret = enum_list->number;
break;
}
enum_list++;
}
assert(found);
return(ret);
}
......@@ -476,7 +464,6 @@ static std::vector<T> GetMultiEnum(const MDFNCS* setting, const char* value)
for(auto& mee : mel)
{
const MDFNSetting_EnumList *enum_list = setting->desc->enum_list;
bool found = false;
MDFN_trim(&mee);
......@@ -484,13 +471,11 @@ static std::vector<T> GetMultiEnum(const MDFNCS* setting, const char* value)
{
if(!MDFN_strazicmp(mee.c_str(), enum_list->string))
{
found = true;
ret.push_back(enum_list->number);
break;
}
enum_list++;
}
assert(found);
}
return ret;
......
......@@ -492,7 +492,6 @@ void MSU1_Init(GameFile* gf, double* IdealSoundRate, uint64 affinity_audio, uint
const std::string fnamepat = filebase + "-%.pcm";
const std::string dirpath = gf->outside.dir;
std::bitset<65536> trypcm; // May have false positives, should not have false negatives, but who knows with case insensitive filesystems...
try
{
gf->outside.vfs->readdirentries(dirpath,
[&](const std::string& fname)
......@@ -543,11 +542,6 @@ void MSU1_Init(GameFile* gf, double* IdealSoundRate, uint64 affinity_audio, uint
return ret;
});
}
catch(std::exception& e)
{
MDFN_printf(_("Doing brute-force search for audio tracks due to error: %s\n"), e.what());
trypcm.set();
}
const std::string fbp = dirpath + gf->outside.vfs->get_preferred_path_separator() + filebase;
for(unsigned tnum = 0, w = 0; tnum < 65536; tnum++)
{
......
......@@ -638,16 +638,7 @@ static MDFN_COLD void LoadReal(GameFile* gf)
static MDFN_COLD void Load(GameFile* gf)
{
try
{
LoadReal(gf);
}
catch(...)
{
Cleanup();
throw;
}
LoadReal(gf);
}
static MDFN_COLD void CloseGame(void)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment