Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Possible mruby bug in mrb_load_string #894
I have been having a bit of a play around with mruby (note: mruby, not MRI Ruby), and I believe I may have found a bug in a recent (20130222) version.
Basically, if you call mrb_load_string with something that returns a class, then make a call on the returned object that throws an exception, and then call mrb_load_string with a string that makes the same kind of return, the class in question has somehow vanished from the environment, and the second load will fail.
Test program and Makefile below. The test string is simply "Float", which returns the Float class. The first time it calls it, it is okay. The second time, "Float" no longer exists.
Naturally, if you remove the call to 'dummyCall', the second load works as it should.
I have seen the problem with other classes as well, although the specifics of what triggers the problem can vary. It is hard to make a general statement as to the exact fault. As a general rule, if any Class is returned from mrb_load_string, and a subsequent call on the return generates an exception, depending on what you do, the whole Class may or may not (seem to) be removed from the current environment.
I can't guarantee my code below is bug-free- I'm still fairly new to mruby. It is possible I have made an incorrect assumption in the code below. If not, it looks like a mruby bug.
I am using mruby as checked out on 20130222 (22/2/13), Linux, Debian, 64-bit. Can supply additional information if needed.
static void show_result(mrb_state *mrb, mrb_value v)
int main(int argc, char *argv)
fprintf(stderr, "Loading first string:\n");
fprintf(stderr, "Making bad call:\n");
fprintf(stderr, "Loading same string again. Should work, but doesn't.\n");
(May be typos- transcribed by hand)
Loading first string: