This example code behaves incorrectly:
#include <mruby.h>
#include <mruby/compile.h>
#include <mruby/string.h>
#include <stdio.h>
mrb_state* mrb;
void p(mrb_value value) {
printf("--> %s\n", mrb_str_to_cstr(mrb, mrb_inspect(mrb, value)));
}
int main() {
mrb = mrb_open();
mrb_value fiber_class = mrb_obj_value(mrb_class_get(mrb, "Fiber"));
mrb_value proc = mrb_load_string(mrb,
"proc do |a| Fiber.yield(a + 1); end");
mrb_sym new = mrb_intern_cstr(mrb, "new");
mrb_value fiber = mrb_funcall_with_block(mrb, fiber_class, new, 0, NULL, proc);
mrb_value start_arg = mrb_fixnum_value(123);
p(mrb_fiber_resume(mrb, fiber, 1, &start_arg));
p(mrb_fiber_resume(mrb, fiber, 0, NULL));
p(mrb_fiber_resume(mrb, fiber, 0, NULL));
p(mrb_fiber_resume(mrb, fiber, 0, NULL));
p(mrb_fiber_resume(mrb, fiber, 0, NULL));
p(mrb_fiber_resume(mrb, fiber, 0, NULL));
p(mrb_fiber_resume(mrb, fiber, 0, NULL));
p(mrb_fiber_resume(mrb, fiber, 0, NULL));
p(mrb_fiber_resume(mrb, fiber, 0, NULL));
}
I would expect this code to output:
--> 124
--> nil
resuming dead fiber (FiberError)
Aborted (core dumped)
Instead it outputs:
--> 124
--> 125
--> 126
--> 127
--> 128
--> 129
--> 130
--> 131
--> 132
I think we are not correctly updating ci->pc when the fiber yields but I am not familiar enough with the VM to understand what should be happening.
This example code behaves incorrectly:
I would expect this code to output:
Instead it outputs:
I think we are not correctly updating
ci->pcwhen the fiber yields but I am not familiar enough with the VM to understand what should be happening.