[前][次][番号順一覧][スレッド一覧]

ruby-changes:28646

From: ko1 <ko1@a...>
Date: Tue, 14 May 2013 00:55:20 +0900 (JST)
Subject: [ruby-changes:28646] ko1:r40698 (trunk): * include/ruby/ruby.h: constify RRational::(num,den) and

ko1	2013-05-14 00:55:09 +0900 (Tue, 14 May 2013)

  New Revision: 40698

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40698

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/complex.c
    trunk/include/ruby/ruby.h
    trunk/rational.c

Index: complex.c
===================================================================
--- complex.c	(revision 40697)
+++ complex.c	(revision 40698)
@@ -315,8 +315,8 @@ nucomp_s_new_internal(VALUE klass, VALUE https://github.com/ruby/ruby/blob/trunk/complex.c#L315
 {
     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) https://github.com/ruby/ruby/blob/trunk/complex.c#L1332
 {
     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;
 }
Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 40697)
+++ include/ruby/ruby.h	(revision 40698)
@@ -931,16 +931,22 @@ struct RFile { https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L931
 
 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*);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40697)
+++ ChangeLog	(revision 40698)
@@ -1,3 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue May 14 00:48:55 2013  Koichi Sasada  <ko1@a...>
+
+	* 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@f...>
 
 	* ext/socket/extconf.rb: Check socketpair again.
Index: rational.c
===================================================================
--- rational.c	(revision 40697)
+++ rational.c	(revision 40698)
@@ -370,8 +370,8 @@ nurat_s_new_internal(VALUE klass, VALUE https://github.com/ruby/ruby/blob/trunk/rational.c#L370
 {
     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) https://github.com/ruby/ruby/blob/trunk/rational.c#L1638
 {
     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;
 }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]