MRI: Make error handling during script load more robust
This commit is contained in:
parent
2f95c0613a
commit
b39964a49a
|
@ -346,7 +346,7 @@ static void runCustomScript(const std::string &filename)
|
||||||
newStringUTF8(filename.c_str(), filename.size()), NULL);
|
newStringUTF8(filename.c_str(), filename.size()), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE kernelLoadDataInt(const char *filename);
|
VALUE kernelLoadDataInt(const char *filename, bool rubyExc);
|
||||||
|
|
||||||
struct BacktraceData
|
struct BacktraceData
|
||||||
{
|
{
|
||||||
|
@ -373,7 +373,19 @@ static void runRMXPScripts(BacktraceData &btData)
|
||||||
return;
|
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))
|
if (!RB_TYPE_P(scriptArray, RUBY_T_ARRAY))
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,7 +40,7 @@ fileIntFreeInstance(void *inst)
|
||||||
DEF_TYPE_CUSTOMFREE(FileInt, fileIntFreeInstance);
|
DEF_TYPE_CUSTOMFREE(FileInt, fileIntFreeInstance);
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
fileIntForPath(const char *path)
|
fileIntForPath(const char *path, bool rubyExc)
|
||||||
{
|
{
|
||||||
SDL_RWops *ops = SDL_AllocRW();
|
SDL_RWops *ops = SDL_AllocRW();
|
||||||
|
|
||||||
|
@ -51,7 +51,11 @@ fileIntForPath(const char *path)
|
||||||
catch (const Exception &e)
|
catch (const Exception &e)
|
||||||
{
|
{
|
||||||
SDL_FreeRW(ops);
|
SDL_FreeRW(ops);
|
||||||
raiseRbExc(e);
|
|
||||||
|
if (rubyExc)
|
||||||
|
raiseRbExc(e);
|
||||||
|
else
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE klass = rb_const_get(rb_cObject, rb_intern("FileInt"));
|
VALUE klass = rb_const_get(rb_cObject, rb_intern("FileInt"));
|
||||||
|
@ -119,11 +123,11 @@ RB_METHOD(fileIntBinmode)
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
kernelLoadDataInt(const char *filename)
|
kernelLoadDataInt(const char *filename, bool rubyExc)
|
||||||
{
|
{
|
||||||
rb_gc_start();
|
rb_gc_start();
|
||||||
|
|
||||||
VALUE port = fileIntForPath(filename);
|
VALUE port = fileIntForPath(filename, rubyExc);
|
||||||
|
|
||||||
VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal"));
|
VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal"));
|
||||||
|
|
||||||
|
@ -142,7 +146,7 @@ RB_METHOD(kernelLoadData)
|
||||||
const char *filename;
|
const char *filename;
|
||||||
rb_get_args(argc, argv, "z", &filename RB_ARG_END);
|
rb_get_args(argc, argv, "z", &filename RB_ARG_END);
|
||||||
|
|
||||||
return kernelLoadDataInt(filename);
|
return kernelLoadDataInt(filename, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_METHOD(kernelSaveData)
|
RB_METHOD(kernelSaveData)
|
||||||
|
|
Loading…
Reference in New Issue