From ec75eac69c84c3c7593cf988f828ef10d7be9e53 Mon Sep 17 00:00:00 2001 From: Peter Ohler Date: Thu, 5 Apr 2012 08:29:02 +0900 Subject: [PATCH] diggining into rbx support for rationals --- ext/ox/dump.c | 8 +++++++- ext/ox/obj_load.c | 4 ++++ ext/ox/ox.h | 2 +- test/tests.rb | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ext/ox/dump.c b/ext/ox/dump.c index 9d7851a8..2fa94461 100644 --- a/ext/ox/dump.c +++ b/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 diff --git a/ext/ox/obj_load.c b/ext/ox/obj_load.c index 4bb918e5..ee3ca793 100644 --- a/ext/ox/obj_load.c +++ b/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); diff --git a/ext/ox/ox.h b/ext/ox/ox.h index 80385c79..f509a6f7 100644 --- a/ext/ox/ox.h +++ b/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 diff --git a/test/tests.rb b/test/tests.rb index 57070236..3e26a085 100755 --- a/test/tests.rb +++ b/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)