From 36990e1fa594b98040a6ebf3823277ae68b72703 Mon Sep 17 00:00:00 2001 From: Pascal Terjan Date: Thu, 1 Nov 2012 20:18:08 +0000 Subject: [PATCH] Use macros to access len, needed for ruby 1.9 --- ruby/caca-canvas.c | 20 ++++++++++---------- ruby/caca-dither.c | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ruby/caca-canvas.c b/ruby/caca-canvas.c index 18a6a5d..674bcc0 100644 --- a/ruby/caca-canvas.c +++ b/ruby/caca-canvas.c @@ -274,7 +274,7 @@ static VALUE draw_polyline(VALUE self, VALUE points, VALUE ch) int error = 0; VALUE v, x, y; - n = RARRAY(points)->len; + n = RARRAY_LEN(points); ax = (int*)malloc(n*sizeof(int)); if(!ax) @@ -290,7 +290,7 @@ static VALUE draw_polyline(VALUE self, VALUE points, VALUE ch) for(i=0; ilen == 2)) + if((TYPE(v) == T_ARRAY) && (RARRAY_LEN(v) == 2)) { x = rb_ary_entry(v,0); y = rb_ary_entry(v,1); @@ -336,7 +336,7 @@ static VALUE draw_thin_polyline(VALUE self, VALUE points) int error = 0; VALUE v, x, y; - n = RARRAY(points)->len; + n = RARRAY_LEN(points); ax = (int*)malloc(n*sizeof(int)); if(!ax) @@ -352,7 +352,7 @@ static VALUE draw_thin_polyline(VALUE self, VALUE points) for(i=0; ilen == 2)) + if((TYPE(v) == T_ARRAY) && (RARRAY_LEN(v) == 2)) { x = rb_ary_entry(v,0); y = rb_ary_entry(v,1); @@ -459,7 +459,7 @@ static VALUE fill_triangle_textured(VALUE self, VALUE coords, VALUE texture, VAL float cuv[6]; VALUE v; - l = RARRAY(coords)->len; + l = RARRAY_LEN(coords); if(l != 6 && l != 3) { rb_raise(rb_eArgError, "invalid coords list"); @@ -471,14 +471,14 @@ static VALUE fill_triangle_textured(VALUE self, VALUE coords, VALUE texture, VAL ccoords[i] = NUM2INT(v); else { - if((TYPE(v) != T_ARRAY) || (RARRAY(v)->len != 2)) + if((TYPE(v) != T_ARRAY) || (RARRAY_LEN(v) != 2)) rb_raise(rb_eArgError, "invalid coords list"); ccoords[2*i] = NUM2INT(rb_ary_entry(v, 0)); ccoords[2*i+1] = NUM2INT(rb_ary_entry(v, 1)); } } - l = RARRAY(uv)->len; + l = RARRAY_LEN(uv); if(l != 6 && l != 3) { rb_raise(rb_eArgError, "invalid uv list"); @@ -490,7 +490,7 @@ static VALUE fill_triangle_textured(VALUE self, VALUE coords, VALUE texture, VAL cuv[i] = NUM2DBL(v); else { - if((TYPE(v) != T_ARRAY) || (RARRAY(v)->len != 2)) + if((TYPE(v) != T_ARRAY) || (RARRAY_LEN(v) != 2)) rb_raise(rb_eArgError, "invalid uv list"); ccoords[2*i] = NUM2DBL(rb_ary_entry(v, 0)); ccoords[2*i+1] = NUM2DBL(rb_ary_entry(v, 1)); @@ -600,7 +600,7 @@ static VALUE render_canvas(VALUE self, VALUE font, VALUE width, VALUE height, VA static VALUE import_from_memory(VALUE self, VALUE data, VALUE format) { long int bytes; - bytes = caca_import_canvas_from_memory (_SELF, StringValuePtr(data), RSTRING(StringValue(data))->len, StringValuePtr(format)); + bytes = caca_import_canvas_from_memory (_SELF, StringValuePtr(data), RSTRING_LEN(StringValue(data)), StringValuePtr(format)); if(bytes <= 0) rb_raise(rb_eRuntimeError, strerror(errno)); @@ -610,7 +610,7 @@ static VALUE import_from_memory(VALUE self, VALUE data, VALUE format) static VALUE import_area_from_memory(VALUE self, VALUE x, VALUE y, VALUE data, VALUE format) { long int bytes; - bytes = caca_import_area_from_memory (_SELF, NUM2INT(x), NUM2INT(y), StringValuePtr(data), RSTRING(StringValue(data))->len, StringValuePtr(format)); + bytes = caca_import_area_from_memory (_SELF, NUM2INT(x), NUM2INT(y), StringValuePtr(data), RSTRING_LEN(StringValue(data)), StringValuePtr(format)); if(bytes <= 0) rb_raise(rb_eRuntimeError, strerror(errno)); diff --git a/ruby/caca-dither.c b/ruby/caca-dither.c index 94d1213..a86c98f 100644 --- a/ruby/caca-dither.c +++ b/ruby/caca-dither.c @@ -48,7 +48,7 @@ static VALUE set_dither_palette(VALUE self, VALUE palette) VALUE v, r, g, b, a; int error = 0; - if(RARRAY(palette)->len != 256) + if(RARRAY_LEN(palette) != 256) { rb_raise(rb_eArgError, "Palette must contain 256 elements"); } @@ -84,7 +84,7 @@ static VALUE set_dither_palette(VALUE self, VALUE palette) for(i=0; i<256; i++) { v = rb_ary_entry(palette, i); - if((TYPE(v) == T_ARRAY) && (RARRAY(v)->len == 4)) + if((TYPE(v) == T_ARRAY) && (RARRAY_LEN(v) == 4)) { r = rb_ary_entry(v,0); g = rb_ary_entry(v,1);