Skip to content

Commit

Permalink
remove the object from recursive_objects in RoxorVM::exec_recursive()…
Browse files Browse the repository at this point in the history
… even if called function raises an exception
  • Loading branch information
Watson1978 committed Jun 12, 2012
1 parent 15a853a commit 74cb1bf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
26 changes: 19 additions & 7 deletions vm.cpp
Expand Up @@ -4717,6 +4717,15 @@ rb_exec_recursive(VALUE (*func) (VALUE, VALUE, int), VALUE obj, VALUE arg)
return GET_VM()->exec_recursive(func, obj, arg);
}

void
RoxorVM::remove_recursive_object(VALUE obj)
{
std::vector<VALUE>::iterator iter =
std::find(recursive_objects.begin(), recursive_objects.end(), obj);
assert(iter != recursive_objects.end());
recursive_objects.erase(iter);
}

VALUE
RoxorVM::exec_recursive(VALUE (*func) (VALUE, VALUE, int), VALUE obj,
VALUE arg)
Expand All @@ -4729,13 +4738,16 @@ RoxorVM::exec_recursive(VALUE (*func) (VALUE, VALUE, int), VALUE obj,
}

recursive_objects.push_back(obj);
// XXX the function is not supposed to raise an exception.
VALUE ret = (*func) (obj, arg, Qfalse);

iter = std::find(recursive_objects.begin(), recursive_objects.end(), obj);
assert(iter != recursive_objects.end());
recursive_objects.erase(iter);

VALUE ret;
try {
ret = (*func) (obj, arg, Qfalse);
}
catch (...) {
RoxorSpecialException *exc = get_special_exc();
remove_recursive_object(obj);
throw exc;
}
remove_recursive_object(obj);
return ret;
}

Expand Down
1 change: 1 addition & 0 deletions vm.h
Expand Up @@ -1226,6 +1226,7 @@ class RoxorVM {

void setup_from_current_thread(void);

void remove_recursive_object(VALUE obj);
VALUE exec_recursive(VALUE (*func) (VALUE, VALUE, int), VALUE obj,
VALUE arg);

Expand Down

0 comments on commit 74cb1bf

Please sign in to comment.