From 2ff238ea83a45fc56e3f1ab089f3163d066b3551 Mon Sep 17 00:00:00 2001 From: mquinson Date: Fri, 5 Mar 2010 09:24:04 +0000 Subject: [PATCH] We must put the location where we copy the task pointer to on the heap, because the stack may move during the context switches (damn ruby internals) This kills a "invalid write" error by reading what we copied into the heap git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7200 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/bindings/ruby/rb_msg_task.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/bindings/ruby/rb_msg_task.c b/src/bindings/ruby/rb_msg_task.c index 38068703e1..ad934b47a3 100644 --- a/src/bindings/ruby/rb_msg_task.c +++ b/src/bindings/ruby/rb_msg_task.c @@ -65,11 +65,16 @@ void rb_task_send(VALUE class,VALUE task,VALUE mailbox) { // Receiving Task (returns a Task) VALUE rb_task_receive(VALUE class, VALUE mailbox) { - // Task - m_task_t task = NULL; + // We must put the location where we copy the task + // pointer to on the heap, because the stack may move + // during the context switches (damn ruby internals) + m_task_t *ptask = malloc(sizeof(m_task_t)); + m_task_t task; + *ptask = NULL; INFO2("Receiving a task on mailbox '%s', store it into %p",RSTRING(mailbox)->ptr,&task); - MSG_task_receive(&task,RSTRING(mailbox)->ptr); - INFO2("XXXXXXXXReceived a task %p %s",task,task->name); + MSG_task_receive(ptask,RSTRING(mailbox)->ptr); + task = *ptask; + free(ptask); return Data_Wrap_Struct(class, 0, rb_task_free, task); } -- 2.20.1