From 8c7322605eac66b1206f7c051ba129aefc9c49e9 Mon Sep 17 00:00:00 2001 From: cristianrosa Date: Thu, 2 Dec 2010 23:19:16 +0000 Subject: [PATCH] Switch to Ruby 1.9.x git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8962 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- buildtools/Cmake/CompleteInFiles.cmake | 8 ++++---- src/bindings/ruby/rb_application_handler.c | 8 ++++---- src/bindings/ruby/rb_msg_host.c | 11 +++++++---- src/bindings/ruby/rb_msg_task.c | 12 ++++++------ src/bindings/ruby/simgrid_ruby.c | 14 +++++++------- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/buildtools/Cmake/CompleteInFiles.cmake b/buildtools/Cmake/CompleteInFiles.cmake index 7508c42e7b..9f3b934736 100644 --- a/buildtools/Cmake/CompleteInFiles.cmake +++ b/buildtools/Cmake/CompleteInFiles.cmake @@ -109,7 +109,7 @@ endif(enable_lua) if(enable_ruby) include(FindRuby) if(RUBY_LIBRARY) - if(RUBY_VERSION_MAJOR MATCHES "1" AND RUBY_VERSION_MINOR MATCHES "8") + if(RUBY_VERSION_MAJOR MATCHES "1" AND RUBY_VERSION_MINOR MATCHES "9") set(LIB_RUBY_VERSION "${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}.${RUBY_VERSION_PATCH}") string(REGEX MATCH "ruby.*[0-9]" RUBY_LIBRARY_NAME ${RUBY_LIBRARY}) if(NOT RUBY_LIBRARY_NAME) @@ -123,10 +123,10 @@ if(enable_ruby) endif(NOT operation) ADD_DEFINITIONS("-I${CMAKE_HOME_DIRECTORY}/src/bindings/ruby -I${CMAKE_HOME_DIRECTORY}/src/simix") SET(HAVE_RUBY 1) - else(RUBY_VERSION_MAJOR MATCHES "1" AND RUBY_VERSION_MINOR MATCHES "8") - message("Ruby binding need version 1.8.x actually version ${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}.x") + else(RUBY_VERSION_MAJOR MATCHES "1" AND RUBY_VERSION_MINOR MATCHES "9") + message("Ruby binding need version 1.9.x actually version ${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}.x") SET(HAVE_RUBY 0) - endif(RUBY_VERSION_MAJOR MATCHES "1" AND RUBY_VERSION_MINOR MATCHES "8") + endif(RUBY_VERSION_MAJOR MATCHES "1" AND RUBY_VERSION_MINOR MATCHES "9") else(RUBY_LIBRARY) SET(HAVE_RUBY 0) endif(RUBY_LIBRARY) diff --git a/src/bindings/ruby/rb_application_handler.c b/src/bindings/ruby/rb_application_handler.c index 6a86db2392..5b056e5487 100644 --- a/src/bindings/ruby/rb_application_handler.c +++ b/src/bindings/ruby/rb_application_handler.c @@ -20,7 +20,7 @@ static VALUE rb_process_instance(VALUE fct_name, VALUE arguments, { ruby_init(); ruby_init_loadpath(); - char *p_className = RSTRING(fct_name)->ptr; // name of process is the one of the class + char *p_className = RSTRING_PTR(fct_name); // name of process is the one of the class return rb_funcall(rb_const_get(rb_cObject, rb_intern(p_className)), rb_intern("new"), 3, fct_name, arguments, properties); } @@ -39,18 +39,18 @@ static void rb_process_create_with_args(VALUE fct_name, VALUE arguments, if (!fct_name) rb_raise(rb_eRuntimeError, "Internal error: Process name cannot be NULL"); - name = RSTRING(fct_name)->ptr; + name = RSTRING_PTR(fct_name); DEBUG1("Create native process %s", name); char **argv = xbt_new(char *, 2); - argv[0] = bprintf("%s@%s", name, RSTRING(ht_name)->ptr); + argv[0] = bprintf("%s@%s", name, RSTRING_PTR(ht_name)); argv[1] = NULL; // Allocate the data for the simulation process = MSG_process_create_with_arguments(name, (xbt_main_func_t) ruby_process, process, - MSG_get_host_by_name(RSTRING(ht_name)->ptr), + MSG_get_host_by_name(RSTRING_PTR(ht_name)), 1, argv); // Bind The Ruby Process instance to The Native Process diff --git a/src/bindings/ruby/rb_msg_host.c b/src/bindings/ruby/rb_msg_host.c index 895ae1de19..d00c329a40 100644 --- a/src/bindings/ruby/rb_msg_host.c +++ b/src/bindings/ruby/rb_msg_host.c @@ -18,12 +18,15 @@ void rb_host_free(m_host_t ht) VALUE rb_host_get_by_name(VALUE class, VALUE name) { - const char *h_name = RSTRING(name)->ptr; + const char *h_name = RSTRING_PTR(name); m_host_t host = MSG_get_host_by_name(h_name); - if (!host) - rb_raise(rb_eRuntimeError, - bprintf("No host called '%s' found", h_name)); + if (!host){ + char *message = bprintf("No host called '%s' found", h_name); + VALUE errorobj = rb_exc_new2(rb_eRuntimeError, message); + xbt_free(message); + rb_exc_raise(errorobj); + } return Data_Wrap_Struct(class, 0, rb_host_free, host); } diff --git a/src/bindings/ruby/rb_msg_task.c b/src/bindings/ruby/rb_msg_task.c index 692b185a60..c2967df722 100644 --- a/src/bindings/ruby/rb_msg_task.c +++ b/src/bindings/ruby/rb_msg_task.c @@ -21,7 +21,7 @@ void rb_task_free(m_task_t tk) VALUE rb_task_new(VALUE class, VALUE name, VALUE comp_size, VALUE comm_size) { - m_task_t task = MSG_task_create(RSTRING(name)->ptr, NUM2INT(comp_size), + m_task_t task = MSG_task_create(RSTRING_PTR(name), NUM2INT(comp_size), NUM2INT(comm_size), NULL); rb_data_t data = malloc(sizeof(s_ruby_data_t)); data->ruby_task = NULL; @@ -75,7 +75,7 @@ void rb_task_send(VALUE class, VALUE task, VALUE mailbox) data->ruby_task = (void *) task; MSG_task_set_data(tk, (void *) data); DEBUG1("Sending task %p", tk); - rv = MSG_task_send(tk, RSTRING(mailbox)->ptr); + rv = MSG_task_send(tk, RSTRING_PTR(mailbox)); if (rv != MSG_OK) { if (rv == MSG_TRANSFER_FAILURE) rb_raise(rb_eRuntimeError, "Transfer failure while Sending"); @@ -99,8 +99,8 @@ VALUE rb_task_receive(VALUE class, VALUE mailbox) *ptask = NULL; rb_data_t data = NULL; DEBUG2("Receiving a task on mailbox '%s', store it into %p", - RSTRING(mailbox)->ptr, &task); - MSG_task_receive(ptask, RSTRING(mailbox)->ptr); + RSTRING_PTR(mailbox), &task); + MSG_task_receive(ptask, RSTRING_PTR(mailbox)); task = *ptask; free(ptask); data = MSG_task_get_data(task); @@ -141,7 +141,7 @@ VALUE rb_task_listen(VALUE class, VALUE task, VALUE alias) int rv; Data_Get_Struct(task, s_m_task_t, tk); - p_alias = RSTRING(alias)->ptr; + p_alias = RSTRING_PTR(alias); rv = MSG_task_listen(p_alias); @@ -162,7 +162,7 @@ VALUE rb_task_listen_host(VALUE class, VALUE task, VALUE alias, VALUE host) Data_Get_Struct(task, s_m_task_t, tk); Data_Get_Struct(host, s_m_host_t, ht); - p_alias = RSTRING(alias)->ptr; + p_alias = RSTRING_PTR(alias); rv = MSG_task_listen_from_host(p_alias, ht); if (rv) return Qtrue; diff --git a/src/bindings/ruby/simgrid_ruby.c b/src/bindings/ruby/simgrid_ruby.c index d6c5338185..7208bdec76 100644 --- a/src/bindings/ruby/simgrid_ruby.c +++ b/src/bindings/ruby/simgrid_ruby.c @@ -31,8 +31,8 @@ static void msg_init(VALUE Class, VALUE args) "Bad arguments to msg_init (expecting an array)"); return; } - ptr = RARRAY(args)->ptr; - argc = RARRAY(args)->len; + ptr = RARRAY_PTR(args); + argc = RARRAY_LEN(args); // Create C array to hold data_get_struct argc++; argv = xbt_new0(char *, argc); @@ -41,7 +41,7 @@ static void msg_init(VALUE Class, VALUE args) VALUE value = ptr[i]; type = TYPE(value); // if (type == T_STRING) - tmp = RSTRING(value)->ptr; + tmp = RSTRING_PTR(value); argv[i + 1] = strdup(tmp); } // Calling C Msg_Init Method @@ -91,7 +91,7 @@ static void msg_createEnvironment(VALUE class, VALUE plateformFile) int type = TYPE(plateformFile); if (type != T_STRING) rb_raise(rb_eRuntimeError, "Bad Argument's Type"); - const char *platform = RSTRING(plateformFile)->ptr; + const char *platform = RSTRING_PTR(plateformFile); MSG_create_environment(platform); DEBUG1("Create Environment (%s)...Done", platform); } @@ -104,7 +104,7 @@ static void msg_deployApplication(VALUE class, VALUE deploymentFile) if (type != T_STRING) rb_raise(rb_eRuntimeError, "Bad Argument's Type for deployApplication "); - const char *dep_file = RSTRING(deploymentFile)->ptr; + const char *dep_file = RSTRING_PTR(deploymentFile); surf_parse_reset_parser(); surfxml_add_callback(STag_surfxml_process_cb_list, rb_application_handler_on_begin_process); @@ -131,13 +131,13 @@ static void msg_deployApplication(VALUE class, VALUE deploymentFile) // INFO static void msg_info(VALUE class, VALUE msg) { - const char *s = RSTRING(msg)->ptr; + const char *s = RSTRING_PTR(msg); INFO1("%s", s); } static void msg_debug(VALUE class, VALUE msg) { - const char *s = RSTRING(msg)->ptr; + const char *s = RSTRING_PTR(msg); DEBUG1("%s", s); } -- 2.20.1