MRI: Make error handling during script load more robust

This commit is contained in:
Jonas Kulla 2014-12-23 19:05:08 +01:00
parent 2f95c0613a
commit b39964a49a
2 changed files with 23 additions and 7 deletions

View File

@ -346,7 +346,7 @@ static void runCustomScript(const std::string &filename)
newStringUTF8(filename.c_str(), filename.size()), NULL);
}
VALUE kernelLoadDataInt(const char *filename);
VALUE kernelLoadDataInt(const char *filename, bool rubyExc);
struct BacktraceData
{
@ -373,7 +373,19 @@ static void runRMXPScripts(BacktraceData &btData)
return;
}
VALUE scriptArray = kernelLoadDataInt(scriptPack.c_str());
VALUE scriptArray;
/* We checked if Scripts.rxdata exists, but something might
* still go wrong */
try
{
scriptArray = kernelLoadDataInt(scriptPack.c_str(), false);
}
catch (const Exception &e)
{
showMsg(std::string("Failed to read script data: ") + e.msg);
return;
}
if (!RB_TYPE_P(scriptArray, RUBY_T_ARRAY))
{

View File

@ -40,7 +40,7 @@ fileIntFreeInstance(void *inst)
DEF_TYPE_CUSTOMFREE(FileInt, fileIntFreeInstance);
static VALUE
fileIntForPath(const char *path)
fileIntForPath(const char *path, bool rubyExc)
{
SDL_RWops *ops = SDL_AllocRW();
@ -51,7 +51,11 @@ fileIntForPath(const char *path)
catch (const Exception &e)
{
SDL_FreeRW(ops);
if (rubyExc)
raiseRbExc(e);
else
throw e;
}
VALUE klass = rb_const_get(rb_cObject, rb_intern("FileInt"));
@ -119,11 +123,11 @@ RB_METHOD(fileIntBinmode)
}
VALUE
kernelLoadDataInt(const char *filename)
kernelLoadDataInt(const char *filename, bool rubyExc)
{
rb_gc_start();
VALUE port = fileIntForPath(filename);
VALUE port = fileIntForPath(filename, rubyExc);
VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal"));
@ -142,7 +146,7 @@ RB_METHOD(kernelLoadData)
const char *filename;
rb_get_args(argc, argv, "z", &filename RB_ARG_END);
return kernelLoadDataInt(filename);
return kernelLoadDataInt(filename, true);
}
RB_METHOD(kernelSaveData)