Skip to content

Commit

Permalink
quick hack for ruby 1.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tadakado committed Feb 4, 2009
1 parent 4f2f99d commit f2c34bb
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
6 changes: 6 additions & 0 deletions History.txt
@@ -1,3 +1,9 @@
= 0.5.1.1 2009-02-05

* quick hack for ruby 1.9.1
* test still fails around Complex
* fix RSRuby.shutdown

= 0.5.1 2008-11-11

* removed #include of Rdevices.h so installation is possible with R 2.8.0 packages
Expand Down
2 changes: 1 addition & 1 deletion Rakefile.rb
Expand Up @@ -4,7 +4,7 @@
$LOAD_PATH.unshift("./ext")

gem_name = RUBY_PLATFORM !~ /mswin32$/ ? "rsruby" : "rsrubywin"
hoe = Hoe.new(gem_name,'0.5.1') do |p|
hoe = Hoe.new(gem_name,'0.5.1.1') do |p|

p.author = "Alex Gutteridge, Ben J Woodcroft"
p.email = "ag357@cam.ac.uk, b.woodcroft@pgrad.unimelb.edu.au"
Expand Down
14 changes: 7 additions & 7 deletions ext/Converters.c
Expand Up @@ -89,7 +89,7 @@ SEXP ruby_to_R(VALUE obj)
else if (!NIL_P(rb_check_string_type(obj)))
{
PROTECT(robj = NEW_STRING(1));
SET_STRING_ELT(robj, 0, COPY_TO_USER_STRING(RSTRING(obj)->ptr));
SET_STRING_ELT(robj, 0, COPY_TO_USER_STRING(RSTRING_PTR(obj)));
}
else if (!NIL_P(rb_check_array_type(obj)))
{
Expand All @@ -103,7 +103,7 @@ SEXP ruby_to_R(VALUE obj)
{
str = rb_funcall(obj,rb_intern("inspect"),0);
str = rb_funcall(str,rb_intern("slice"),2,INT2NUM(0),INT2NUM(60));
sprintf(buf,"Unsupported object '%s' passed to R.\n",RSTRING(str)->ptr);
sprintf(buf,"Unsupported object '%s' passed to R.\n",RSTRING_PTR(str));
rb_raise(rb_eArgError,buf);
PROTECT(robj = NULL); /* Protected to avoid stack inbalance */
}
Expand Down Expand Up @@ -141,13 +141,13 @@ SEXP array_to_R(VALUE obj)
//Probably unnessecary but just in case
obj = rb_check_array_type(obj);

if (RARRAY(obj)->len == 0)
if (RARRAY_LEN(obj) == 0)
return R_NilValue;

PROTECT(robj = NEW_LIST(RARRAY(obj)->len));
PROTECT(robj = NEW_LIST(RARRAY_LEN(obj)));

state = -1;
for (i=0; i<RARRAY(obj)->len; i++) {
for (i=0; i<RARRAY_LEN(obj); i++) {

it = rb_ary_entry(obj, i);

Expand Down Expand Up @@ -296,7 +296,7 @@ to_ruby_basic(SEXP robj, VALUE *obj)

status = to_ruby_vector(robj, &tmp, BASIC_CONVERSION);

if(status==1 && TYPE(tmp) == T_ARRAY && RARRAY(tmp)->len == 1)
if(status==1 && TYPE(tmp) == T_ARRAY && RARRAY_LEN(tmp) == 1)
{
*obj = rb_ary_entry(tmp, 0);
}
Expand Down Expand Up @@ -600,7 +600,7 @@ VALUE to_ruby_hash(VALUE obj, SEXP names)
VALUE it, hash;
char *name;

if ((len = RARRAY(obj)->len) < 0)
if ((len = RARRAY_LEN(obj)) < 0)
return Qnil;

hash = rb_hash_new();
Expand Down
16 changes: 8 additions & 8 deletions ext/robj.c
Expand Up @@ -49,7 +49,7 @@ VALUE RObj_lcall(VALUE self, VALUE args){
args = rb_check_array_type(args);

// A SEXP with the function to call and the arguments
PROTECT(exp = allocVector(LANGSXP, (RARRAY(args)->len)+1));
PROTECT(exp = allocVector(LANGSXP, RARRAY_LEN(args)+1));
e = exp;

Data_Get_Struct(self, struct SEXPREC, r_obj);
Expand Down Expand Up @@ -97,7 +97,7 @@ VALUE RObj_init_lcall(VALUE self, VALUE args){
args = rb_check_array_type(args);

// A SEXP with the function to call and the arguments
PROTECT(exp = allocVector(LANGSXP, (RARRAY(args)->len)+1));
PROTECT(exp = allocVector(LANGSXP, RARRAY_LEN(args)+1));
e = exp;

Data_Get_Struct(self, struct SEXPREC, r_obj);
Expand Down Expand Up @@ -137,10 +137,10 @@ make_argl(VALUE args, SEXP *e)
//Ensure we have an array
args = rb_check_array_type(args);

for (i=0; i<RARRAY(args)->len; i++) {
for (i=0; i<RARRAY_LEN(args); i++) {
pair = rb_ary_entry(args, i);
pair = rb_check_array_type(pair);
if(RARRAY(pair)->len != 2)
if(RARRAY_LEN(pair) != 2)
rb_raise(rb_eArgError,"Misformed argument in lcall\n");

/* Name must be a string. If it is empty string '' then no name*/
Expand All @@ -158,9 +158,9 @@ make_argl(VALUE args, SEXP *e)
SETCAR(*e, rvalue);

/* Add name (if present) */
if (RSTRING(name)->len > 0)
if (RSTRING_LEN(name) > 0)
{
SET_TAG(*e, Rf_install(RSTRING(name)->ptr));
SET_TAG(*e, Rf_install(RSTRING_PTR(name)));
}

/* Move index to new end of call */
Expand All @@ -177,11 +177,11 @@ VALUE RObj_to_ruby(VALUE self, VALUE args){

args = rb_check_array_type(args);

if (RARRAY(args)->len > 1){
if (RARRAY_LEN(args) > 1){
rb_raise(rb_eArgError,"Too many arguments in to_ruby\n");
}

if (RARRAY(args)->len == 0){
if (RARRAY_LEN(args) == 0){
conv = NUM2INT(rb_iv_get(RSRUBY,"@default_mode"));
} else {
conv = NUM2INT(rb_ary_entry(args,0));
Expand Down
4 changes: 2 additions & 2 deletions ext/rsruby.c
Expand Up @@ -76,7 +76,7 @@ VALUE get_fun(VALUE self, VALUE name){

str = StringValue(name);

cstr_name = RSTRING(str)->ptr;
cstr_name = RSTRING_PTR(str);

robj = (SEXP)get_fun_from_name(cstr_name);
if (!robj)
Expand All @@ -101,7 +101,7 @@ void r_finalize(void)
R_dot_Last();
R_RunExitFinalizers();
CleanEd();
KillAllDevices();
Rf_KillAllDevices();

if((tmpdir = getenv("R_SESSION_TMPDIR"))) {
snprintf((char *)buf, 1024, "rm -rf %s", tmpdir);
Expand Down
14 changes: 7 additions & 7 deletions test/tc_modes.rb
Expand Up @@ -40,11 +40,11 @@ def test_to_ruby_default_arg
RSRuby.set_default_mode(RSRuby::VECTOR_CONVERSION)
assert_equal(sequence.to_ruby, [1,2,3])

@r.class_table['htest'] = lambda{5}
@r.class_table['htest'] = lambda{|x| 5}
RSRuby.set_default_mode(RSRuby::CLASS_CONVERSION)
assert_equal(t_test.to_ruby, 5)

@r.proc_table[lambda{true}] = lambda{return 6}
@r.proc_table[lambda{|x| true}] = lambda{|x| return 6}
RSRuby.set_default_mode(RSRuby::PROC_CONVERSION)
assert_equal(t_test.to_ruby, 6)
end
Expand Down Expand Up @@ -77,7 +77,7 @@ def test_no_default_mode
assert_equal(@r.array(1,3).class, @r.array.class)

assert_equal(@r.seq(1,3), [1,2,3])
@r.class_table['htest'] = lambda{5}
@r.class_table['htest'] = lambda{|x| 5}
assert_equal(@r.t_test([1,2,3]), 5)
end

Expand Down Expand Up @@ -149,7 +149,7 @@ def test_basic_conversion

def test_class_table

@r.class_table['htest'] = lambda{'htest'}
@r.class_table['htest'] = lambda{|x| 'htest'}
@r.class_table['data.frame'] = lambda{|x|
if @r['[['].call(x,1).length > 2
return 5
Expand All @@ -170,9 +170,9 @@ def test_multiple_class_table
f = @r.class__(@r.c(4),'foo')
g = @r.class__(@r.c(4), ['bar','foo'])

@r.class_table['foo'] = lambda{'foo'}
@r.class_table['bar'] = lambda{'bar'}
@r.class_table[['bar','foo']] = lambda{5}
@r.class_table['foo'] = lambda{|x| 'foo'}
@r.class_table['bar'] = lambda{|x| 'bar'}
@r.class_table[['bar','foo']] = lambda{|x| 5}

RSRuby.set_default_mode(RSRuby::CLASS_CONVERSION)
assert_equal(f.to_ruby, 'foo')
Expand Down

0 comments on commit f2c34bb

Please sign in to comment.