Permalink
Browse files

- Fixed examples for 1.9 compatibility.

[git-p4: depot-paths = "//src/RubyInline/dev/": change = 6417]
  • Loading branch information...
1 parent 787ab68 commit d6a5acd76e9f7597715964c93aba72452f67db92 @zenspider zenspider committed Jun 30, 2011
Showing with 8 additions and 9 deletions.
  1. +2 −3 example2.rb
  2. +6 −6 tutorial/example2.rb
View
@@ -14,10 +14,9 @@ class MyTest
builder.add_compile_flags %q(-x c++)
builder.add_link_flags %q(-lstdc++)
+ builder.include "<iostream>"
+
builder.c "
-// stupid c++ comment
-#include <iostream>
-/* stupid c comment */
static
void
hello(int i) {
View
@@ -7,15 +7,15 @@ class Array
inline do |builder|
builder.c_raw "
static VALUE average(int argc, VALUE *argv, VALUE self) {
- double result;
+ double result = 0;
long i, len;
- VALUE *arr = RARRAY(self)->ptr;
- len = RARRAY(self)->len;
-
+ VALUE *arr = RARRAY_PTR(self);
+ len = RARRAY_LEN(self);
+
for(i=0; i<len; i++) {
result += NUM2DBL(arr[i]);
}
-
+
return rb_float_new(result/(double)len);
}
"
@@ -70,7 +70,7 @@ class Array
# & time ruby ./example2.rb 5 100000
# .....
-#
+#
# real 0m1.403s
# user 0m1.120s
# sys 0m0.070s

0 comments on commit d6a5acd

Please sign in to comment.