Skip to content

Commit

Permalink
diggining into rbx support for rationals
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Ohler committed Apr 4, 2012
1 parent 40b980a commit ec75eac
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion ext/ox/dump.c
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions ext/ox/obj_load.c
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ext/ox/ox.h
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/tests.rb
Expand Up @@ -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)
Expand Down

0 comments on commit ec75eac

Please sign in to comment.