Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions mrbgems/mruby-task/src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -1265,11 +1265,13 @@ mrb_task_s_get(mrb_state *mrb, mrb_value self)

mrb_get_args(mrb, "S", &name);

/* Search all queues for task with matching name */
/* Search all queues for task with matching name. Compare bytes in C:
Task#name= takes any object, and an `==` dispatched from here could
close or relink the task under the walk. */
for (int i = 0; i < MRB_NUM_TASK_QUEUE; i++) {
mrb_task *t = mrb->task.queues[i];
while (t != NULL) {
if (mrb_equal(mrb, t->name, name)) {
if (mrb_string_p(t->name) && mrb_str_equal(mrb, t->name, name)) {
return t->self;
}
t = t->next;
Expand Down
22 changes: 22 additions & 0 deletions mrbgems/mruby-task/test/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,28 @@
assert_equal "(noname)", task.name
end

class TaskGetClosingName
def initialize(task)
@task = task
end

def ==(other)
@task.close
true
end
end

assert("Task.get does not call a name's == while walking the queues") do
task = Task.new(name: "task_get_target") { }
task.name = TaskGetClosingName.new(task)
assert_nil Task.get("task_get_other")
assert_equal :READY, task.status
task.close
found = Task.new(name: "task_get_found") { }
assert_same found, Task.get("task_get_found")
found.close
end

# Edge cases

assert("Task.new with block doesn't execute immediately") do
Expand Down
Loading