diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-05-13 15:55:09 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-05-13 15:55:09 +0000 |
commit | 89e6910f04bb7dcb4d1b3879b8e98295bc20271d (patch) | |
tree | 4175c82a68e4de62e382568d5d255736b8b2b9ac | |
parent | 8ccd658e5467da884f40260e695268965f8d5d06 (diff) | |
download | ruby-89e6910f04bb7dcb4d1b3879b8e98295bc20271d.tar.gz |
* include/ruby/ruby.h: constify RRational::(num,den) and
RComplex::(real,imag).
Add macro to set these values:
* RRATIONAL_SET_NUM()
* RRATIONAL_SET_DEN()
* RCOMPLEX_SET_REAL()
* RCOMPLEX_SET_IMAG()
This change is a part of RGENGC branch [ruby-trunk - Feature #8339].
TODO: API design. RRATIONAL_SET(rat,num,den) is enough?
TODO: Setting constify variable with cast has same issue of r40691.
* complex.c, rational.c: use above macros.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40698 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | complex.c | 8 | ||||
-rw-r--r-- | include/ruby/ruby.h | 14 | ||||
-rw-r--r-- | rational.c | 8 |
4 files changed, 34 insertions, 12 deletions
@@ -1,3 +1,19 @@ +Tue May 14 00:48:55 2013 Koichi Sasada <ko1@atdot.net> + + * include/ruby/ruby.h: constify RRational::(num,den) and + RComplex::(real,imag). + Add macro to set these values: + * RRATIONAL_SET_NUM() + * RRATIONAL_SET_DEN() + * RCOMPLEX_SET_REAL() + * RCOMPLEX_SET_IMAG() + This change is a part of RGENGC branch [ruby-trunk - Feature #8339]. + + TODO: API design. RRATIONAL_SET(rat,num,den) is enough? + TODO: Setting constify variable with cast has same issue of r40691. + + * complex.c, rational.c: use above macros. + Mon May 13 21:49:17 2013 Tanaka Akira <akr@fsij.org> * ext/socket/extconf.rb: Check socketpair again. @@ -315,8 +315,8 @@ nucomp_s_new_internal(VALUE klass, VALUE real, VALUE imag) { NEWOBJ_OF(obj, struct RComplex, klass, T_COMPLEX); - obj->real = real; - obj->imag = imag; + RCOMPLEX_SET_REAL(obj, real); + RCOMPLEX_SET_IMAG(obj, imag); return (VALUE)obj; } @@ -1332,8 +1332,8 @@ nucomp_loader(VALUE self, VALUE a) { get_dat1(self); - dat->real = rb_ivar_get(a, id_i_real); - dat->imag = rb_ivar_get(a, id_i_imag); + RCOMPLEX_SET_REAL(dat, rb_ivar_get(a, id_i_real)); + RCOMPLEX_SET_IMAG(dat, rb_ivar_get(a, id_i_imag)); return self; } diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index ed91594bf1..3e6909d3e0 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -931,16 +931,22 @@ struct RFile { struct RRational { struct RBasic basic; - VALUE num; - VALUE den; + const VALUE num; + const VALUE den; }; +#define RRATIONAL_SET_NUM(rat, n) (*((VALUE *)(&((struct RRational *)(rat))->num)) = (n)) +#define RRATIONAL_SET_DEN(rat, d) (*((VALUE *)(&((struct RRational *)(rat))->den)) = (d)) + struct RComplex { struct RBasic basic; - VALUE real; - VALUE imag; + const VALUE real; + const VALUE imag; }; +#define RCOMPLEX_SET_REAL(cmp, r) (*((VALUE *)(&((struct RComplex *)(cmp))->real)) = (r)) +#define RCOMPLEX_SET_IMAG(cmp, i) (*((VALUE *)(&((struct RComplex *)(cmp))->imag)) = (i)) + struct RData { struct RBasic basic; void (*dmark)(void*); diff --git a/rational.c b/rational.c index bbf1cafcb1..b7a3ee6bf5 100644 --- a/rational.c +++ b/rational.c @@ -370,8 +370,8 @@ nurat_s_new_internal(VALUE klass, VALUE num, VALUE den) { NEWOBJ_OF(obj, struct RRational, klass, T_RATIONAL); - obj->num = num; - obj->den = den; + RRATIONAL_SET_NUM(obj, num); + RRATIONAL_SET_DEN(obj, den); return (VALUE)obj; } @@ -1638,8 +1638,8 @@ nurat_loader(VALUE self, VALUE a) { get_dat1(self); - dat->num = rb_ivar_get(a, id_i_num); - dat->den = rb_ivar_get(a, id_i_den); + RRATIONAL_SET_NUM(dat, rb_ivar_get(a, id_i_num)); + RRATIONAL_SET_DEN(dat, rb_ivar_get(a, id_i_den)); return self; } |