Browse files

diggining into rbx support for rationals

  • Loading branch information...
1 parent 40b980a commit ec75eac69c84c3c7593cf988f828ef10d7be9e53 Peter Ohler committed Apr 5, 2012
Showing with 13 additions and 3 deletions.
  1. +7 −1 ext/ox/dump.c
  2. +4 −0 ext/ox/obj_load.c
  3. +1 −1 ext/ox/ox.h
  4. +1 −1 test/tests.rb
View
8 ext/ox/dump.c
@@ -913,12 +913,18 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
out->w_end(out, &e);
break;
#endif
-#if (defined T_RATIONAL && defined RRATIONAL)
+ //#if (defined T_RATIONAL && defined RRATIONAL)
+#ifdef T_RATIONAL
case T_RATIONAL:
e.type = RationalCode;
out->w_start(out, &e);
+#ifdef RUBINIUS_RUBY
+ dump_obj(0, rb_funcall2(obj, rb_intern("numerator"), 0, 0), depth + 1, out);
+ dump_obj(0, rb_funcall2(obj, rb_intern("denominator"), 0, 0), depth + 1, out);
+#else
dump_obj(0, RRATIONAL(obj)->num, depth + 1, out);
dump_obj(0, RRATIONAL(obj)->den, depth + 1, out);
+#endif
out->w_end(out, &e);
break;
#endif
View
4 ext/ox/obj_load.c
@@ -759,7 +759,11 @@ end_element(PInfo pi, const char *ename) {
if (Qundef == pi->h->obj) {
pi->h->obj = h->obj;
} else {
+#ifdef RUBINIUS_RUBY
+ pi->h->obj = rb_Rational(pi->h->obj, h->obj);
+#else
pi->h->obj = rb_rational_new(pi->h->obj, h->obj);
+#endif
}
#else
raise_error("Rational Objects not implemented in Ruby 1.8.7", pi->str, pi->s);
View
2 ext/ox/ox.h
@@ -46,7 +46,7 @@ extern "C" {
#endif
#ifdef RUBINIUS_RUBY
-#undef T_RATIONAL
+//#undef T_RATIONAL
#undef T_COMPLEX
enum st_retval {ST_CONTINUE = 0, ST_STOP = 1, ST_DELETE = 2, ST_CHECK};
#else
View
2 test/tests.rb
@@ -162,7 +162,7 @@ def test_complex_number
end
def test_rational
- if RUBY_VERSION.start_with?('1.8') || 'rubinius' == $ruby
+ if RUBY_VERSION.start_with?('1.8')
assert(true)
else
dump_and_load(Rational(1, 3), false)

0 comments on commit ec75eac

Please sign in to comment.