diff options
author | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-13 12:29:50 +0000 |
---|---|---|
committer | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-13 12:29:50 +0000 |
commit | c7f4ebc8b703bc5d674752299e8190f424e92189 (patch) | |
tree | 61c0d8f5c1a513d3f874753fdc4c96f55b04e392 /rational.c | |
parent | 05093ae437c8c45849c66f010ab24b32236dfb6a (diff) | |
download | ruby-c7f4ebc8b703bc5d674752299e8190f424e92189.tar.gz |
* complex.c (string_to_c, nucomp_s_convert): preserve the current
backref.
* rational.c (string_to_r, nurat_s_convert): ditto.
* include/ruby/intern.h (rb_match_busy): added a declaration.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'rational.c')
-rw-r--r-- | rational.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/rational.c b/rational.c index 53e5fd4aeb..d24195ac14 100644 --- a/rational.c +++ b/rational.c @@ -1274,15 +1274,13 @@ make_patterns(void) static VALUE string_to_r_internal(VALUE self) { - VALUE s, m, backref; + VALUE s, m; s = f_strip(self); if (RSTRING_LEN(s) == 0) return rb_assoc_new(Qnil, self); - backref = rb_backref_get(); - rb_match_busy(backref); m = f_match(rat_pat, s); if (!NIL_P(m)) { @@ -1335,10 +1333,8 @@ string_to_r_internal(VALUE self) if (!NIL_P(de)) v = f_div(v, f_to_i(de)); - rb_backref_set(backref); return rb_assoc_new(v, re); } - rb_backref_set(backref); return rb_assoc_new(Qnil, self); } @@ -1360,8 +1356,16 @@ string_to_r_strict(VALUE self) static VALUE string_to_r(VALUE self) { - VALUE s = f_gsub(self, underscores_pat, an_underscore); - VALUE a = string_to_r_internal(s); + VALUE s, a, backref; + + backref = rb_backref_get(); + rb_match_busy(backref); + + s = f_gsub(self, underscores_pat, an_underscore); + a = string_to_r_internal(s); + + rb_backref_set(backref); + if (!NIL_P(RARRAY_PTR(a)[0])) return RARRAY_PTR(a)[0]; return rb_rational_new1(INT2FIX(0)); @@ -1373,7 +1377,7 @@ string_to_r(VALUE self) static VALUE nurat_s_convert(int argc, VALUE *argv, VALUE klass) { - VALUE a1, a2; + VALUE a1, a2, backref; rb_scan_args(argc, argv, "02", &a1, &a2); @@ -1397,6 +1401,9 @@ nurat_s_convert(int argc, VALUE *argv, VALUE klass) a2 = RCOMPLEX(a2)->real; } + backref = rb_backref_get(); + rb_match_busy(backref); + switch (TYPE(a1)) { case T_FIXNUM: case T_BIGNUM: @@ -1421,6 +1428,8 @@ nurat_s_convert(int argc, VALUE *argv, VALUE klass) break; } + rb_backref_set(backref); + switch (TYPE(a1)) { case T_RATIONAL: if (NIL_P(a2) || f_zero_p(a2)) |